public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/5] Handle trying to use a native target with the wrong binary
@ 2022-05-31 14:30 Andrew Burgess
  2022-05-31 14:30 ` [PATCH 1/5] gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope Andrew Burgess
                   ` (5 more replies)
  0 siblings, 6 replies; 83+ messages in thread
From: Andrew Burgess @ 2022-05-31 14:30 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

This started when I accidentally tried to run a RISC-V binary on an
x86-64 native target and discovered that GDB died with an assertion.
I thought surely it must be easy to spot when a user makes this
mistake, right...

Patches #1 and #2 are nice cleanups in their own right, but are
required to allow patch #4.

Patches #3 and #4 are not actually required to solve the original
problem, but were a part of my journey to figuring this out, and will,
I think help catch any future issues in this area (of architecture
mismatch).

Patch #5 solves the original problem.

Thanks,
Andrew


---

Andrew Burgess (5):
  gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope
  gdb/mips: rewrite show_mask_address
  gdb: move the type cast into gdbarch_tdep
  gdb: ensure the cast in gdbarch_tdep is valid
  gdb: native target invalid architecture detection

 gdb/aarch64-fbsd-nat.c     |   4 +-
 gdb/aarch64-fbsd-tdep.c    |   6 +-
 gdb/aarch64-linux-nat.c    |  16 ++---
 gdb/aarch64-linux-tdep.c   |  10 +--
 gdb/aarch64-newlib-tdep.c  |   2 +-
 gdb/aarch64-tdep.c         |  48 +++++++-------
 gdb/aix-thread.c           |  28 ++++----
 gdb/alpha-linux-tdep.c     |   2 +-
 gdb/alpha-netbsd-tdep.c    |   2 +-
 gdb/alpha-obsd-tdep.c      |   2 +-
 gdb/alpha-tdep.c           |  14 ++--
 gdb/amd64-darwin-tdep.c    |   2 +-
 gdb/amd64-fbsd-nat.c       |   4 +-
 gdb/amd64-fbsd-tdep.c      |   4 +-
 gdb/amd64-linux-tdep.c     |   8 +--
 gdb/amd64-netbsd-tdep.c    |   2 +-
 gdb/amd64-obsd-tdep.c      |   2 +-
 gdb/amd64-sol2-tdep.c      |   2 +-
 gdb/amd64-tdep.c           |  34 +++++-----
 gdb/amd64-windows-tdep.c   |   2 +-
 gdb/arc-linux-tdep.c       |   4 +-
 gdb/arc-newlib-tdep.c      |   2 +-
 gdb/arc-tdep.c             |   8 +--
 gdb/arch-utils.c           |  14 +++-
 gdb/arch-utils.h           |   5 ++
 gdb/arm-fbsd-nat.c         |   4 +-
 gdb/arm-fbsd-tdep.c        |   6 +-
 gdb/arm-linux-nat.c        |   8 +--
 gdb/arm-linux-tdep.c       |   4 +-
 gdb/arm-netbsd-nat.c       |   8 +--
 gdb/arm-netbsd-tdep.c      |   4 +-
 gdb/arm-none-tdep.c        |   2 +-
 gdb/arm-obsd-tdep.c        |   2 +-
 gdb/arm-tdep.c             | 130 ++++++++++++++++++------------------
 gdb/arm-wince-tdep.c       |   2 +-
 gdb/avr-tdep.c             |  12 ++--
 gdb/bfin-tdep.c            |   4 +-
 gdb/cris-linux-tdep.c      |   2 +-
 gdb/cris-tdep.c            |  18 ++---
 gdb/frv-tdep.c             |   4 +-
 gdb/ft32-tdep.c            |   2 +-
 gdb/gdbarch.h              |  26 +++++++-
 gdb/hppa-bsd-tdep.c        |   2 +-
 gdb/hppa-linux-tdep.c      |   4 +-
 gdb/hppa-tdep.c            |  12 ++--
 gdb/i386-bsd-tdep.c        |   2 +-
 gdb/i386-darwin-tdep.c     |   4 +-
 gdb/i386-fbsd-tdep.c       |   4 +-
 gdb/i386-gnu-tdep.c        |   2 +-
 gdb/i386-go32-tdep.c       |   2 +-
 gdb/i386-linux-tdep.c      |   4 +-
 gdb/i386-netbsd-tdep.c     |   4 +-
 gdb/i386-nto-tdep.c        |   6 +-
 gdb/i386-obsd-tdep.c       |   2 +-
 gdb/i386-sol2-tdep.c       |   2 +-
 gdb/i386-tdep.c            |  98 +++++++++++++--------------
 gdb/i386-windows-tdep.c    |   2 +-
 gdb/i387-tdep.c            |  20 +++---
 gdb/ia64-linux-tdep.c      |   2 +-
 gdb/ia64-tdep.c            |  12 ++--
 gdb/inf-child.c            |  19 ++++++
 gdb/inf-child.h            |   2 +
 gdb/infcmd.c               |   8 +++
 gdb/loongarch-linux-nat.c  |   6 +-
 gdb/loongarch-linux-tdep.c |   8 +--
 gdb/loongarch-tdep.c       |  10 +--
 gdb/m32c-tdep.c            |  58 ++++++++--------
 gdb/m68hc11-tdep.c         |  12 ++--
 gdb/m68k-bsd-tdep.c        |   2 +-
 gdb/m68k-linux-tdep.c      |   2 +-
 gdb/m68k-tdep.c            |  38 +++++------
 gdb/mep-tdep.c             |   6 +-
 gdb/mips-linux-tdep.c      |   4 +-
 gdb/mips-tdep.c            |  85 ++++++++++++------------
 gdb/mn10300-tdep.c         |   2 +-
 gdb/mn10300-tdep.h         |   2 +-
 gdb/msp430-tdep.c          |  12 ++--
 gdb/nds32-tdep.c           |  20 +++---
 gdb/nios2-linux-tdep.c     |   2 +-
 gdb/nios2-tdep.c           |   4 +-
 gdb/or1k-tdep.c            |   8 +--
 gdb/ppc-fbsd-nat.c         |   4 +-
 gdb/ppc-fbsd-tdep.c        |   8 +--
 gdb/ppc-linux-nat.c        |  22 +++----
 gdb/ppc-linux-tdep.c       |  18 ++---
 gdb/ppc-netbsd-nat.c       |   6 +-
 gdb/ppc-netbsd-tdep.c      |   2 +-
 gdb/ppc-obsd-nat.c         |   4 +-
 gdb/ppc-obsd-tdep.c        |   2 +-
 gdb/ppc-sysv-tdep.c        |  22 +++----
 gdb/ppc64-tdep.c           |   2 +-
 gdb/riscv-linux-tdep.c     |   2 +-
 gdb/riscv-tdep.c           |  26 ++++----
 gdb/rl78-tdep.c            |   8 +--
 gdb/rs6000-aix-nat.c       |   6 +-
 gdb/rs6000-aix-tdep.c      |  16 ++---
 gdb/rs6000-lynx178-tdep.c  |   4 +-
 gdb/rs6000-tdep.c          | 132 ++++++++++++++++++-------------------
 gdb/rx-tdep.c              |   2 +-
 gdb/s390-linux-tdep.c      |  20 +++---
 gdb/s390-tdep.c            |  42 ++++++------
 gdb/sh-linux-tdep.c        |   2 +-
 gdb/sh-netbsd-tdep.c       |   2 +-
 gdb/sh-tdep.c              |   8 +--
 gdb/sparc-linux-tdep.c     |   4 +-
 gdb/sparc-netbsd-tdep.c    |   2 +-
 gdb/sparc-sol2-tdep.c      |   2 +-
 gdb/sparc-tdep.c           |  14 ++--
 gdb/sparc64-fbsd-tdep.c    |   2 +-
 gdb/sparc64-linux-tdep.c   |   4 +-
 gdb/sparc64-netbsd-tdep.c  |   2 +-
 gdb/sparc64-obsd-tdep.c    |   2 +-
 gdb/sparc64-sol2-tdep.c    |   2 +-
 gdb/sparc64-tdep.c         |  10 +--
 gdb/target-delegates.c     |  28 ++++++++
 gdb/target.h               |  13 +++-
 gdb/tic6x-linux-tdep.c     |   6 +-
 gdb/tic6x-tdep.c           |   6 +-
 gdb/v850-tdep.c            |   6 +-
 gdb/windows-nat.c          |   2 +-
 gdb/xtensa-linux-nat.c     |   4 +-
 gdb/xtensa-linux-tdep.c    |   2 +-
 gdb/xtensa-tdep.c          |  54 +++++++--------
 gdb/z80-tdep.c             |   8 +--
 124 files changed, 799 insertions(+), 693 deletions(-)

-- 
2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCH 1/5] gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope
  2022-05-31 14:30 [PATCH 0/5] Handle trying to use a native target with the wrong binary Andrew Burgess
@ 2022-05-31 14:30 ` Andrew Burgess
  2022-06-01  7:58   ` Luis Machado
  2022-05-31 14:30 ` [PATCH 2/5] gdb/mips: rewrite show_mask_address Andrew Burgess
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 83+ messages in thread
From: Andrew Burgess @ 2022-05-31 14:30 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

This is a small refactor to resolve an issue before it becomes a
problem in a later commit.

Move the fetching of an arm_gdbarch_tdep into a more inner scope
within two functions in arm-tdep.c.

The problem with the current code is that the functions in question
are used as the callbacks for two set/show parameters.  These set/show
parameters are available no matter the current architecture, but are
really about controlling an ARM architecture specific setting.  And
so, if I build GDB for all targets on an x86-64/GNU-Linux system, I
can still do this:

  (gdb) show arm fpu
  (gdb) show arm abi

After these calls we end up in show_fp_model and arm_show_abi
respectively, where we unconditionally do this:

  arm_gdbarch_tdep *tdep
    = (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());

However, the gdbarch_tdep() result will only be a arm_gdbarch_tdep if
the current architecture is ARM, otherwise the result will actually be
of some other type.

This isn't actually a problem, as in both cases the use of tdep is
guarded by a later check that the gdbarch architecture is
bfd_arch_arm.

This commit just moves the call to gdbarch_tdep() after the
architecture check.

In a later commit gdbarch_tdep() will be able to spot when we are
casting the result to the wrong type, and this function will trigger
assertion failures if things are not fixed.

There should be not user visible changes after this commit.
---
 gdb/arm-tdep.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 49664093f00..d39342e19c6 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -9015,14 +9015,16 @@ static void
 show_fp_model (struct ui_file *file, int from_tty,
 	       struct cmd_list_element *c, const char *value)
 {
-  arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
-
   if (arm_fp_model == ARM_FLOAT_AUTO
       && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm)
-    gdb_printf (file, _("\
+    {
+      arm_gdbarch_tdep *tdep
+	= (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+
+      gdb_printf (file, _("\
 The current ARM floating point model is \"auto\" (currently \"%s\").\n"),
-		fp_model_strings[tdep->fp_model]);
+		  fp_model_strings[tdep->fp_model]);
+    }
   else
     gdb_printf (file, _("\
 The current ARM floating point model is \"%s\".\n"),
@@ -9053,14 +9055,16 @@ static void
 arm_show_abi (struct ui_file *file, int from_tty,
 	     struct cmd_list_element *c, const char *value)
 {
-  arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
-
   if (arm_abi_global == ARM_ABI_AUTO
       && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm)
-    gdb_printf (file, _("\
+    {
+      arm_gdbarch_tdep *tdep
+	= (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+
+      gdb_printf (file, _("\
 The current ARM ABI is \"auto\" (currently \"%s\").\n"),
-		arm_abi_strings[tdep->arm_abi]);
+		  arm_abi_strings[tdep->arm_abi]);
+    }
   else
     gdb_printf (file, _("The current ARM ABI is \"%s\".\n"),
 		arm_abi_string);
-- 
2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCH 2/5] gdb/mips: rewrite show_mask_address
  2022-05-31 14:30 [PATCH 0/5] Handle trying to use a native target with the wrong binary Andrew Burgess
  2022-05-31 14:30 ` [PATCH 1/5] gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope Andrew Burgess
@ 2022-05-31 14:30 ` Andrew Burgess
  2022-05-31 14:30 ` [PATCH 3/5] gdb: move the type cast into gdbarch_tdep Andrew Burgess
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 83+ messages in thread
From: Andrew Burgess @ 2022-05-31 14:30 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

This commit is similar to the previous commit, but in this case GDB is
actually relying on undefined behaviour.

Consider building GDB for all targets on x86-64/GNU-Linux, then doing
this:

  (gdb) show mips mask-address
  Zeroing of upper 32 bits of 64-bit addresses is auto.
  The 32 bit address mask is set automatically.  Currently disabled
  (gdb)

The 'show mips mask-address' command ends up in show_mask_address in
mips-tdep.c, and this function does this:

  mips_gdbarch_tdep *tdep
    = (mips_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());

Later we might pass TDEP to mips_mask_address_p.  However, in my
example above, on an x86-64 native target, the current target
architecture will be an x86-64 gdbarch, and the tdep field within the
gdbarch will be of type i386_gdbarch_tdep, not of type
mips_gdbarch_tdep, as a result the cast above was incorrect, and TDEP
is not pointing at what it thinks it is.

I also think the current output is a little confusing, we appear to
have two lines that show the same information, but using different
words.

The first line comes from calling deprecated_show_value_hack, while
the second line is printed directly from show_mask_address.  However,
both of these lines are printing the same mask_address_var value.  I
don't think the two lines actually adds any value here.

Finally, none of the text in this function is passed through the
internationalisation mechanism.

It would be nice to remove another use of deprecated_show_value_hack
if possible, so this commit does a complete rewrite of
show_mask_address.

After this commit the output of the above example command, still on my
x86-64 native target is:

    (gdb) show mips mask-address
    Zeroing of upper 32 bits of 64-bit addresses is "auto" (current architecture is not MIPS).

The 'current architecture is not MIPS' text is only displayed when the
current architecture is not MIPS.  If the architecture is mips then we
get the more commonly seen 'currently "on"' or 'currently "off"', like
this:

  (gdb) set architecture mips
  The target architecture is set to "mips".
  (gdb) show mips mask-address
  Zeroing of upper 32 bits of 64-bit addresses is "auto" (currently "off").
  (gdb)

All the text is passed through the internationalisation mechanism, and
we only call gdbarch_tdep when we know the gdbarch architecture is
bfd_arch_mips.
---
 gdb/mips-tdep.c | 37 +++++++++++++++++--------------------
 1 file changed, 17 insertions(+), 20 deletions(-)

diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index 805c5beba59..fc1cb46de84 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -1183,28 +1183,25 @@ static void
 show_mask_address (struct ui_file *file, int from_tty,
 		   struct cmd_list_element *c, const char *value)
 {
-  mips_gdbarch_tdep *tdep
-    = (mips_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
-
-  deprecated_show_value_hack (file, from_tty, c, value);
-  switch (mask_address_var)
+  const char *additional_text = "";
+  if (mask_address_var == AUTO_BOOLEAN_AUTO)
     {
-    case AUTO_BOOLEAN_TRUE:
-      gdb_printf (file, "The 32 bit mips address mask is enabled\n");
-      break;
-    case AUTO_BOOLEAN_FALSE:
-      gdb_printf (file, "The 32 bit mips address mask is disabled\n");
-      break;
-    case AUTO_BOOLEAN_AUTO:
-      gdb_printf
-	(file,
-	 "The 32 bit address mask is set automatically.  Currently %s\n",
-	 mips_mask_address_p (tdep) ? "enabled" : "disabled");
-      break;
-    default:
-      internal_error (__FILE__, __LINE__, _("show_mask_address: bad switch"));
-      break;
+      if (gdbarch_bfd_arch_info (target_gdbarch ())->arch != bfd_arch_mips)
+	additional_text = _(" (current architecture is not MIPS)");
+      else
+	{
+	  mips_gdbarch_tdep *tdep
+	    = (mips_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+
+	  if (mips_mask_address_p (tdep))
+	    additional_text = _(" (currently \"on\")");
+	  else
+	    additional_text = _(" (currently \"off\")");
+	}
     }
+
+  gdb_printf (file, _("Zeroing of upper 32 bits of 64-bit addresses is \"%s\"%s.\n"),
+	      value, additional_text);
 }
 
 /* Tell if the program counter value in MEMADDR is in a standard ISA
-- 
2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCH 3/5] gdb: move the type cast into gdbarch_tdep
  2022-05-31 14:30 [PATCH 0/5] Handle trying to use a native target with the wrong binary Andrew Burgess
  2022-05-31 14:30 ` [PATCH 1/5] gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope Andrew Burgess
  2022-05-31 14:30 ` [PATCH 2/5] gdb/mips: rewrite show_mask_address Andrew Burgess
@ 2022-05-31 14:30 ` Andrew Burgess
  2022-06-01  8:01   ` Luis Machado
  2022-05-31 14:30 ` [PATCH 4/5] gdb: ensure the cast in gdbarch_tdep is valid Andrew Burgess
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 83+ messages in thread
From: Andrew Burgess @ 2022-05-31 14:30 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

I built GDB for all targets on a x86-64/GNU-Linux system, and
then (accidentally) passed GDB a RISC-V binary, and asked GDB to "run"
the binary on the native target.  I got this error:

  (gdb) show architecture
  The target architecture is set to "auto" (currently "i386").
  (gdb) file /tmp/hello.rv32.exe
  Reading symbols from /tmp/hello.rv32.exe...
  (gdb) show architecture
  The target architecture is set to "auto" (currently "riscv:rv32").
  (gdb) run
  Starting program: /tmp/hello.rv32.exe
  ../../src/gdb/i387-tdep.c:596: internal-error: i387_supply_fxsave: Assertion `tdep->st0_regnum >= I386_ST0_REGNUM' failed.

What's going on here is this; initially the architecture is i386, this
is based on the default architecture, which is set based on the native
target.  After loading the RISC-V executable the architecture of the
current inferior is updated based on the architecture of the
executable.

When we "run", GDB does a fork & exec, with the inferior being
controlled through ptrace.  GDB sees an initial stop from the inferior
as soon as the inferior comes to life.  In response to this stop GDB
ends up calling save_stop_reason (linux-nat.c), which ends up trying
to read register from the inferior, to do this we end up calling
target_ops::fetch_registers, which, for the x86-64 native target,
calls amd64_linux_nat_target::fetch_registers.

After this I eventually end up in i387_supply_fxsave, different x86
based targets will end in different functions to fetch registers, but
it doesn't really matter which function we end up in, the problem is
this line, which is repeated in many places:

  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);

The problem here is that the ARCH in this line comes from the current
inferior, which, as we discussed above, will be a RISC-V gdbarch, the
tdep field will actually be of type riscv_gdbarch_tdep, not
i386_gdbarch_tdep.  After this cast we are relying on undefined
behaviour, in my case I happen to trigger an assert, but this might
not always be the case.

The thing I tried that exposed this problem was of course, trying to
start an executable of the wrong architecture on a native target.  I
don't think that the correct solution for this problem is to detect,
at the point of cast, that the gdbarch_tdep object is of the wrong
type, but, I did wonder, is there a way that we could protect
ourselves from incorrectly casting the gdbarch_tdep object?

I think that there is something we can do here, and this commit is the
first step in that direction, though no actual check is added by this
commit.

This commit can be split into two parts:

 (1) In gdbarch.h and arch-utils.c.  In these files I have modified
 gdbarch_tdep (the function) so that it now takes a template argument,
 like this:

    template<typename TDepType>
    static inline TDepType *
    gdbarch_tdep (struct gdbarch *gdbarch)
    {
      struct gdbarch_tdep *tdep = gdbarch_tdep_1 (gdbarch);
      return static_cast<TDepType *> (tdep);
    }

  After this change we are no better protected, but the cast is now
  done within the gdbarch_tdep function rather than at the call sites,
  this leads to the second, much larger change in this commit,

  (2) Everywhere gdbarch_tdep is called, we make changes like this:

    -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
    +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);

There should be no functional change after this commit.

In the next commit I will build on this change to add an assertion in
gdbarch_tdep that checks we are casting to the correct type.
---
 gdb/aarch64-fbsd-nat.c     |   4 +-
 gdb/aarch64-fbsd-tdep.c    |   6 +-
 gdb/aarch64-linux-nat.c    |  16 ++---
 gdb/aarch64-linux-tdep.c   |  10 +--
 gdb/aarch64-newlib-tdep.c  |   2 +-
 gdb/aarch64-tdep.c         |  48 +++++++-------
 gdb/aix-thread.c           |  28 ++++----
 gdb/alpha-linux-tdep.c     |   2 +-
 gdb/alpha-netbsd-tdep.c    |   2 +-
 gdb/alpha-obsd-tdep.c      |   2 +-
 gdb/alpha-tdep.c           |  14 ++--
 gdb/amd64-darwin-tdep.c    |   2 +-
 gdb/amd64-fbsd-nat.c       |   4 +-
 gdb/amd64-fbsd-tdep.c      |   4 +-
 gdb/amd64-linux-tdep.c     |   8 +--
 gdb/amd64-netbsd-tdep.c    |   2 +-
 gdb/amd64-obsd-tdep.c      |   2 +-
 gdb/amd64-sol2-tdep.c      |   2 +-
 gdb/amd64-tdep.c           |  34 +++++-----
 gdb/amd64-windows-tdep.c   |   2 +-
 gdb/arc-linux-tdep.c       |   4 +-
 gdb/arc-newlib-tdep.c      |   2 +-
 gdb/arc-tdep.c             |   8 +--
 gdb/arch-utils.c           |   6 +-
 gdb/arm-fbsd-nat.c         |   4 +-
 gdb/arm-fbsd-tdep.c        |   6 +-
 gdb/arm-linux-nat.c        |   8 +--
 gdb/arm-linux-tdep.c       |   4 +-
 gdb/arm-netbsd-nat.c       |   8 +--
 gdb/arm-netbsd-tdep.c      |   4 +-
 gdb/arm-none-tdep.c        |   2 +-
 gdb/arm-obsd-tdep.c        |   2 +-
 gdb/arm-tdep.c             | 110 +++++++++++++++----------------
 gdb/arm-wince-tdep.c       |   2 +-
 gdb/avr-tdep.c             |  12 ++--
 gdb/bfin-tdep.c            |   4 +-
 gdb/cris-linux-tdep.c      |   2 +-
 gdb/cris-tdep.c            |  18 ++---
 gdb/frv-tdep.c             |   4 +-
 gdb/ft32-tdep.c            |   2 +-
 gdb/gdbarch.h              |  17 ++++-
 gdb/hppa-bsd-tdep.c        |   2 +-
 gdb/hppa-linux-tdep.c      |   4 +-
 gdb/hppa-tdep.c            |  12 ++--
 gdb/i386-bsd-tdep.c        |   2 +-
 gdb/i386-darwin-tdep.c     |   4 +-
 gdb/i386-fbsd-tdep.c       |   4 +-
 gdb/i386-gnu-tdep.c        |   2 +-
 gdb/i386-go32-tdep.c       |   2 +-
 gdb/i386-linux-tdep.c      |   4 +-
 gdb/i386-netbsd-tdep.c     |   4 +-
 gdb/i386-nto-tdep.c        |   6 +-
 gdb/i386-obsd-tdep.c       |   2 +-
 gdb/i386-sol2-tdep.c       |   2 +-
 gdb/i386-tdep.c            |  98 +++++++++++++--------------
 gdb/i386-windows-tdep.c    |   2 +-
 gdb/i387-tdep.c            |  20 +++---
 gdb/ia64-linux-tdep.c      |   2 +-
 gdb/ia64-tdep.c            |  12 ++--
 gdb/loongarch-linux-nat.c  |   6 +-
 gdb/loongarch-linux-tdep.c |   8 +--
 gdb/loongarch-tdep.c       |  10 +--
 gdb/m32c-tdep.c            |  58 ++++++++--------
 gdb/m68hc11-tdep.c         |  12 ++--
 gdb/m68k-bsd-tdep.c        |   2 +-
 gdb/m68k-linux-tdep.c      |   2 +-
 gdb/m68k-tdep.c            |  38 +++++------
 gdb/mep-tdep.c             |   6 +-
 gdb/mips-linux-tdep.c      |   4 +-
 gdb/mips-tdep.c            |  50 +++++++-------
 gdb/mn10300-tdep.c         |   2 +-
 gdb/mn10300-tdep.h         |   2 +-
 gdb/msp430-tdep.c          |  12 ++--
 gdb/nds32-tdep.c           |  20 +++---
 gdb/nios2-linux-tdep.c     |   2 +-
 gdb/nios2-tdep.c           |   4 +-
 gdb/or1k-tdep.c            |   8 +--
 gdb/ppc-fbsd-nat.c         |   4 +-
 gdb/ppc-fbsd-tdep.c        |   8 +--
 gdb/ppc-linux-nat.c        |  22 +++----
 gdb/ppc-linux-tdep.c       |  18 ++---
 gdb/ppc-netbsd-nat.c       |   6 +-
 gdb/ppc-netbsd-tdep.c      |   2 +-
 gdb/ppc-obsd-nat.c         |   4 +-
 gdb/ppc-obsd-tdep.c        |   2 +-
 gdb/ppc-sysv-tdep.c        |  22 +++----
 gdb/ppc64-tdep.c           |   2 +-
 gdb/riscv-linux-tdep.c     |   2 +-
 gdb/riscv-tdep.c           |  26 ++++----
 gdb/rl78-tdep.c            |   8 +--
 gdb/rs6000-aix-nat.c       |   6 +-
 gdb/rs6000-aix-tdep.c      |  16 ++---
 gdb/rs6000-lynx178-tdep.c  |   4 +-
 gdb/rs6000-tdep.c          | 132 ++++++++++++++++++-------------------
 gdb/rx-tdep.c              |   2 +-
 gdb/s390-linux-tdep.c      |  20 +++---
 gdb/s390-tdep.c            |  42 ++++++------
 gdb/sh-linux-tdep.c        |   2 +-
 gdb/sh-netbsd-tdep.c       |   2 +-
 gdb/sh-tdep.c              |   8 +--
 gdb/sparc-linux-tdep.c     |   4 +-
 gdb/sparc-netbsd-tdep.c    |   2 +-
 gdb/sparc-sol2-tdep.c      |   2 +-
 gdb/sparc-tdep.c           |  14 ++--
 gdb/sparc64-fbsd-tdep.c    |   2 +-
 gdb/sparc64-linux-tdep.c   |   4 +-
 gdb/sparc64-netbsd-tdep.c  |   2 +-
 gdb/sparc64-obsd-tdep.c    |   2 +-
 gdb/sparc64-sol2-tdep.c    |   2 +-
 gdb/sparc64-tdep.c         |  10 +--
 gdb/tic6x-linux-tdep.c     |   6 +-
 gdb/tic6x-tdep.c           |   6 +-
 gdb/v850-tdep.c            |   6 +-
 gdb/windows-nat.c          |   2 +-
 gdb/xtensa-linux-nat.c     |   4 +-
 gdb/xtensa-linux-tdep.c    |   2 +-
 gdb/xtensa-tdep.c          |  54 +++++++--------
 gdb/z80-tdep.c             |   8 +--
 118 files changed, 681 insertions(+), 664 deletions(-)

diff --git a/gdb/aarch64-fbsd-nat.c b/gdb/aarch64-fbsd-nat.c
index d8cf6227e73..708ddc40d58 100644
--- a/gdb/aarch64-fbsd-nat.c
+++ b/gdb/aarch64-fbsd-nat.c
@@ -90,7 +90,7 @@ aarch64_fbsd_nat_target::fetch_registers (struct regcache *regcache,
 				    &aarch64_fbsd_fpregset);
 
   gdbarch *gdbarch = regcache->arch ();
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   if (tdep->has_tls ())
     {
       const struct regcache_map_entry aarch64_fbsd_tls_regmap[] =
@@ -123,7 +123,7 @@ aarch64_fbsd_nat_target::store_registers (struct regcache *regcache,
 				    PT_SETFPREGS, &aarch64_fbsd_fpregset);
 
   gdbarch *gdbarch = regcache->arch ();
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   if (tdep->has_tls ())
     {
       const struct regcache_map_entry aarch64_fbsd_tls_regmap[] =
diff --git a/gdb/aarch64-fbsd-tdep.c b/gdb/aarch64-fbsd-tdep.c
index 891546b3c64..4a6b4115234 100644
--- a/gdb/aarch64-fbsd-tdep.c
+++ b/gdb/aarch64-fbsd-tdep.c
@@ -143,7 +143,7 @@ aarch64_fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					   void *cb_data,
 					   const struct regcache *regcache)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   cb (".reg", AARCH64_FBSD_SIZEOF_GREGSET, AARCH64_FBSD_SIZEOF_GREGSET,
       &aarch64_fbsd_gregset, NULL, cb_data);
@@ -190,7 +190,7 @@ static CORE_ADDR
 aarch64_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 				       CORE_ADDR lm_addr, CORE_ADDR offset)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   struct regcache *regcache;
 
   regcache = get_thread_arch_regcache (current_inferior ()->process_target (),
@@ -213,7 +213,7 @@ aarch64_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 static void
 aarch64_fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support.  */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c
index 9cde72b247b..77b1f5525e1 100644
--- a/gdb/aarch64-linux-nat.c
+++ b/gdb/aarch64-linux-nat.c
@@ -358,7 +358,7 @@ static void
 fetch_pauth_masks_from_thread (struct regcache *regcache)
 {
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
   int ret;
   struct iovec iovec;
   uint64_t pauth_regset[2] = {0, 0};
@@ -384,7 +384,7 @@ static void
 fetch_mteregs_from_thread (struct regcache *regcache)
 {
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
   int regno = tdep->mte_reg_base;
 
   gdb_assert (regno != -1);
@@ -409,7 +409,7 @@ static void
 store_mteregs_to_thread (struct regcache *regcache)
 {
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
   int regno = tdep->mte_reg_base;
 
   gdb_assert (regno != -1);
@@ -438,7 +438,7 @@ static void
 fetch_tlsregs_from_thread (struct regcache *regcache)
 {
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
   int regno = tdep->tls_regnum;
 
   gdb_assert (regno != -1);
@@ -463,7 +463,7 @@ static void
 store_tlsregs_to_thread (struct regcache *regcache)
 {
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
   int regno = tdep->tls_regnum;
 
   gdb_assert (regno != -1);
@@ -492,7 +492,7 @@ aarch64_linux_nat_target::fetch_registers (struct regcache *regcache,
 					   int regno)
 {
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
 
   if (regno == -1)
     {
@@ -541,7 +541,7 @@ aarch64_linux_nat_target::store_registers (struct regcache *regcache,
 					   int regno)
 {
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
 
   if (regno == -1)
     {
@@ -808,7 +808,7 @@ aarch64_linux_nat_target::thread_architecture (ptid_t ptid)
   inferior *inf = find_inferior_ptid (this, ptid);
   gdb_assert (inf != NULL);
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (inf->gdbarch);
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (inf->gdbarch);
   if (vq == tdep->vq)
     return inf->gdbarch;
 
diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c
index 453692df2f4..4c96662efb3 100644
--- a/gdb/aarch64-linux-tdep.c
+++ b/gdb/aarch64-linux-tdep.c
@@ -286,7 +286,7 @@ aarch64_linux_sigframe_init (const struct tramp_frame *self,
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   CORE_ADDR sp = get_frame_register_unsigned (this_frame, AARCH64_SP_REGNUM);
   CORE_ADDR sigcontext_addr = (sp + AARCH64_RT_SIGFRAME_UCONTEXT_OFFSET
 			       + AARCH64_UCONTEXT_SIGCONTEXT_OFFSET );
@@ -640,7 +640,7 @@ aarch64_linux_collect_sve_regset (const struct regset *regset,
   gdb_byte *header = (gdb_byte *) buf;
   struct gdbarch *gdbarch = regcache->arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   uint64_t vq = tdep->vq;
 
   gdb_assert (buf != NULL);
@@ -676,7 +676,7 @@ aarch64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					    void *cb_data,
 					    const struct regcache *regcache)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   cb (".reg", AARCH64_LINUX_SIZEOF_GREGSET, AARCH64_LINUX_SIZEOF_GREGSET,
       &aarch64_linux_gregset, NULL, cb_data);
@@ -1743,7 +1743,7 @@ aarch64_linux_report_signal_info (struct gdbarch *gdbarch,
 				  struct ui_out *uiout,
 				  enum gdb_signal siggnal)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (!tdep->has_mte () || siggnal != GDB_SIGNAL_SEGV)
     return;
@@ -1812,7 +1812,7 @@ aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 								    NULL };
   static const char *const stap_register_indirection_suffixes[] = { "]",
 								    NULL };
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   tdep->lowest_pc = 0x8000;
 
diff --git a/gdb/aarch64-newlib-tdep.c b/gdb/aarch64-newlib-tdep.c
index 507b7fc5a51..c9236b17801 100644
--- a/gdb/aarch64-newlib-tdep.c
+++ b/gdb/aarch64-newlib-tdep.c
@@ -29,7 +29,7 @@
 static void
 aarch64_newlib_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   /* Jump buffer - support for longjmp.
      Offset of original PC in jump buffer (in registers).  */
diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
index 67a3f96e1a7..bf8ad0f5525 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -502,7 +502,7 @@ aarch64_analyze_prologue (struct gdbarch *gdbarch,
       else if (inst.opcode->iclass == ic_system)
 	{
 	  aarch64_gdbarch_tdep *tdep
-	    = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	    = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 	  int ra_state_val = 0;
 
 	  if (insn == 0xd503233f /* paciasp.  */
@@ -640,7 +640,7 @@ aarch64_analyze_prologue_test (void)
   struct aarch64_prologue_cache cache;
   cache.saved_regs = trad_frame_alloc_saved_regs (gdbarch);
 
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   /* Test the simple prologue in which frame pointer is used.  */
   {
@@ -1076,7 +1076,7 @@ aarch64_prologue_frame_unwind_stop_reason (struct frame_info *this_frame,
 
   /* Halt the backtrace at "_start".  */
   gdbarch *arch = get_frame_arch (this_frame);
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (arch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (arch);
   if (cache->prev_pc <= tdep->lowest_pc)
     return UNWIND_OUTERMOST;
 
@@ -1120,7 +1120,7 @@ aarch64_prologue_prev_register (struct frame_info *this_frame,
       CORE_ADDR lr;
       struct gdbarch *gdbarch = get_frame_arch (this_frame);
       aarch64_gdbarch_tdep *tdep
-	= (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	= gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
       lr = frame_unwind_register_unsigned (this_frame, AARCH64_LR_REGNUM);
 
@@ -1289,7 +1289,7 @@ aarch64_dwarf2_prev_register (struct frame_info *this_frame,
 			      void **this_cache, int regnum)
 {
   gdbarch *arch = get_frame_arch (this_frame);
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (arch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (arch);
   CORE_ADDR lr;
 
   switch (regnum)
@@ -1315,7 +1315,7 @@ aarch64_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
 			       struct dwarf2_frame_state_reg *reg,
 			       struct frame_info *this_frame)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   switch (regnum)
     {
@@ -1355,7 +1355,7 @@ static bool
 aarch64_execute_dwarf_cfa_vendor_op (struct gdbarch *gdbarch, gdb_byte op,
 				     struct dwarf2_frame_state *fs)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   struct dwarf2_frame_state_reg *ra_state;
 
   if (op == DW_CFA_AARCH64_negate_ra_state)
@@ -1996,7 +1996,7 @@ aarch64_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
 static struct type *
 aarch64_vnq_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vnq_type == NULL)
     {
@@ -2023,7 +2023,7 @@ aarch64_vnq_type (struct gdbarch *gdbarch)
 static struct type *
 aarch64_vnd_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vnd_type == NULL)
     {
@@ -2053,7 +2053,7 @@ aarch64_vnd_type (struct gdbarch *gdbarch)
 static struct type *
 aarch64_vns_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vns_type == NULL)
     {
@@ -2083,7 +2083,7 @@ aarch64_vns_type (struct gdbarch *gdbarch)
 static struct type *
 aarch64_vnh_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vnh_type == NULL)
     {
@@ -2116,7 +2116,7 @@ aarch64_vnh_type (struct gdbarch *gdbarch)
 static struct type *
 aarch64_vnb_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vnb_type == NULL)
     {
@@ -2143,7 +2143,7 @@ aarch64_vnb_type (struct gdbarch *gdbarch)
 static struct type *
 aarch64_vnv_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vnv_type == NULL)
     {
@@ -2214,7 +2214,7 @@ aarch64_vnv_type (struct gdbarch *gdbarch)
 static int
 aarch64_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (reg >= AARCH64_DWARF_X0 && reg <= AARCH64_DWARF_X0 + 30)
     return AARCH64_X0_REGNUM + reg - AARCH64_DWARF_X0;
@@ -2518,7 +2518,7 @@ aarch64_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
   CORE_ADDR jb_addr;
   gdb_byte buf[X_REGISTER_SIZE];
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   jb_addr = get_frame_register_unsigned (frame, AARCH64_X0_REGNUM);
@@ -2549,7 +2549,7 @@ aarch64_gen_return_address (struct gdbarch *gdbarch,
 static const char *
 aarch64_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   static const char *const q_name[] =
     {
@@ -2663,7 +2663,7 @@ aarch64_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 static struct type *
 aarch64_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   int p_regnum = regnum - gdbarch_num_regs (gdbarch);
 
@@ -2700,7 +2700,7 @@ static int
 aarch64_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 				    const struct reggroup *group)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   int p_regnum = regnum - gdbarch_num_regs (gdbarch);
 
@@ -2754,7 +2754,7 @@ static struct value *
 aarch64_pseudo_read_value (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int regnum)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   struct value *result_value = allocate_value (register_type (gdbarch, regnum));
 
   VALUE_LVAL (result_value) = lval_register;
@@ -2824,7 +2824,7 @@ static void
 aarch64_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache,
 		      int regnum, const gdb_byte *buf)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   regnum -= gdbarch_num_regs (gdbarch);
 
   if (regnum >= AARCH64_Q0_REGNUM && regnum < AARCH64_Q0_REGNUM + 32)
@@ -3377,7 +3377,7 @@ aarch64_get_tdesc_vq (const struct target_desc *tdesc)
 static int
 aarch64_cannot_store_register (struct gdbarch *gdbarch, int regnum)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (!tdep->has_pauth ())
     return 0;
@@ -3444,7 +3444,7 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
     {
       aarch64_gdbarch_tdep *tdep
-	= (aarch64_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
+	= gdbarch_tdep<aarch64_gdbarch_tdep> (best_arch->gdbarch);
       if (tdep && tdep->vq == vq)
 	return best_arch->gdbarch;
     }
@@ -3693,7 +3693,7 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 aarch64_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep == NULL)
     return;
@@ -3915,7 +3915,7 @@ aarch64_record_branch_except_sys (insn_decode_record *aarch64_insn_r)
 {
 
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (aarch64_insn_r->gdbarch);
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (aarch64_insn_r->gdbarch);
   uint8_t insn_bits24_27, insn_bits28_31, insn_bits22_23;
   uint32_t record_buf[4];
 
diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c
index ecd8200b692..3d76b8c6d01 100644
--- a/gdb/aix-thread.c
+++ b/gdb/aix-thread.c
@@ -1114,7 +1114,7 @@ static void
 supply_gprs64 (struct regcache *regcache, uint64_t *vals)
 {
   ppc_gdbarch_tdep *tdep
-    = (ppc_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<ppc_gdbarch_tdep> (regcache->arch ());
   int regno;
 
   for (regno = 0; regno < ppc_num_gprs; regno++)
@@ -1136,7 +1136,7 @@ static void
 supply_fprs (struct regcache *regcache, double *vals)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int regno;
 
   /* This function should never be called on architectures without
@@ -1154,7 +1154,7 @@ supply_fprs (struct regcache *regcache, double *vals)
 static int
 special_register_p (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   return regno == gdbarch_pc_regnum (gdbarch)
       || regno == tdep->ppc_ps_regnum
@@ -1177,7 +1177,7 @@ supply_sprs64 (struct regcache *regcache,
 	       uint32_t fpscr)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   regcache->raw_supply (gdbarch_pc_regnum (gdbarch), (char *) &iar);
   regcache->raw_supply (tdep->ppc_ps_regnum, (char *) &msr);
@@ -1199,7 +1199,7 @@ supply_sprs32 (struct regcache *regcache,
 	       uint32_t fpscr)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   regcache->raw_supply (gdbarch_pc_regnum (gdbarch), (char *) &iar);
   regcache->raw_supply (tdep->ppc_ps_regnum, (char *) &msr);
@@ -1222,7 +1222,7 @@ static void
 fetch_regs_user_thread (struct regcache *regcache, pthdb_pthread_t pdtid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int status, i;
   pthdb_context_t ctx;
 
@@ -1277,7 +1277,7 @@ fetch_regs_kernel_thread (struct regcache *regcache, int regno,
 			  pthdb_tid_t tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   uint64_t gprs64[ppc_num_gprs];
   uint32_t gprs32[ppc_num_gprs];
   double fprs[ppc_num_fprs];
@@ -1380,7 +1380,7 @@ static void
 fill_gprs64 (const struct regcache *regcache, uint64_t *vals)
 {
   ppc_gdbarch_tdep *tdep
-    = (ppc_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<ppc_gdbarch_tdep> (regcache->arch ());
   int regno;
 
   for (regno = 0; regno < ppc_num_gprs; regno++)
@@ -1393,7 +1393,7 @@ static void
 fill_gprs32 (const struct regcache *regcache, uint32_t *vals)
 {
   ppc_gdbarch_tdep *tdep
-    = (ppc_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<ppc_gdbarch_tdep> (regcache->arch ());
   int regno;
 
   for (regno = 0; regno < ppc_num_gprs; regno++)
@@ -1407,7 +1407,7 @@ static void
 fill_fprs (const struct regcache *regcache, double *vals)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int regno;
 
   /* This function should never be called on architectures without
@@ -1431,7 +1431,7 @@ fill_sprs64 (const struct regcache *regcache,
 	     uint32_t *fpscr)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* Verify that the size of the size of the IAR buffer is the
      same as the raw size of the PC (in the register cache).  If
@@ -1465,7 +1465,7 @@ fill_sprs32 (const struct regcache *regcache,
 	     uint32_t *fpscr)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* Verify that the size of the size of the IAR buffer is the
      same as the raw size of the PC (in the register cache).  If
@@ -1502,7 +1502,7 @@ static void
 store_regs_user_thread (const struct regcache *regcache, pthdb_pthread_t pdtid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int status, i;
   pthdb_context_t ctx;
   uint32_t int32;
@@ -1592,7 +1592,7 @@ store_regs_kernel_thread (const struct regcache *regcache, int regno,
 			  pthdb_tid_t tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   uint64_t gprs64[ppc_num_gprs];
   uint32_t gprs32[ppc_num_gprs];
   double fprs[ppc_num_fprs];
diff --git a/gdb/alpha-linux-tdep.c b/gdb/alpha-linux-tdep.c
index 6cea40d3f34..c103aafc1ff 100644
--- a/gdb/alpha-linux-tdep.c
+++ b/gdb/alpha-linux-tdep.c
@@ -362,7 +362,7 @@ alpha_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   /* Hook into the MDEBUG frame unwinder.  */
   alpha_mdebug_init_abi (info, gdbarch);
 
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
   tdep->dynamic_sigtramp_offset = alpha_linux_sigtramp_offset;
   tdep->sigcontext_addr = alpha_linux_sigcontext_addr;
   tdep->pc_in_sigtramp = alpha_linux_pc_in_sigtramp;
diff --git a/gdb/alpha-netbsd-tdep.c b/gdb/alpha-netbsd-tdep.c
index 6b604cfa9c6..72d7019377f 100644
--- a/gdb/alpha-netbsd-tdep.c
+++ b/gdb/alpha-netbsd-tdep.c
@@ -250,7 +250,7 @@ static void
 alphanbsd_init_abi (struct gdbarch_info info,
 		    struct gdbarch *gdbarch)
 {
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
 
   /* Hook into the DWARF CFI frame unwinder.  */
   alpha_dwarf2_init_abi (info, gdbarch);
diff --git a/gdb/alpha-obsd-tdep.c b/gdb/alpha-obsd-tdep.c
index 8baa8cc32c4..c0d672c3f72 100644
--- a/gdb/alpha-obsd-tdep.c
+++ b/gdb/alpha-obsd-tdep.c
@@ -97,7 +97,7 @@ alphaobsd_sigcontext_addr (struct frame_info *this_frame)
 static void
 alphaobsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
 
   /* Hook into the DWARF CFI frame unwinder.  */
   alpha_dwarf2_init_abi (info, gdbarch);
diff --git a/gdb/alpha-tdep.c b/gdb/alpha-tdep.c
index f04bad6bed8..44efc8e4bbb 100644
--- a/gdb/alpha-tdep.c
+++ b/gdb/alpha-tdep.c
@@ -615,7 +615,7 @@ alpha_return_value (struct gdbarch *gdbarch, struct value *function,
 		    gdb_byte *readbuf, const gdb_byte *writebuf)
 {
   enum type_code code = type->code ();
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
 
   if ((code == TYPE_CODE_STRUCT
        || code == TYPE_CODE_UNION
@@ -851,7 +851,7 @@ static int
 alpha_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR jb_addr;
   gdb_byte raw_buffer[ALPHA_REGISTER_SIZE];
@@ -891,7 +891,7 @@ alpha_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
   *this_prologue_cache = info;
 
   gdbarch *arch = get_frame_arch (this_frame);
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (arch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (arch);
   info->sigcontext_addr = tdep->sigcontext_addr (this_frame);
 
   return info;
@@ -904,7 +904,7 @@ static CORE_ADDR
 alpha_sigtramp_register_address (struct gdbarch *gdbarch,
 				 CORE_ADDR sigcontext_addr, int regnum)
 { 
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
 
   if (regnum >= 0 && regnum < 32)
     return sigcontext_addr + tdep->sc_regs_offset + regnum * 8;
@@ -925,7 +925,7 @@ alpha_sigtramp_frame_this_id (struct frame_info *this_frame,
 			      struct frame_id *this_id)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
   struct alpha_sigtramp_unwind_cache *info
     = alpha_sigtramp_frame_unwind_cache (this_frame, this_prologue_cache);
   CORE_ADDR stack_addr, code_addr;
@@ -1000,7 +1000,7 @@ alpha_sigtramp_frame_sniffer (const struct frame_unwind *self,
 
   /* We shouldn't even bother to try if the OSABI didn't register a
      sigcontext_addr handler or pc_in_sigtramp handler.  */
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
   if (tdep->sigcontext_addr == NULL)
     return 0;
 
@@ -1041,7 +1041,7 @@ static int heuristic_fence_post = 0;
 static CORE_ADDR
 alpha_heuristic_proc_start (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
   CORE_ADDR last_non_nop = pc;
   CORE_ADDR fence = pc - heuristic_fence_post;
   CORE_ADDR orig_pc = pc;
diff --git a/gdb/amd64-darwin-tdep.c b/gdb/amd64-darwin-tdep.c
index 74906f6a02d..7fc35536bc6 100644
--- a/gdb/amd64-darwin-tdep.c
+++ b/gdb/amd64-darwin-tdep.c
@@ -97,7 +97,7 @@ amd64_darwin_sigcontext_addr (struct frame_info *this_frame)
 static void
 x86_darwin_init_abi_64 (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   amd64_init_abi (info, gdbarch,
 		  amd64_target_description (X86_XSTATE_SSE_MASK, true));
diff --git a/gdb/amd64-fbsd-nat.c b/gdb/amd64-fbsd-nat.c
index d125d582a21..7023a182e78 100644
--- a/gdb/amd64-fbsd-nat.c
+++ b/gdb/amd64-fbsd-nat.c
@@ -102,7 +102,7 @@ amd64_fbsd_nat_target::fetch_registers (struct regcache *regcache, int regnum)
 {
   struct gdbarch *gdbarch = regcache->arch ();
 #if defined(PT_GETFSBASE) || defined(PT_GETGSBASE)
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 #endif
   pid_t pid = get_ptrace_pid (regcache->ptid ());
   const struct regset *gregset = find_gregset (gdbarch);
@@ -174,7 +174,7 @@ amd64_fbsd_nat_target::store_registers (struct regcache *regcache, int regnum)
 {
   struct gdbarch *gdbarch = regcache->arch ();
 #if defined(PT_GETFSBASE) || defined(PT_GETGSBASE)
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 #endif
   pid_t pid = get_ptrace_pid (regcache->ptid ());
   const struct regset *gregset = find_gregset (gdbarch);
diff --git a/gdb/amd64-fbsd-tdep.c b/gdb/amd64-fbsd-tdep.c
index 55764beaad2..8e40283d838 100644
--- a/gdb/amd64-fbsd-tdep.c
+++ b/gdb/amd64-fbsd-tdep.c
@@ -262,7 +262,7 @@ amd64fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					void *cb_data,
 					const struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   cb (".reg", AMD64_FBSD_SIZEOF_GREGSET, AMD64_FBSD_SIZEOF_GREGSET,
       &amd64_fbsd_gregset, NULL, cb_data);
@@ -299,7 +299,7 @@ amd64fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 static void
 amd64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support. */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
index 9a0759d639c..aa9c56586ab 100644
--- a/gdb/amd64-linux-tdep.c
+++ b/gdb/amd64-linux-tdep.c
@@ -1656,7 +1656,7 @@ amd64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					  void *cb_data,
 					  const struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   cb (".reg", 27 * 8, 27 * 8, &i386_gregset, NULL, cb_data);
   cb (".reg2", 512, 512, &amd64_fpregset, NULL, cb_data);
@@ -1793,7 +1793,7 @@ static void
 amd64_linux_init_abi_common(struct gdbarch_info info, struct gdbarch *gdbarch,
 			    int num_disp_step_buffers)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, num_disp_step_buffers);
 
@@ -1846,7 +1846,7 @@ amd64_linux_init_abi_common(struct gdbarch_info info, struct gdbarch *gdbarch,
 static void
 amd64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   struct tdesc_arch_data *tdesc_data = info.tdesc_data;
   const struct tdesc_feature *feature;
   int valid_p;
@@ -2060,7 +2060,7 @@ amd64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 static void
 amd64_x32_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   struct tdesc_arch_data *tdesc_data = info.tdesc_data;
   const struct tdesc_feature *feature;
   int valid_p;
diff --git a/gdb/amd64-netbsd-tdep.c b/gdb/amd64-netbsd-tdep.c
index 3ab0267060d..59d723caa55 100644
--- a/gdb/amd64-netbsd-tdep.c
+++ b/gdb/amd64-netbsd-tdep.c
@@ -97,7 +97,7 @@ int amd64nbsd_r_reg_offset[] =
 static void
 amd64nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* Initialize general-purpose register set details first.  */
   tdep->gregset_reg_offset = amd64nbsd_r_reg_offset;
diff --git a/gdb/amd64-obsd-tdep.c b/gdb/amd64-obsd-tdep.c
index 3cb64fe924f..f0bc7c474a6 100644
--- a/gdb/amd64-obsd-tdep.c
+++ b/gdb/amd64-obsd-tdep.c
@@ -420,7 +420,7 @@ static const struct frame_unwind amd64obsd_trapframe_unwind =
 static void
 amd64obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   amd64_init_abi (info, gdbarch,
 		  amd64_target_description (X86_XSTATE_SSE_MASK, true));
diff --git a/gdb/amd64-sol2-tdep.c b/gdb/amd64-sol2-tdep.c
index 22a48e476a5..ce96eb045ec 100644
--- a/gdb/amd64-sol2-tdep.c
+++ b/gdb/amd64-sol2-tdep.c
@@ -80,7 +80,7 @@ amd64_sol2_mcontext_addr (struct frame_info *this_frame)
 static void
 amd64_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   tdep->gregset_reg_offset = amd64_sol2_gregset_reg_offset;
   tdep->gregset_num_regs = ARRAY_SIZE (amd64_sol2_gregset_reg_offset);
diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index b95ab1e87b8..0563b32a54b 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -247,7 +247,7 @@ static const int amd64_dwarf_regmap_len =
 static int
 amd64_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int ymm0_regnum = tdep->ymm0_regnum;
   int regnum = -1;
 
@@ -331,7 +331,7 @@ static const char * const amd64_dword_names[] =
 static const char *
 amd64_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   if (i386_byte_regnum_p (gdbarch, regnum))
     return amd64_byte_names[regnum - tdep->al_regnum];
   else if (i386_zmm_regnum_p (gdbarch, regnum))
@@ -353,7 +353,7 @@ amd64_pseudo_register_read_value (struct gdbarch *gdbarch,
 				  readable_regcache *regcache,
 				  int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   value *result_value = allocate_value (register_type (gdbarch, regnum));
   VALUE_LVAL (result_value) = lval_register;
@@ -413,7 +413,7 @@ amd64_pseudo_register_write (struct gdbarch *gdbarch,
 			     struct regcache *regcache,
 			     int regnum, const gdb_byte *buf)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (i386_byte_regnum_p (gdbarch, regnum))
     {
@@ -465,7 +465,7 @@ static int
 amd64_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				  struct agent_expr *ax, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (i386_byte_regnum_p (gdbarch, regnum))
     {
@@ -2749,7 +2749,7 @@ static struct amd64_frame_cache *
 amd64_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct amd64_frame_cache *cache;
   CORE_ADDR addr;
@@ -2832,7 +2832,7 @@ amd64_sigtramp_frame_sniffer (const struct frame_unwind *self,
 			      void **this_cache)
 {
   gdbarch *arch = get_frame_arch (this_frame);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
 
   /* We shouldn't even bother if we don't have a sigcontext_addr
      handler.  */
@@ -3032,7 +3032,7 @@ amd64_supply_fpregset (const struct regset *regset, struct regcache *regcache,
 		       int regnum, const void *fpregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   gdb_assert (len >= tdep->sizeof_fpregset);
   amd64_supply_fxsave (regcache, regnum, fpregs);
@@ -3049,7 +3049,7 @@ amd64_collect_fpregset (const struct regset *regset,
 			int regnum, void *fpregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   gdb_assert (len >= tdep->sizeof_fpregset);
   amd64_collect_fxsave (regcache, regnum, fpregs);
@@ -3073,7 +3073,7 @@ amd64_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
   gdb_byte buf[8];
   CORE_ADDR jb_addr;
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int jb_pc_offset = tdep->jb_pc_offset;
   int len = TYPE_LENGTH (builtin_type (gdbarch)->builtin_func_ptr);
 
@@ -3117,7 +3117,7 @@ void
 amd64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch,
 		const target_desc *default_tdesc)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   const struct target_desc *tdesc = info.target_desc;
   static const char *const stap_integer_prefixes[] = { "$", NULL };
   static const char *const stap_register_prefixes[] = { "%", NULL };
@@ -3296,7 +3296,7 @@ amd64_none_init_abi (gdbarch_info info, gdbarch *arch)
 static struct type *
 amd64_x32_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   switch (regnum - tdep->eax_regnum)
     {
@@ -3314,7 +3314,7 @@ void
 amd64_x32_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch,
 		    const target_desc *default_tdesc)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   amd64_init_abi (info, gdbarch, default_tdesc);
 
@@ -3384,7 +3384,7 @@ amd64_supply_fxsave (struct regcache *regcache, int regnum,
 		     const void *fxsave)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   i387_supply_fxsave (regcache, regnum, fxsave);
 
@@ -3407,7 +3407,7 @@ amd64_supply_xsave (struct regcache *regcache, int regnum,
 		    const void *xsave)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   i387_supply_xsave (regcache, regnum, xsave);
 
@@ -3442,7 +3442,7 @@ amd64_collect_fxsave (const struct regcache *regcache, int regnum,
 		      void *fxsave)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   gdb_byte *regs = (gdb_byte *) fxsave;
 
   i387_collect_fxsave (regcache, regnum, fxsave);
@@ -3463,7 +3463,7 @@ amd64_collect_xsave (const struct regcache *regcache, int regnum,
 		     void *xsave, int gcore)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   gdb_byte *regs = (gdb_byte *) xsave;
 
   i387_collect_xsave (regcache, regnum, xsave, gcore);
diff --git a/gdb/amd64-windows-tdep.c b/gdb/amd64-windows-tdep.c
index eca94f2ea7c..a9aef0bab88 100644
--- a/gdb/amd64-windows-tdep.c
+++ b/gdb/amd64-windows-tdep.c
@@ -1277,7 +1277,7 @@ amd64_windows_auto_wide_charset (void)
 static void
 amd64_windows_init_abi_common (gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* The dwarf2 unwinder (appended very early by i386_gdbarch_init) is
      preferred over the SEH one.  The reasons are:
diff --git a/gdb/arc-linux-tdep.c b/gdb/arc-linux-tdep.c
index 13595f2e8e9..9c1febcd900 100644
--- a/gdb/arc-linux-tdep.c
+++ b/gdb/arc-linux-tdep.c
@@ -411,7 +411,7 @@ static std::vector<CORE_ADDR>
 arc_linux_software_single_step (struct regcache *regcache)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
   struct disassemble_info di = arc_disassemble_info (gdbarch);
 
   /* Read current instruction.  */
@@ -693,7 +693,7 @@ arc_linux_core_read_description (struct gdbarch *gdbarch,
 static void
 arc_linux_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
 
   arc_linux_debug_printf ("GNU/Linux OS/ABI initialization.");
 
diff --git a/gdb/arc-newlib-tdep.c b/gdb/arc-newlib-tdep.c
index 7d7406c501c..2499dff43ec 100644
--- a/gdb/arc-newlib-tdep.c
+++ b/gdb/arc-newlib-tdep.c
@@ -36,7 +36,7 @@ arc_newlib_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
   arc_newlib_debug_printf ("Initialization.");
 
-  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
 
   /* Offset of original PC in longjmp jump buffer (in registers).  Value of PC
      offset can be found in newlib/libc/machine/arc/setjmp.S.  */
diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c
index 3edfd466f3b..b9c734210fe 100644
--- a/gdb/arc-tdep.c
+++ b/gdb/arc-tdep.c
@@ -1002,7 +1002,7 @@ arc_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
   arc_debug_printf ("called");
 
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
   int pc_offset = tdep->jb_pc * ARC_REGISTER_SIZE;
   gdb_byte buf[ARC_REGISTER_SIZE];
   CORE_ADDR jb_addr = get_frame_register_unsigned (frame, ARC_FIRST_ARG_REGNUM);
@@ -1827,7 +1827,7 @@ arc_make_sigtramp_frame_cache (struct frame_info *this_frame)
   arc_debug_printf ("called");
 
   gdbarch *arch = get_frame_arch (this_frame);
-  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (arch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (arch);
 
   /* Allocate new frame cache instance and space for saved register info.  */
   struct arc_frame_cache *cache = FRAME_OBSTACK_ZALLOC (struct arc_frame_cache);
@@ -1904,7 +1904,7 @@ arc_sigtramp_frame_sniffer (const struct frame_unwind *self,
   arc_debug_printf ("called");
 
   gdbarch *arch = get_frame_arch (this_frame);
-  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (arch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (arch);
 
   /* If we have a sigcontext_addr handler, then just return 1 (same as the
      "default_frame_sniffer ()").  */
@@ -2431,7 +2431,7 @@ arc_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 arc_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
 
   gdb_printf (file, "arc_dump_tdep: jb_pc = %i\n", tdep->jb_pc);
 
diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index ff946ee3767..360b8d694be 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -1198,11 +1198,13 @@ gdbarch_free (struct gdbarch *arch)
   xfree (obstack);
 }
 
+/* See gdbarch.h.  */
+
 struct gdbarch_tdep *
-gdbarch_tdep (struct gdbarch *gdbarch)
+gdbarch_tdep_1 (struct gdbarch *gdbarch)
 {
   if (gdbarch_debug >= 2)
-    gdb_printf (gdb_stdlog, "gdbarch_tdep called\n");
+    gdb_printf (gdb_stdlog, "gdbarch_tdep_1 called\n");
   return gdbarch->tdep;
 }
 
diff --git a/gdb/arm-fbsd-nat.c b/gdb/arm-fbsd-nat.c
index a306e1e2ee0..b161b7ed908 100644
--- a/gdb/arm-fbsd-nat.c
+++ b/gdb/arm-fbsd-nat.c
@@ -55,7 +55,7 @@ arm_fbsd_nat_target::fetch_registers (struct regcache *regcache, int regnum)
 #endif
 #ifdef PT_GETREGSET
   gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->tls_regnum > 0)
     {
@@ -90,7 +90,7 @@ arm_fbsd_nat_target::store_registers (struct regcache *regcache, int regnum)
 #endif
 #ifdef PT_GETREGSET
   gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->tls_regnum > 0)
     {
diff --git a/gdb/arm-fbsd-tdep.c b/gdb/arm-fbsd-tdep.c
index 483820c1092..61c8f0cecad 100644
--- a/gdb/arm-fbsd-tdep.c
+++ b/gdb/arm-fbsd-tdep.c
@@ -159,7 +159,7 @@ arm_fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				       void *cb_data,
 				       const struct regcache *regcache)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   cb (".reg", ARM_FBSD_SIZEOF_GREGSET, ARM_FBSD_SIZEOF_GREGSET,
       &arm_fbsd_gregset, NULL, cb_data);
@@ -233,7 +233,7 @@ static CORE_ADDR
 arm_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 				   CORE_ADDR lm_addr, CORE_ADDR offset)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   struct regcache *regcache;
 
   regcache = get_thread_arch_regcache (current_inferior ()->process_target (),
@@ -256,7 +256,7 @@ arm_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 static void
 arm_fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support.  */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/arm-linux-nat.c b/gdb/arm-linux-nat.c
index 2abaf5a675d..9dd1cdcb0b0 100644
--- a/gdb/arm-linux-nat.c
+++ b/gdb/arm-linux-nat.c
@@ -339,7 +339,7 @@ fetch_vfp_regs (struct regcache *regcache)
   gdb_byte regbuf[ARM_VFP3_REGS_SIZE];
   int ret, tid;
   struct gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Get the thread id for the ptrace call.  */
   tid = regcache->ptid ().lwp ();
@@ -368,7 +368,7 @@ store_vfp_regs (const struct regcache *regcache)
   gdb_byte regbuf[ARM_VFP3_REGS_SIZE];
   int ret, tid;
   struct gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Get the thread id for the ptrace call.  */
   tid = regcache->ptid ().lwp ();
@@ -413,7 +413,7 @@ void
 arm_linux_nat_target::fetch_registers (struct regcache *regcache, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (-1 == regno)
     {
@@ -450,7 +450,7 @@ void
 arm_linux_nat_target::store_registers (struct regcache *regcache, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (-1 == regno)
     {
diff --git a/gdb/arm-linux-tdep.c b/gdb/arm-linux-tdep.c
index f299e9665d5..d530b7f59a8 100644
--- a/gdb/arm-linux-tdep.c
+++ b/gdb/arm-linux-tdep.c
@@ -712,7 +712,7 @@ arm_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					void *cb_data,
 					const struct regcache *regcache)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   cb (".reg", ARM_LINUX_SIZEOF_GREGSET, ARM_LINUX_SIZEOF_GREGSET,
       &arm_linux_gregset, NULL, cb_data);
@@ -1715,7 +1715,7 @@ arm_linux_init_abi (struct gdbarch_info info,
 								    NULL };
   static const char *const stap_register_indirection_suffixes[] = { "]",
 								    NULL };
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 1);
 
diff --git a/gdb/arm-netbsd-nat.c b/gdb/arm-netbsd-nat.c
index 764bbe8cd3d..251159154c9 100644
--- a/gdb/arm-netbsd-nat.c
+++ b/gdb/arm-netbsd-nat.c
@@ -50,7 +50,7 @@ static arm_netbsd_nat_target the_arm_netbsd_nat_target;
 static void
 arm_supply_vfpregset (struct regcache *regcache, struct fpreg *fpregset)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
   if (tdep->vfp_register_count == 0)
     return;
 
@@ -97,7 +97,7 @@ fetch_fp_register (struct regcache *regcache, int regno)
       return;
     }
 
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
   if (regno == ARM_FPSCR_REGNUM && tdep->vfp_register_count != 0)
     regcache->raw_supply (ARM_FPSCR_REGNUM, (char *) &vfp.vfp_fpscr);
   else if (regno >= ARM_D0_REGNUM
@@ -279,7 +279,7 @@ store_fp_register (const struct regcache *regcache, int regno)
       return;
     }
 
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
   if (regno == ARM_FPSCR_REGNUM && tdep->vfp_register_count != 0)
     regcache->raw_collect (ARM_FPSCR_REGNUM, (char *) &vfp.vfp_fpscr);
   else if (regno >= ARM_D0_REGNUM
@@ -301,7 +301,7 @@ store_fp_register (const struct regcache *regcache, int regno)
 static void
 store_fp_regs (const struct regcache *regcache)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
   int lwp = regcache->ptid ().lwp ();
   if (tdep->vfp_register_count == 0)
     return;
diff --git a/gdb/arm-netbsd-tdep.c b/gdb/arm-netbsd-tdep.c
index a6a78f0b893..aa4d15df4c6 100644
--- a/gdb/arm-netbsd-tdep.c
+++ b/gdb/arm-netbsd-tdep.c
@@ -111,7 +111,7 @@ static void
 arm_netbsd_init_abi_common (struct gdbarch_info info,
 			    struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   tdep->lowest_pc = 0x8000;
   switch (info.byte_order)
@@ -148,7 +148,7 @@ static void
 arm_netbsd_elf_init_abi (struct gdbarch_info info,
 			 struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   arm_netbsd_init_abi_common (info, gdbarch);
 
diff --git a/gdb/arm-none-tdep.c b/gdb/arm-none-tdep.c
index 510ce4fa3c5..0d5eb04826e 100644
--- a/gdb/arm-none-tdep.c
+++ b/gdb/arm-none-tdep.c
@@ -177,7 +177,7 @@ arm_none_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				       void *cb_data,
 				       const struct regcache *regcache)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   cb (".reg", ARM_NONE_SIZEOF_GREGSET, ARM_NONE_SIZEOF_GREGSET,
       &arm_none_gregset, nullptr, cb_data);
diff --git a/gdb/arm-obsd-tdep.c b/gdb/arm-obsd-tdep.c
index 37cb30b9a2a..634c76b7561 100644
--- a/gdb/arm-obsd-tdep.c
+++ b/gdb/arm-obsd-tdep.c
@@ -76,7 +76,7 @@ static void
 armobsd_init_abi (struct gdbarch_info info,
 		  struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->fp_model == ARM_FLOAT_AUTO)
     tdep->fp_model = ARM_FLOAT_SOFT_VFP;
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index d39342e19c6..99b73f64cd1 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -338,7 +338,7 @@ static void
 arm_cache_init (struct arm_prologue_cache *cache, struct frame_info *frame)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   arm_cache_init (cache, gdbarch);
 
@@ -520,7 +520,7 @@ bool arm_unwind_secure_frames = true;
 int
 arm_psr_thumb_bit (struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->is_m)
     return XPSR_T;
@@ -628,7 +628,7 @@ arm_pc_is_thumb (struct gdbarch *gdbarch, CORE_ADDR memaddr)
   struct bound_minimal_symbol sym;
   char type;
   arm_displaced_step_copy_insn_closure *dsc = nullptr;
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (gdbarch_displaced_step_copy_insn_closure_by_addr_p (gdbarch))
     dsc = ((arm_displaced_step_copy_insn_closure * )
@@ -732,7 +732,7 @@ arm_pc_is_thumb (struct gdbarch *gdbarch, CORE_ADDR memaddr)
 static int
 arm_m_addr_is_magic (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   if (tdep->have_sec_ext)
     {
       switch ((addr & 0xff000000))
@@ -774,7 +774,7 @@ arm_m_addr_is_magic (struct gdbarch *gdbarch, CORE_ADDR addr)
 static CORE_ADDR
 arm_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR val)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* On M-profile devices, do not strip the low bit from EXC_RETURN
      (the magic exception return address).  */
@@ -1378,7 +1378,7 @@ thumb_analyze_prologue (struct gdbarch *gdbarch,
 	    }
 
 	  arm_gdbarch_tdep *tdep
-	    = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	    = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
 	  /* Make sure we are dealing with a target that supports ARMv8.1-m
 	     PACBTI.  */
@@ -1840,7 +1840,7 @@ arm_analyze_prologue (struct gdbarch *gdbarch,
   CORE_ADDR offset, current_pc;
   pv_t regs[ARM_FPS_REGNUM];
   CORE_ADDR unrecognized_pc = 0;
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Search the prologue looking for instructions that set up the
      frame pointer, adjust the stack pointer, and save registers.
@@ -2084,7 +2084,7 @@ arm_scan_prologue (struct frame_info *this_frame,
   CORE_ADDR prologue_start, prologue_end;
   CORE_ADDR prev_pc = get_frame_pc (this_frame);
   CORE_ADDR block_addr = get_frame_address_in_block (this_frame);
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Assume there is no frame until proven otherwise.  */
   cache->framereg = ARM_SP_REGNUM;
@@ -2189,7 +2189,7 @@ arm_make_prologue_cache (struct frame_info *this_frame)
     return cache;
 
   arm_gdbarch_tdep *tdep =
-    (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
 
   arm_cache_set_active_sp_value (cache, tdep, unwound_fp + cache->framesize);
 
@@ -2219,7 +2219,7 @@ arm_prologue_unwind_stop_reason (struct frame_info *this_frame,
   /* This is meant to halt the backtrace at "_start".  */
   pc = get_frame_pc (this_frame);
   gdbarch *arch = get_frame_arch (this_frame);
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (arch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (arch);
   if (pc <= tdep->lowest_pc)
     return UNWIND_OUTERMOST;
 
@@ -2247,7 +2247,7 @@ arm_prologue_this_id (struct frame_info *this_frame,
   cache = (struct arm_prologue_cache *) *this_cache;
 
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
 
   /* Use function start address as part of the frame ID.  If we cannot
      identify the start address (due to missing symbol information),
@@ -2274,7 +2274,7 @@ arm_prologue_prev_register (struct frame_info *this_frame,
     *this_cache = arm_make_prologue_cache (this_frame);
   cache = (struct arm_prologue_cache *) *this_cache;
 
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* If this frame has signed the return address, mark it as so.  */
   if (tdep->have_pacbti && cache->ra_signed_state.has_value ()
@@ -2947,7 +2947,7 @@ arm_exidx_fill_cache (struct frame_info *this_frame, gdb_byte *entry)
 
   /* We already got the previous SP.  */
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   arm_cache_set_active_sp_value (cache, tdep, vsp);
 
   return cache;
@@ -3072,7 +3072,7 @@ arm_make_epilogue_frame_cache (struct frame_info *this_frame)
 
   /* Since we are in epilogue, the SP has been restored.  */
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   arm_cache_set_active_sp_value (cache, tdep,
 				 get_frame_register_unsigned (this_frame,
 							      ARM_SP_REGNUM));
@@ -3111,7 +3111,7 @@ arm_epilogue_frame_this_id (struct frame_info *this_frame,
     func = pc;
 
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   *this_id = frame_id_build (arm_cache_get_prev_sp_value (cache, tdep), pc);
 }
 
@@ -3235,7 +3235,7 @@ arm_make_stub_cache (struct frame_info *this_frame)
   arm_cache_init (cache, this_frame);
 
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   arm_cache_set_active_sp_value (cache, tdep,
 				 get_frame_register_unsigned (this_frame,
 							      ARM_SP_REGNUM));
@@ -3257,7 +3257,7 @@ arm_stub_this_id (struct frame_info *this_frame,
   cache = (struct arm_prologue_cache *) *this_cache;
 
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   *this_id = frame_id_build (arm_cache_get_prev_sp_value (cache, tdep),
 			     get_frame_pc (this_frame));
 }
@@ -3305,7 +3305,7 @@ static struct arm_prologue_cache *
 arm_m_exception_cache (struct frame_info *this_frame)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct arm_prologue_cache *cache;
   CORE_ADDR lr;
@@ -3523,7 +3523,7 @@ arm_m_exception_this_id (struct frame_info *this_frame,
 
   /* Our frame ID for a stub frame is the current SP and LR.  */
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   *this_id = frame_id_build (arm_cache_get_prev_sp_value (cache, tdep),
 			     get_frame_pc (this_frame));
 }
@@ -3545,7 +3545,7 @@ arm_m_exception_prev_register (struct frame_info *this_frame,
 
   /* The value was already reconstructed into PREV_SP.  */
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   if (prev_regnum == ARM_SP_REGNUM)
     return frame_unwind_got_constant (this_frame, prev_regnum,
 				      arm_cache_get_prev_sp_value (cache, tdep));
@@ -3612,7 +3612,7 @@ arm_normal_frame_base (struct frame_info *this_frame, void **this_cache)
   cache = (struct arm_prologue_cache *) *this_cache;
 
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   return arm_cache_get_prev_sp_value (cache, tdep) - cache->framesize;
 }
 
@@ -3628,7 +3628,7 @@ arm_dwarf2_prev_register (struct frame_info *this_frame, void **this_cache,
 			  int regnum)
 {
   struct gdbarch * gdbarch = get_frame_arch (this_frame);
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   CORE_ADDR lr, cpsr;
   ULONGEST t_bit = arm_psr_thumb_bit (gdbarch);
 
@@ -4154,7 +4154,7 @@ arm_vfp_call_candidate (struct type *t, enum arm_vfp_cprc_base_type *base_type,
 static int
 arm_vfp_abi_for_function (struct gdbarch *gdbarch, struct type *func_type)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Variadic functions always use the base ABI.  Assume that functions
      without debug info are not variadic.  */
@@ -4188,7 +4188,7 @@ arm_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   int use_vfp_abi;
   struct type *ftype;
   unsigned vfp_regs_free = (1 << 16) - 1;
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Determine the type of this function and whether the VFP ABI
      applies.  */
@@ -4460,7 +4460,7 @@ arm_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
 static struct type *
 arm_ext_type (struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (!tdep->arm_ext_type)
     tdep->arm_ext_type
@@ -4473,7 +4473,7 @@ arm_ext_type (struct gdbarch *gdbarch)
 static struct type *
 arm_neon_double_type (struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->neon_double_type == NULL)
     {
@@ -4512,7 +4512,7 @@ arm_neon_double_type (struct gdbarch *gdbarch)
 static struct type *
 arm_neon_quad_type (struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->neon_quad_type == NULL)
     {
@@ -4550,7 +4550,7 @@ arm_neon_quad_type (struct gdbarch *gdbarch)
 static bool
 is_q_pseudo (struct gdbarch *gdbarch, int regnum)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Q pseudo registers are available for both NEON (Q0~Q15) and
      MVE (Q0~Q7) features.  */
@@ -4571,7 +4571,7 @@ is_q_pseudo (struct gdbarch *gdbarch, int regnum)
 static bool
 is_s_pseudo (struct gdbarch *gdbarch, int regnum)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->have_s_pseudos
       && regnum >= tdep->s_pseudo_base
@@ -4590,7 +4590,7 @@ is_s_pseudo (struct gdbarch *gdbarch, int regnum)
 static bool
 is_mve_pseudo (struct gdbarch *gdbarch, int regnum)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->have_mve
       && regnum >= tdep->mve_pseudo_base
@@ -4609,7 +4609,7 @@ is_mve_pseudo (struct gdbarch *gdbarch, int regnum)
 static bool
 is_pacbti_pseudo (struct gdbarch *gdbarch, int regnum)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->have_pacbti
       && regnum >= tdep->pacbti_pseudo_base
@@ -4625,7 +4625,7 @@ is_pacbti_pseudo (struct gdbarch *gdbarch, int regnum)
 static struct type *
 arm_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (is_s_pseudo (gdbarch, regnum))
     return builtin_type (gdbarch)->builtin_float;
@@ -4704,7 +4704,7 @@ arm_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
   /* PACBTI register containing the Pointer Authentication Code.  */
   if (reg == ARM_DWARF_RA_AUTH_CODE)
     {
-      arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
       if (tdep->have_pacbti)
 	return tdep->pacbti_pseudo_base;
@@ -4850,7 +4850,7 @@ arm_adjust_breakpoint_address (struct gdbarch *gdbarch, CORE_ADDR bpaddr)
   int buf_len;
   enum bfd_endian order = gdbarch_byte_order_for_code (gdbarch);
   int i, any, last_it, last_it_count;
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* If we are using BKPT breakpoints, none of this is necessary.  */
   if (tdep->thumb2_breakpoint == NULL)
@@ -8158,7 +8158,7 @@ arm_displaced_init_closure (struct gdbarch *gdbarch, CORE_ADDR from,
 			    CORE_ADDR to,
 			    arm_displaced_step_copy_insn_closure *dsc)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   unsigned int i, len, offset;
   enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
   int size = dsc->is_thumb? 2 : 4;
@@ -8321,7 +8321,7 @@ static const gdb_byte arm_default_thumb_be_breakpoint[] = THUMB_BE_BREAKPOINT;
 static int
 arm_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
 
   if (arm_pc_is_thumb (gdbarch, *pcptr))
@@ -8356,7 +8356,7 @@ arm_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 static const gdb_byte *
 arm_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   switch (kind)
     {
@@ -8428,7 +8428,7 @@ arm_extract_return_value (struct type *type, struct regcache *regs,
 {
   struct gdbarch *gdbarch = regs->arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (TYPE_CODE_FLT == type->code ())
     {
@@ -8539,7 +8539,7 @@ arm_return_in_memory (struct gdbarch *gdbarch, struct type *type)
       return (TYPE_LENGTH (type) > 16);
     }
 
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   if (tdep->arm_abi != ARM_ABI_APCS)
     {
       /* The AAPCS says all aggregates not larger than a word are returned
@@ -8645,7 +8645,7 @@ arm_store_return_value (struct type *type, struct regcache *regs,
   if (type->code () == TYPE_CODE_FLT)
     {
       gdb_byte buf[ARM_FP_REGISTER_SIZE];
-      arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
       switch (tdep->fp_model)
 	{
@@ -8734,7 +8734,7 @@ arm_return_value (struct gdbarch *gdbarch, struct value *function,
 		  struct type *valtype, struct regcache *regcache,
 		  gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   struct type *func_type = function ? value_type (function) : NULL;
   enum arm_vfp_cprc_base_type vfp_base_type;
   int vfp_base_count;
@@ -8826,7 +8826,7 @@ static int
 arm_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR jb_addr;
   gdb_byte buf[ARM_INT_REGISTER_SIZE];
@@ -9019,7 +9019,7 @@ show_fp_model (struct ui_file *file, int from_tty,
       && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm)
     {
       arm_gdbarch_tdep *tdep
-	= (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+	= gdbarch_tdep<arm_gdbarch_tdep> (target_gdbarch ());
 
       gdb_printf (file, _("\
 The current ARM floating point model is \"auto\" (currently \"%s\").\n"),
@@ -9059,7 +9059,7 @@ arm_show_abi (struct ui_file *file, int from_tty,
       && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm)
     {
       arm_gdbarch_tdep *tdep
-	= (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+	= gdbarch_tdep<arm_gdbarch_tdep> (target_gdbarch ());
 
       gdb_printf (file, _("\
 The current ARM ABI is \"auto\" (currently \"%s\").\n"),
@@ -9138,7 +9138,7 @@ show_disassembly_style_sfunc (struct ui_file *file, int from_tty,
 static const char *
 arm_register_name (struct gdbarch *gdbarch, int i)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (is_s_pseudo (gdbarch, i))
     {
@@ -9309,7 +9309,7 @@ static enum register_status
 arm_mve_pseudo_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 		     int regnum, gdb_byte *buf)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* P0 is the first 16 bits of VPR.  */
   return regcache->raw_read_part (tdep->mve_vpr_regnum, 0, 2, buf);
@@ -9323,7 +9323,7 @@ arm_pseudo_read (struct gdbarch *gdbarch, readable_regcache *regcache,
   char name_buf[4];
   gdb_byte reg_buf[8];
   int offset, double_regnum;
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   gdb_assert (regnum >= num_regs);
 
@@ -9395,7 +9395,7 @@ static void
 arm_mve_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache,
 		      int regnum, const gdb_byte *buf)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* P0 is the first 16 bits of VPR.  */
   regcache->raw_write_part (tdep->mve_vpr_regnum, 0, 2, buf);
@@ -9409,7 +9409,7 @@ arm_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache,
   char name_buf[4];
   gdb_byte reg_buf[8];
   int offset, double_regnum;
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   gdb_assert (regnum >= num_regs);
 
@@ -9497,7 +9497,7 @@ arm_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 static void
 arm_register_g_packet_guesses (struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->is_m)
     {
@@ -9540,7 +9540,7 @@ arm_register_g_packet_guesses (struct gdbarch *gdbarch)
 static int
 arm_code_of_frame_writable (struct gdbarch *gdbarch, struct frame_info *frame)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->is_m && get_frame_type (frame) == SIGTRAMP_FRAME)
     {
@@ -10099,7 +10099,7 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
     {
       arm_gdbarch_tdep *tdep
-	= (arm_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
+	= gdbarch_tdep<arm_gdbarch_tdep> (best_arch->gdbarch);
 
       if (arm_abi != ARM_ABI_AUTO && arm_abi != tdep->arm_abi)
 	continue;
@@ -10419,7 +10419,7 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 arm_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep == NULL)
     return;
@@ -12628,7 +12628,7 @@ arm_record_coproc_data_proc (insn_decode_record *arm_insn_r)
 {
   uint32_t op, op1_ebit, coproc, bits_24_25;
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (arm_insn_r->gdbarch);
+    = gdbarch_tdep<arm_gdbarch_tdep> (arm_insn_r->gdbarch);
   struct regcache *reg_cache = arm_insn_r->regcache;
 
   arm_insn_r->opcode = bits (arm_insn_r->arm_insn, 24, 27);
@@ -13116,7 +13116,7 @@ static int
 thumb_record_ldm_stm_swi (insn_decode_record *thumb_insn_r)
 {
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep  (thumb_insn_r->gdbarch);
+    = gdbarch_tdep<arm_gdbarch_tdep>  (thumb_insn_r->gdbarch);
   struct regcache *reg_cache = thumb_insn_r->regcache;
 
   uint32_t ret = 0; /* function return value: -1:record failure ;  0:success  */
diff --git a/gdb/arm-wince-tdep.c b/gdb/arm-wince-tdep.c
index 354c6fbca7f..5063b308809 100644
--- a/gdb/arm-wince-tdep.c
+++ b/gdb/arm-wince-tdep.c
@@ -115,7 +115,7 @@ arm_wince_skip_main_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
 static void
 arm_wince_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   windows_init_abi (info, gdbarch);
 
diff --git a/gdb/avr-tdep.c b/gdb/avr-tdep.c
index 9e73c507b2e..30042162edb 100644
--- a/gdb/avr-tdep.c
+++ b/gdb/avr-tdep.c
@@ -232,7 +232,7 @@ avr_register_type (struct gdbarch *gdbarch, int reg_nr)
   if (reg_nr == AVR_PC_REGNUM)
     return builtin_type (gdbarch)->builtin_uint32;
 
-  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
   if (reg_nr == AVR_PSEUDO_PC_REGNUM)
     return tdep->pc_type;
 
@@ -750,7 +750,7 @@ avr_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR pc_beg, CORE_ADDR pc_end,
   gdb_assert (vpc < AVR_MAX_PROLOGUE_SIZE);
 
   /* Handle static small stack allocation using rcall or push.  */
-  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
   while (scan_stage == 1 && vpc < len)
     {
       insn = extract_unsigned_integer (&prologue[vpc], 2, byte_order);
@@ -1053,7 +1053,7 @@ avr_frame_unwind_cache (struct frame_info *this_frame,
 
   /* The previous frame's SP needed to be computed.  Save the computed
      value.  */
-  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
   info->saved_regs[AVR_SP_REGNUM].set_value (info->prev_sp
 					     - 1 + tdep->call_length);
 
@@ -1135,7 +1135,7 @@ avr_frame_prev_register (struct frame_info *this_frame,
 	  int i;
 	  gdb_byte buf[3];
 	  struct gdbarch *gdbarch = get_frame_arch (this_frame);
-	  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
 
 	  read_memory (info->saved_regs[AVR_PC_REGNUM].addr (),
 		       buf, tdep->call_length);
@@ -1277,7 +1277,7 @@ avr_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 {
   int i;
   gdb_byte buf[3];
-  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
   int call_length = tdep->call_length;
   CORE_ADDR return_pc = avr_convert_iaddr_to_raw (bp_addr);
   int regnum = AVR_ARGN_REGNUM;
@@ -1461,7 +1461,7 @@ avr_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
     {
       avr_gdbarch_tdep *tdep
-	= (avr_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
+	= gdbarch_tdep<avr_gdbarch_tdep> (best_arch->gdbarch);
 
       if (tdep->call_length == call_length)
 	return best_arch->gdbarch;
diff --git a/gdb/bfin-tdep.c b/gdb/bfin-tdep.c
index 573eed94793..f232e22c37c 100644
--- a/gdb/bfin-tdep.c
+++ b/gdb/bfin-tdep.c
@@ -766,7 +766,7 @@ bfin_frame_align (struct gdbarch *gdbarch, CORE_ADDR address)
 enum bfin_abi
 bfin_abi (struct gdbarch *gdbarch)
 {
-  bfin_gdbarch_tdep *tdep = (bfin_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  bfin_gdbarch_tdep *tdep = gdbarch_tdep<bfin_gdbarch_tdep> (gdbarch);
   return tdep->bfin_abi;
 }
 
@@ -792,7 +792,7 @@ bfin_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       bfin_gdbarch_tdep *tdep
-	= (bfin_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<bfin_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->bfin_abi != abi)
 	continue;
diff --git a/gdb/cris-linux-tdep.c b/gdb/cris-linux-tdep.c
index f55f9b9083c..b3ed7450e99 100644
--- a/gdb/cris-linux-tdep.c
+++ b/gdb/cris-linux-tdep.c
@@ -33,7 +33,7 @@
 static void
 cris_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/cris-tdep.c b/gdb/cris-tdep.c
index 898d277b3fe..7cd73d34ca6 100644
--- a/gdb/cris-tdep.c
+++ b/gdb/cris-tdep.c
@@ -313,7 +313,7 @@ cris_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
 				  void **this_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct cris_unwind_cache *info;
   CORE_ADDR addr;
@@ -450,7 +450,7 @@ static int
 crisv32_single_step_through_delay (struct gdbarch *gdbarch,
 				   struct frame_info *this_frame)
 {
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   ULONGEST erp;
   int ret = 0;
 
@@ -695,7 +695,7 @@ cris_frame_unwind_cache (struct frame_info *this_frame,
 			 void **this_prologue_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   struct cris_unwind_cache *info;
 
   if ((*this_prologue_cache))
@@ -1333,7 +1333,7 @@ crisv32_scan_prologue (CORE_ADDR pc, struct frame_info *this_frame,
 static CORE_ADDR
 cris_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   CORE_ADDR func_addr, func_end;
   struct symtab_and_line sal;
   CORE_ADDR pc_after_prologue;
@@ -1368,7 +1368,7 @@ cris_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 static const gdb_byte *
 cris_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   static unsigned char break8_insn[] = {0x38, 0xe9};
   static unsigned char break15_insn[] = {0x3f, 0xe9};
 
@@ -1387,7 +1387,7 @@ static int
 cris_spec_reg_applicable (struct gdbarch *gdbarch,
 			  struct cris_spec_reg spec_reg)
 {
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   unsigned int version = tdep->cris_version;
   
   switch (spec_reg.applicable_version)
@@ -3766,7 +3766,7 @@ cris_supply_gregset (const struct regset *regset, struct regcache *regcache,
 		     int regnum, const void *gregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   int i;
   const cris_elf_greg_t *regp = static_cast<const cris_elf_greg_t *>(gregs);
 
@@ -3860,7 +3860,7 @@ Makes GDB use the NRP register instead of the ERP register in certain cases."),
 static void
 cris_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   if (tdep != NULL)
     {
       gdb_printf (file, "cris_dump_tdep: tdep->cris_version = %i\n",
@@ -3940,7 +3940,7 @@ cris_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       cris_gdbarch_tdep *tdep
-	= (cris_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<cris_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->cris_version == usr_cmd_cris_version
 	  && tdep->cris_mode == usr_cmd_cris_mode
diff --git a/gdb/frv-tdep.c b/gdb/frv-tdep.c
index 2328791a540..34f437764a9 100644
--- a/gdb/frv-tdep.c
+++ b/gdb/frv-tdep.c
@@ -93,7 +93,7 @@ struct frv_gdbarch_tdep : gdbarch_tdep
 enum frv_abi
 frv_abi (struct gdbarch *gdbarch)
 {
-  frv_gdbarch_tdep *tdep = (frv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  frv_gdbarch_tdep *tdep = gdbarch_tdep<frv_gdbarch_tdep> (gdbarch);
   return tdep->frv_abi;
 }
 
@@ -275,7 +275,7 @@ frv_register_name (struct gdbarch *gdbarch, int reg)
   if (reg >= frv_num_regs + frv_num_pseudo_regs)
     return "?toolarge?";
 
-  frv_gdbarch_tdep *tdep = (frv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  frv_gdbarch_tdep *tdep = gdbarch_tdep<frv_gdbarch_tdep> (gdbarch);
   return tdep->register_names[reg];
 }
 
diff --git a/gdb/ft32-tdep.c b/gdb/ft32-tdep.c
index f77e313e0dd..024ca47ce4d 100644
--- a/gdb/ft32-tdep.c
+++ b/gdb/ft32-tdep.c
@@ -110,7 +110,7 @@ ft32_register_type (struct gdbarch *gdbarch, int reg_nr)
 {
   if (reg_nr == FT32_PC_REGNUM)
     {
-      ft32_gdbarch_tdep *tdep = (ft32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      ft32_gdbarch_tdep *tdep = gdbarch_tdep<ft32_gdbarch_tdep> (gdbarch);
       return tdep->pc_type;
     }
   else if (reg_nr == FT32_SP_REGNUM || reg_nr == FT32_FP_REGNUM)
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index 3a7b7f92ef7..b2c91db0c4f 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -142,8 +142,23 @@ using read_core_file_mappings_loop_ftype =
 
 #include "gdbarch-gen.h"
 
-extern struct gdbarch_tdep *gdbarch_tdep (struct gdbarch *gdbarch);
+/* An internal function that should _only_ be called from gdbarch_tdep.
+   Returns the gdbarch_tdep field held within GDBARCH.  */
 
+extern struct gdbarch_tdep *gdbarch_tdep_1 (struct gdbarch *gdbarch);
+
+/* Return the gdbarch_tdep object held within GDBARCH cast to the type
+   TDepType, which should be a sub-class of gdbarch_tdep.  There is no
+   checking done that the gdbarch_tdep within GDBARCH actually is of the
+   type TDepType, we just assume the caller knows what they are doing.  */
+
+template<typename TDepType>
+static inline TDepType *
+gdbarch_tdep (struct gdbarch *gdbarch)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep_1 (gdbarch);
+  return static_cast<TDepType *> (tdep);
+}
 
 /* Mechanism for co-ordinating the selection of a specific
    architecture.
diff --git a/gdb/hppa-bsd-tdep.c b/gdb/hppa-bsd-tdep.c
index 34f57d2512a..c405511529d 100644
--- a/gdb/hppa-bsd-tdep.c
+++ b/gdb/hppa-bsd-tdep.c
@@ -118,7 +118,7 @@ hppabsd_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
 void
 hppabsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
 
   /* OpenBSD and NetBSD have a 64-bit 'long double'.  */
   set_gdbarch_long_double_bit (gdbarch, 64);
diff --git a/gdb/hppa-linux-tdep.c b/gdb/hppa-linux-tdep.c
index 40e32c115d2..f17d2ae6b02 100644
--- a/gdb/hppa-linux-tdep.c
+++ b/gdb/hppa-linux-tdep.c
@@ -476,7 +476,7 @@ hppa_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					 void *cb_data,
 					 const struct regcache *regcache)
 {
-  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
 
   cb (".reg", 80 * tdep->bytes_per_address, 80 * tdep->bytes_per_address,
       &hppa_linux_regset, NULL, cb_data);
@@ -486,7 +486,7 @@ hppa_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 static void
 hppa_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/hppa-tdep.c b/gdb/hppa-tdep.c
index f9ececbb04f..9f93a945a6a 100644
--- a/gdb/hppa-tdep.c
+++ b/gdb/hppa-tdep.c
@@ -247,7 +247,7 @@ internalize_unwinds (struct objfile *objfile, struct unwind_table_entry *table,
   if (size > 0)
     {
       struct gdbarch *gdbarch = objfile->arch ();
-      hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
       unsigned long tmp;
       unsigned i;
       char *buf = (char *) alloca (size);
@@ -718,7 +718,7 @@ hppa32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   /* Global pointer (r19) of the function we are trying to call.  */
   CORE_ADDR gp;
 
-  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
 
   for (write_pass = 0; write_pass < 2; write_pass++)
     {
@@ -955,7 +955,7 @@ hppa64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 			function_call_return_method return_method,
 			CORE_ADDR struct_addr)
 {
-  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int i, offset = 0;
   CORE_ADDR gp;
@@ -2241,7 +2241,7 @@ hppa_frame_cache (struct frame_info *this_frame, void **this_cache)
   }
 
   {
-    hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+    hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
 
     if (tdep->unwind_adjust_stub)
       tdep->unwind_adjust_stub (this_frame, cache->base, cache->saved_regs);
@@ -2471,7 +2471,7 @@ hppa_stub_unwind_sniffer (const struct frame_unwind *self,
 {
   CORE_ADDR pc = get_frame_address_in_block (this_frame);
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
 
   if (pc == 0
       || (tdep->in_solib_call_trampoline != NULL
@@ -3147,7 +3147,7 @@ hppa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 hppa_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
 
   gdb_printf (file, "bytes_per_address = %d\n", 
 	      tdep->bytes_per_address);
diff --git a/gdb/i386-bsd-tdep.c b/gdb/i386-bsd-tdep.c
index b38f8d05887..dbbd3c786c3 100644
--- a/gdb/i386-bsd-tdep.c
+++ b/gdb/i386-bsd-tdep.c
@@ -74,7 +74,7 @@ int i386bsd_sc_reg_offset[] =
 void
 i386bsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   tdep->jb_pc_offset = 0;
 
diff --git a/gdb/i386-darwin-tdep.c b/gdb/i386-darwin-tdep.c
index dc780583766..2a9198aceb3 100644
--- a/gdb/i386-darwin-tdep.c
+++ b/gdb/i386-darwin-tdep.c
@@ -156,7 +156,7 @@ i386_darwin_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 			     function_call_return_method return_method,
 			     CORE_ADDR struct_addr)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   gdb_byte buf[4];
   int i;
@@ -248,7 +248,7 @@ i386_darwin_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 static void
 i386_darwin_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* We support the SSE registers.  */
   tdep->num_xmm_regs = I386_NUM_XREGS - 1;
diff --git a/gdb/i386-fbsd-tdep.c b/gdb/i386-fbsd-tdep.c
index d68498cd5e9..b7a524db68c 100644
--- a/gdb/i386-fbsd-tdep.c
+++ b/gdb/i386-fbsd-tdep.c
@@ -325,7 +325,7 @@ i386fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				       void *cb_data,
 				       const struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   cb (".reg", I386_FBSD_SIZEOF_GREGSET, I386_FBSD_SIZEOF_GREGSET,
       &i386_fbsd_gregset, NULL, cb_data);
@@ -365,7 +365,7 @@ i386fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 static void
 i386fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support. */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/i386-gnu-tdep.c b/gdb/i386-gnu-tdep.c
index 51c253d2dfe..3d97fe36a85 100644
--- a/gdb/i386-gnu-tdep.c
+++ b/gdb/i386-gnu-tdep.c
@@ -173,7 +173,7 @@ static int i386gnu_gregset_reg_offset[] =
 static void
 i386gnu_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* GNU uses ELF.  */
   i386_elf_init_abi (info, gdbarch);
diff --git a/gdb/i386-go32-tdep.c b/gdb/i386-go32-tdep.c
index 15ac38dc12f..0c0c08e3579 100644
--- a/gdb/i386-go32-tdep.c
+++ b/gdb/i386-go32-tdep.c
@@ -26,7 +26,7 @@
 static void
 i386_go32_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* DJGPP doesn't have any special frames for signal handlers.  */
   tdep->sigtramp_p = NULL;
diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c
index 5d7f54194af..6033104230f 100644
--- a/gdb/i386-linux-tdep.c
+++ b/gdb/i386-linux-tdep.c
@@ -763,7 +763,7 @@ i386_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					 void *cb_data,
 					 const struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   cb (".reg", 68, 68, &i386_gregset, NULL, cb_data);
 
@@ -825,7 +825,7 @@ i386_linux_displaced_step_copy_insn (struct gdbarch *gdbarch,
 static void
 i386_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   const struct target_desc *tdesc = info.target_desc;
   struct tdesc_arch_data *tdesc_data = info.tdesc_data;
   const struct tdesc_feature *feature;
diff --git a/gdb/i386-netbsd-tdep.c b/gdb/i386-netbsd-tdep.c
index 2cee1b94760..a9ebc3dd827 100644
--- a/gdb/i386-netbsd-tdep.c
+++ b/gdb/i386-netbsd-tdep.c
@@ -372,7 +372,7 @@ i386nbsd_sigtramp_cache_init (const struct tramp_frame *self,
 static void 
 i386nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* Obviously NetBSD is BSD-based.  */
   i386bsd_init_abi (info, gdbarch);
@@ -407,7 +407,7 @@ i386nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 static void
 i386nbsdelf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* It's still NetBSD.  */
   i386nbsd_init_abi (info, gdbarch);
diff --git a/gdb/i386-nto-tdep.c b/gdb/i386-nto-tdep.c
index 6716329149b..259867f262b 100644
--- a/gdb/i386-nto-tdep.c
+++ b/gdb/i386-nto-tdep.c
@@ -77,7 +77,7 @@ static void
 i386nto_supply_gregset (struct regcache *regcache, char *gpregs)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   gdb_assert (tdep->gregset_reg_offset == i386nto_gregset_reg_offset);
   i386_gregset.supply_regset (&i386_gregset, regcache, -1,
@@ -126,7 +126,7 @@ static int
 i386nto_register_area (struct gdbarch *gdbarch,
 		       int regno, int regset, unsigned *off)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   *off = 0;
   if (regset == NTO_REG_GENERAL)
@@ -315,7 +315,7 @@ init_i386nto_ops (void)
 static void
 i386nto_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   static struct target_so_ops nto_svr4_so_ops;
 
   /* Deal with our strange signals.  */
diff --git a/gdb/i386-obsd-tdep.c b/gdb/i386-obsd-tdep.c
index b1f4d6c5e8d..798094509c6 100644
--- a/gdb/i386-obsd-tdep.c
+++ b/gdb/i386-obsd-tdep.c
@@ -407,7 +407,7 @@ static const struct frame_unwind i386obsd_trapframe_unwind = {
 static void 
 i386obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* Obviously OpenBSD is BSD-based.  */
   i386bsd_init_abi (info, gdbarch);
diff --git a/gdb/i386-sol2-tdep.c b/gdb/i386-sol2-tdep.c
index e8a3ba20045..5ee108d3578 100644
--- a/gdb/i386-sol2-tdep.c
+++ b/gdb/i386-sol2-tdep.c
@@ -65,7 +65,7 @@ i386_sol2_mcontext_addr (struct frame_info *this_frame)
 static void
 i386_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* Solaris is SVR4-based.  */
   i386_svr4_init_abi (info, gdbarch);
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 8501e12e241..d500f6998c5 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -169,7 +169,7 @@ const int num_lower_zmm_regs = 16;
 static int
 i386_mmx_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int mm0_regnum = tdep->mm0_regnum;
 
   if (mm0_regnum < 0)
@@ -184,7 +184,7 @@ i386_mmx_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_byte_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   regnum -= tdep->al_regnum;
   return regnum >= 0 && regnum < tdep->num_byte_regs;
@@ -195,7 +195,7 @@ i386_byte_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_word_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   regnum -= tdep->ax_regnum;
   return regnum >= 0 && regnum < tdep->num_word_regs;
@@ -206,7 +206,7 @@ i386_word_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_dword_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int eax_regnum = tdep->eax_regnum;
 
   if (eax_regnum < 0)
@@ -221,7 +221,7 @@ i386_dword_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_zmmh_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int zmm0h_regnum = tdep->zmm0h_regnum;
 
   if (zmm0h_regnum < 0)
@@ -234,7 +234,7 @@ i386_zmmh_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_zmm_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int zmm0_regnum = tdep->zmm0_regnum;
 
   if (zmm0_regnum < 0)
@@ -247,7 +247,7 @@ i386_zmm_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_k_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int k0_regnum = tdep->k0_regnum;
 
   if (k0_regnum < 0)
@@ -260,7 +260,7 @@ i386_k_regnum_p (struct gdbarch *gdbarch, int regnum)
 static int
 i386_ymmh_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int ymm0h_regnum = tdep->ymm0h_regnum;
 
   if (ymm0h_regnum < 0)
@@ -275,7 +275,7 @@ i386_ymmh_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_ymm_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int ymm0_regnum = tdep->ymm0_regnum;
 
   if (ymm0_regnum < 0)
@@ -288,7 +288,7 @@ i386_ymm_regnum_p (struct gdbarch *gdbarch, int regnum)
 static int
 i386_ymmh_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int ymm16h_regnum = tdep->ymm16h_regnum;
 
   if (ymm16h_regnum < 0)
@@ -301,7 +301,7 @@ i386_ymmh_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_ymm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int ymm16_regnum = tdep->ymm16_regnum;
 
   if (ymm16_regnum < 0)
@@ -316,7 +316,7 @@ i386_ymm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_bnd_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int bnd0_regnum = tdep->bnd0_regnum;
 
   if (bnd0_regnum < 0)
@@ -331,7 +331,7 @@ i386_bnd_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_xmm_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int num_xmm_regs = I387_NUM_XMM_REGS (tdep);
 
   if (num_xmm_regs == 0)
@@ -346,7 +346,7 @@ i386_xmm_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_xmm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int num_xmm_avx512_regs = I387_NUM_XMM_AVX512_REGS (tdep);
 
   if (num_xmm_avx512_regs == 0)
@@ -359,7 +359,7 @@ i386_xmm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 static int
 i386_mxcsr_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (I387_NUM_XMM_REGS (tdep) == 0)
     return 0;
@@ -372,7 +372,7 @@ i386_mxcsr_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_fp_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (I387_ST0_REGNUM (tdep) < 0)
     return 0;
@@ -384,7 +384,7 @@ i386_fp_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_fpc_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (I387_ST0_REGNUM (tdep) < 0)
     return 0;
@@ -398,7 +398,7 @@ i386_fpc_regnum_p (struct gdbarch *gdbarch, int regnum)
 static int
 i386_bndr_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
    if (I387_BND0R_REGNUM (tdep) < 0)
      return 0;
@@ -412,7 +412,7 @@ i386_bndr_regnum_p (struct gdbarch *gdbarch, int regnum)
 static int
 i386_mpx_ctrl_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
    if (I387_BNDCFGU_REGNUM (tdep) < 0)
      return 0;
@@ -426,7 +426,7 @@ i386_mpx_ctrl_regnum_p (struct gdbarch *gdbarch, int regnum)
 bool
 i386_pkru_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int pkru_regnum = tdep->pkru_regnum;
 
   if (pkru_regnum < 0)
@@ -462,7 +462,7 @@ i386_register_name (struct gdbarch *gdbarch, int regnum)
 const char *
 i386_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   if (i386_bnd_regnum_p (gdbarch, regnum))
     return i386_bnd_names[regnum - tdep->bnd0_regnum];
   if (i386_mmx_regnum_p (gdbarch, regnum))
@@ -485,7 +485,7 @@ i386_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 static int
 i386_dbx_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* This implements what GCC calls the "default" register map
      (dbx_register_map[]).  */
@@ -532,7 +532,7 @@ i386_dbx_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 static int
 i386_svr4_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* This implements the GCC register map that tries to be compatible
      with the SVR4 C compiler for DWARF (svr4_dbx_register_map[]).  */
@@ -2434,7 +2434,7 @@ static struct i386_frame_cache *
 i386_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct i386_frame_cache *cache;
   CORE_ADDR addr;
@@ -2524,7 +2524,7 @@ i386_sigtramp_frame_sniffer (const struct frame_unwind *self,
 			     void **this_prologue_cache)
 {
   gdbarch *arch = get_frame_arch (this_frame);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
 
   /* We shouldn't even bother if we don't have a sigcontext_addr
      handler.  */
@@ -2611,7 +2611,7 @@ i386_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
   CORE_ADDR sp, jb_addr;
   struct gdbarch *gdbarch = get_frame_arch (frame);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int jb_pc_offset = tdep->jb_pc_offset;
 
   /* If JB_PC_OFFSET is -1, we have no way to find out where the
@@ -2860,7 +2860,7 @@ static void
 i386_extract_return_value (struct gdbarch *gdbarch, struct type *type,
 			   struct regcache *regcache, gdb_byte *valbuf)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int len = TYPE_LENGTH (type);
   gdb_byte buf[I386_MAX_REGISTER_SIZE];
 
@@ -2918,7 +2918,7 @@ static void
 i386_store_return_value (struct gdbarch *gdbarch, struct type *type,
 			 struct regcache *regcache, const gdb_byte *valbuf)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int len = TYPE_LENGTH (type);
 
   if (type->code () == TYPE_CODE_FLT)
@@ -2997,7 +2997,7 @@ static const char *struct_convention = default_struct_convention;
 static int
 i386_reg_struct_return_p (struct gdbarch *gdbarch, struct type *type)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   enum type_code code = type->code ();
   int len = TYPE_LENGTH (type);
 
@@ -3099,7 +3099,7 @@ i386_return_value (struct gdbarch *gdbarch, struct value *function,
 struct type *
 i387_ext_type (struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (!tdep->i387_ext_type)
     {
@@ -3117,7 +3117,7 @@ i387_ext_type (struct gdbarch *gdbarch)
 static struct type *
 i386_bnd_type (struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
 
   if (!tdep->i386_bnd_type)
@@ -3153,7 +3153,7 @@ i386_bnd_type (struct gdbarch *gdbarch)
 static struct type *
 i386_zmm_type (struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (!tdep->i386_zmm_type)
     {
@@ -3212,7 +3212,7 @@ i386_zmm_type (struct gdbarch *gdbarch)
 static struct type *
 i386_ymm_type (struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (!tdep->i386_ymm_type)
     {
@@ -3269,7 +3269,7 @@ i386_ymm_type (struct gdbarch *gdbarch)
 static struct type *
 i386_mmx_type (struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (!tdep->i386_mmx_type)
     {
@@ -3346,7 +3346,7 @@ static int
 i386_mmx_regnum_to_fp_regnum (readable_regcache *regcache, int regnum)
 {
   gdbarch *arch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
   int mmxreg, fpreg;
   ULONGEST fstat;
   int tos;
@@ -3387,7 +3387,7 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
     }
   else
     {
-      i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
       if (i386_bnd_regnum_p (gdbarch, regnum))
 	{
 	  regnum -= tdep->bnd0_regnum;
@@ -3577,7 +3577,7 @@ i386_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
     }
   else
     {
-      i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
       if (i386_bnd_regnum_p (gdbarch, regnum))
 	{
@@ -3685,7 +3685,7 @@ int
 i386_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				 struct agent_expr *ax, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (i386_mmx_regnum_p (gdbarch, regnum))
     {
@@ -3902,7 +3902,7 @@ i386_supply_gregset (const struct regset *regset, struct regcache *regcache,
 		     int regnum, const void *gregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   const gdb_byte *regs = (const gdb_byte *) gregs;
   int i;
 
@@ -3927,7 +3927,7 @@ i386_collect_gregset (const struct regset *regset,
 		      int regnum, void *gregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   gdb_byte *regs = (gdb_byte *) gregs;
   int i;
 
@@ -3950,7 +3950,7 @@ i386_supply_fpregset (const struct regset *regset, struct regcache *regcache,
 		      int regnum, const void *fpregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (len == I387_SIZEOF_FXSAVE)
     {
@@ -3973,7 +3973,7 @@ i386_collect_fpregset (const struct regset *regset,
 		       int regnum, void *fpregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (len == I387_SIZEOF_FXSAVE)
     {
@@ -4005,7 +4005,7 @@ i386_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				   void *cb_data,
 				   const struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   cb (".reg", tdep->sizeof_gregset, tdep->sizeof_gregset, &i386_gregset, NULL,
       cb_data);
@@ -4510,7 +4510,7 @@ i386_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 void
 i386_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* System V Release 4 uses ELF.  */
   i386_elf_init_abi (info, gdbarch);
@@ -4552,7 +4552,7 @@ int
 i386_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 			  const struct reggroup *group)
 {
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int fp_regnum_p, mmx_regnum_p, xmm_regnum_p, mxcsr_regnum_p,
       ymm_regnum_p, ymmh_regnum_p, ymm_avx512_regnum_p, ymmh_avx512_regnum_p,
       bndr_regnum_p, bnd_regnum_p, zmm_regnum_p, zmmh_regnum_p,
@@ -4997,7 +4997,7 @@ static int i386_record_floats (struct gdbarch *gdbarch,
 			       struct i386_record_s *ir,
 			       uint32_t iregnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int i;
 
   /* Oza: Because of floating point insn push/pop of fpu stack is going to
@@ -5068,7 +5068,7 @@ i386_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
   ULONGEST addr;
   gdb_byte buf[I386_MAX_REGISTER_SIZE];
   struct i386_record_s ir;
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   uint8_t rex_w = -1;
   uint8_t rex_r = 0;
 
@@ -8839,7 +8839,7 @@ i386_mpx_bd_base (void)
 
   rcache = get_current_regcache ();
   gdbarch *arch = rcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
 
   regstatus = regcache_raw_read_unsigned (rcache, tdep->bndcfgu_regnum, &ret);
 
@@ -8853,7 +8853,7 @@ int
 i386_mpx_enabled (void)
 {
   gdbarch *arch = get_current_arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
   const struct target_desc *tdesc = tdep->tdesc;
 
   return (tdesc_find_feature (tdesc, "org.gnu.gdb.i386.mpx") != NULL);
diff --git a/gdb/i386-windows-tdep.c b/gdb/i386-windows-tdep.c
index 8e1cc17b91c..9eec6e28109 100644
--- a/gdb/i386-windows-tdep.c
+++ b/gdb/i386-windows-tdep.c
@@ -136,7 +136,7 @@ i386_windows_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 static void
 i386_windows_init_abi_common (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   set_gdbarch_skip_trampoline_code (gdbarch, i386_windows_skip_trampoline_code);
 
diff --git a/gdb/i387-tdep.c b/gdb/i387-tdep.c
index f056ea59347..42ed4eebc2c 100644
--- a/gdb/i387-tdep.c
+++ b/gdb/i387-tdep.c
@@ -204,7 +204,7 @@ void
 i387_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
 		       struct frame_info *frame, const char *args)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   ULONGEST fctrl;
   int fctrl_p;
   ULONGEST fstat;
@@ -440,7 +440,7 @@ void
 i387_supply_fsave (struct regcache *regcache, int regnum, const void *fsave)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   const gdb_byte *regs = (const gdb_byte *) fsave;
   int i;
@@ -495,7 +495,7 @@ void
 i387_collect_fsave (const struct regcache *regcache, int regnum, void *fsave)
 {
   gdbarch *arch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
   gdb_byte *regs = (gdb_byte *) fsave;
   int i;
 
@@ -589,7 +589,7 @@ void
 i387_supply_fxsave (struct regcache *regcache, int regnum, const void *fxsave)
 {
   gdbarch *arch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
   const gdb_byte *regs = (const gdb_byte *) fxsave;
   int i;
 
@@ -673,7 +673,7 @@ void
 i387_collect_fxsave (const struct regcache *regcache, int regnum, void *fxsave)
 {
   gdbarch *arch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
   gdb_byte *regs = (gdb_byte *) fxsave;
   int i;
 
@@ -906,7 +906,7 @@ i387_xsave_get_clear_bv (struct gdbarch *gdbarch, const void *xsave)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   const gdb_byte *regs = (const gdb_byte *) xsave;
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* Get `xstat_bv'.  The supported bits in `xstat_bv' are 8 bytes.  */
   ULONGEST xstate_bv = extract_unsigned_integer (XSAVE_XSTATE_BV_ADDR (regs),
@@ -926,7 +926,7 @@ i387_supply_xsave (struct regcache *regcache, int regnum,
 {
   struct gdbarch *gdbarch = regcache->arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   const gdb_byte *regs = (const gdb_byte *) xsave;
   int i;
   /* In 64-bit mode the split between "low" and "high" ZMM registers is at
@@ -1349,7 +1349,7 @@ i387_collect_xsave (const struct regcache *regcache, int regnum,
 {
   struct gdbarch *gdbarch = regcache->arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   gdb_byte *p, *regs = (gdb_byte *) xsave;
   gdb_byte raw[I386_MAX_REGISTER_SIZE];
   ULONGEST initial_xstate_bv, clear_bv, xstate_bv = 0;
@@ -1934,7 +1934,7 @@ i387_tag (const gdb_byte *raw)
 void
 i387_return_value (struct gdbarch *gdbarch, struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   ULONGEST fstat;
 
   /* Set the top of the floating-point register stack to 7.  The
@@ -1957,7 +1957,7 @@ i387_return_value (struct gdbarch *gdbarch, struct regcache *regcache)
 void
 i387_reset_bnd_regs (struct gdbarch *gdbarch, struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (I387_BND0R_REGNUM (tdep) > 0)
     {
diff --git a/gdb/ia64-linux-tdep.c b/gdb/ia64-linux-tdep.c
index 64a57f5bf2f..508d4e6f7c6 100644
--- a/gdb/ia64-linux-tdep.c
+++ b/gdb/ia64-linux-tdep.c
@@ -216,7 +216,7 @@ ia64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 static void
 ia64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
   static const char *const stap_register_prefixes[] = { "r", NULL };
   static const char *const stap_register_indirection_prefixes[] = { "[",
 								    NULL };
diff --git a/gdb/ia64-tdep.c b/gdb/ia64-tdep.c
index dd6d5b199b2..eb0b9ec6a52 100644
--- a/gdb/ia64-tdep.c
+++ b/gdb/ia64-tdep.c
@@ -310,7 +310,7 @@ static const struct floatformat *floatformats_ia64_ext[2] =
 static struct type *
 ia64_ext_type (struct gdbarch *gdbarch)
 {
-  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
 
   if (!tdep->ia64_ext_type)
     tdep->ia64_ext_type
@@ -2177,7 +2177,7 @@ ia64_sigtramp_frame_init_saved_regs (struct frame_info *this_frame,
 				     struct ia64_frame_cache *cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
 
   if (tdep->sigcontext_register_address)
     {
@@ -2336,7 +2336,7 @@ ia64_sigtramp_frame_sniffer (const struct frame_unwind *self,
 			     void **this_cache)
 {
   gdbarch *arch = get_frame_arch (this_frame);
-  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (arch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (arch);
   if (tdep->pc_in_sigtramp)
     {
       CORE_ADDR pc = get_frame_pc (this_frame);
@@ -2485,7 +2485,7 @@ ia64_access_reg (unw_addr_space_t as, unw_regnum_t uw_regnum, unw_word_t *val,
   unw_word_t bsp, sof, cfm, psr, ip;
   struct frame_info *this_frame = (struct frame_info *) arg;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
   
   /* We never call any libunwind routines that need to write registers.  */
   gdb_assert (!write);
@@ -3484,7 +3484,7 @@ ia64_find_global_pointer_from_dynamic_section (struct gdbarch *gdbarch,
 static CORE_ADDR
 ia64_find_global_pointer (struct gdbarch *gdbarch, CORE_ADDR faddr)
 {
-  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
   CORE_ADDR addr = 0;
 
   if (tdep->find_global_pointer_from_solib)
@@ -3679,7 +3679,7 @@ ia64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 		      function_call_return_method return_method,
 		      CORE_ADDR struct_addr)
 {
-  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int argno;
   struct value *arg;
diff --git a/gdb/loongarch-linux-nat.c b/gdb/loongarch-linux-nat.c
index edc3d697d7b..689c10bd57e 100644
--- a/gdb/loongarch-linux-nat.c
+++ b/gdb/loongarch-linux-nat.c
@@ -51,7 +51,7 @@ static void
 fetch_gregs_from_thread (struct regcache *regcache, int regno, pid_t tid)
 {
   loongarch_gdbarch_tdep *tdep
-    = (loongarch_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<loongarch_gdbarch_tdep> (regcache->arch ());
   auto regs = tdep->regs;
   elf_gregset_t regset;
 
@@ -78,7 +78,7 @@ static void
 store_gregs_to_thread (struct regcache *regcache, int regno, pid_t tid)
 {
   loongarch_gdbarch_tdep *tdep
-    = (loongarch_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<loongarch_gdbarch_tdep> (regcache->arch ());
   auto regs = tdep->regs;
   elf_gregset_t regset;
 
@@ -131,7 +131,7 @@ loongarch_linux_nat_target::register_u_offset (struct gdbarch *gdbarch,
 					       int regno, int store_p)
 {
   loongarch_gdbarch_tdep *tdep
-    = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+    = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
   auto regs = tdep->regs;
 
   /* According to <asm/ptrace.h> */
diff --git a/gdb/loongarch-linux-tdep.c b/gdb/loongarch-linux-tdep.c
index f6854298569..b76d8240f6e 100644
--- a/gdb/loongarch-linux-tdep.c
+++ b/gdb/loongarch-linux-tdep.c
@@ -42,7 +42,7 @@ loongarch_supply_gregset (const struct regset *r,
 			  const void *gprs, size_t len)
 {
   loongarch_gdbarch_tdep *tdep
-    = (loongarch_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<loongarch_gdbarch_tdep> (regcache->arch ());
   auto regs = tdep->regs;
 
   int regsize = register_size (regcache->arch (), regs.r);
@@ -86,7 +86,7 @@ loongarch_fill_gregset (const struct regset *r,
 			void *gprs, size_t len)
 {
   loongarch_gdbarch_tdep *tdep
-    = (loongarch_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<loongarch_gdbarch_tdep> (regcache->arch ());
   auto regs = tdep->regs;
   int regsize = register_size (regcache->arch (), regs.r);
   gdb_byte *buf = nullptr;
@@ -137,7 +137,7 @@ loongarch_linux_rt_sigframe_init (const struct tramp_frame *self,
 				  CORE_ADDR func)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  loongarch_gdbarch_tdep *tdep = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
   auto regs = tdep->regs;
 
   CORE_ADDR frame_sp = get_frame_sp (this_frame);
@@ -178,7 +178,7 @@ loongarch_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					const struct regcache *regcache)
 {
   loongarch_gdbarch_tdep *tdep
-    = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+    = gdbarch_tdep<loongarch_gdbarch_tdep> (regcache->arch ());
   auto regs = tdep->regs;
   int regsize = register_size (gdbarch, regs.r);
 
diff --git a/gdb/loongarch-tdep.c b/gdb/loongarch-tdep.c
index 8e74c9b779d..30ac9bd298b 100644
--- a/gdb/loongarch-tdep.c
+++ b/gdb/loongarch-tdep.c
@@ -74,7 +74,7 @@ loongarch_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc,
 			 struct trad_frame_cache *this_cache)
 {
   CORE_ADDR cur_pc = start_pc, prologue_end = 0;
-  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  loongarch_gdbarch_tdep *tdep = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
   auto regs = tdep->regs;
   int32_t sp = regs.r + 3;
   int32_t fp = regs.r + 22;
@@ -202,7 +202,7 @@ loongarch_frame_cache (struct frame_info *this_frame, void **this_cache)
   cache = trad_frame_cache_zalloc (this_frame);
   *this_cache = cache;
 
-  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  loongarch_gdbarch_tdep *tdep = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
   trad_frame_set_reg_realreg (cache, gdbarch_pc_regnum (gdbarch), tdep->regs.ra);
 
   pc = get_frame_address_in_block (this_frame);
@@ -254,7 +254,7 @@ loongarch_return_value (struct gdbarch *gdbarch, struct value *function,
 			struct type *type, struct regcache *regcache,
 			gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  loongarch_gdbarch_tdep *tdep = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
   auto regs = tdep->regs;
   int len = TYPE_LENGTH (type);
   int regnum = -1;
@@ -282,7 +282,7 @@ loongarch_return_value (struct gdbarch *gdbarch, struct value *function,
 static int
 loongarch_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int num)
 {
-  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  loongarch_gdbarch_tdep *tdep = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
   auto regs = tdep->regs;
 
   if (0 <= num && num < 32)
@@ -408,7 +408,7 @@ loongarch_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 	 we are looking for.  If it doesn't then we can't reuse this
 	 gdbarch.  */
       loongarch_gdbarch_tdep *candidate_tdep
-	= (loongarch_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<loongarch_gdbarch_tdep> (arches->gdbarch);
 
       if (candidate_tdep->abi_features != abi_features)
 	continue;
diff --git a/gdb/m32c-tdep.c b/gdb/m32c-tdep.c
index 4971be796cd..37456d16cb3 100644
--- a/gdb/m32c-tdep.c
+++ b/gdb/m32c-tdep.c
@@ -142,7 +142,7 @@ struct m32c_gdbarch_tdep : gdbarch_tdep
 static void
 make_types (struct gdbarch *arch)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   unsigned long mach = gdbarch_bfd_arch_info (arch)->mach;
   int data_addr_reg_bits, code_addr_reg_bits;
   char type_name[50];
@@ -215,7 +215,7 @@ make_types (struct gdbarch *arch)
 static const char *
 m32c_register_name (struct gdbarch *gdbarch, int num)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   return tdep->regs[num].name;
 }
 
@@ -223,7 +223,7 @@ m32c_register_name (struct gdbarch *gdbarch, int num)
 static struct type *
 m32c_register_type (struct gdbarch *arch, int reg_nr)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   return tdep->regs[reg_nr].type;
 }
 
@@ -231,7 +231,7 @@ m32c_register_type (struct gdbarch *arch, int reg_nr)
 static int
 m32c_register_sim_regno (struct gdbarch *gdbarch, int reg_nr)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   return tdep->regs[reg_nr].sim_num;
 }
 
@@ -239,7 +239,7 @@ m32c_register_sim_regno (struct gdbarch *gdbarch, int reg_nr)
 static int
 m32c_debug_info_reg_to_regnum (struct gdbarch *gdbarch, int reg_nr)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   if (0 <= reg_nr && reg_nr <= M32C_MAX_DWARF_REGNUM
       && tdep->dwarf_regs[reg_nr])
     return tdep->dwarf_regs[reg_nr]->num;
@@ -254,7 +254,7 @@ static int
 m32c_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 			  const struct reggroup *group)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   struct m32c_reg *reg = &tdep->regs[regnum];
 
   /* The anonymous raw registers aren't in any groups.  */
@@ -330,7 +330,7 @@ static int
 m32c_read_flg (readable_regcache *cache)
 {
   gdbarch *arch = cache->arch ();
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   ULONGEST flg;
 
   cache->raw_read (tdep->flg->num, &flg);
@@ -530,7 +530,7 @@ static enum register_status
 m32c_r3r2r1r0_read (struct m32c_reg *reg, readable_regcache *cache, gdb_byte *buf)
 {
   gdbarch *arch = reg->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   int len = TYPE_LENGTH (tdep->r0->type);
   enum register_status status;
 
@@ -567,7 +567,7 @@ m32c_r3r2r1r0_write (struct m32c_reg *reg, struct regcache *cache,
 		     const gdb_byte *buf)
 {
   gdbarch *arch = reg->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   int len = TYPE_LENGTH (tdep->r0->type);
 
   if (gdbarch_byte_order (reg->arch) == BFD_ENDIAN_BIG)
@@ -595,7 +595,7 @@ m32c_pseudo_register_read (struct gdbarch *arch,
 			   int cookednum,
 			   gdb_byte *buf)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   struct m32c_reg *reg;
 
   gdb_assert (0 <= cookednum && cookednum < tdep->num_regs);
@@ -613,7 +613,7 @@ m32c_pseudo_register_write (struct gdbarch *arch,
 			    int cookednum,
 			    const gdb_byte *buf)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   struct m32c_reg *reg;
 
   gdb_assert (0 <= cookednum && cookednum < tdep->num_regs);
@@ -638,7 +638,7 @@ add_reg (struct gdbarch *arch,
 	 struct m32c_reg *ry,
 	 int n)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   struct m32c_reg *r = &tdep->regs[tdep->num_regs];
 
   gdb_assert (tdep->num_regs < M32C_MAX_NUM_REGS);
@@ -678,7 +678,7 @@ set_dwarf_regnum (struct m32c_reg *reg, int num)
 
   /* Update the DWARF->reg mapping.  */
   gdbarch *arch = reg->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   tdep->dwarf_regs[num] = reg;
 }
 
@@ -800,7 +800,7 @@ mark_save_restore (struct m32c_reg *reg)
 static void
 make_regs (struct gdbarch *arch)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   int mach = gdbarch_bfd_arch_info (arch)->mach;
   int num_raw_regs;
   int num_cooked_regs;
@@ -1349,7 +1349,7 @@ m32c_pv_enter (struct m32c_pv_state *state, int size)
     return 1;
 
   gdbarch *arch = state->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   if (m32c_pv_push (state, state->fb, tdep->push_addr_bytes))
     return 1;
 
@@ -1379,7 +1379,7 @@ static int
 m32c_pv_pushm (struct m32c_pv_state *state, int src)
 {
   gdbarch *arch = state->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   /* The bits in SRC indicating which registers to save are:
      r0 r1 r2 r3 a0 a1 sb fb */
@@ -1400,7 +1400,7 @@ static int
 m32c_is_1st_arg_reg (struct m32c_pv_state *state, pv_t value)
 {
   gdbarch *arch = state->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   return (value.kind == pvk_register
 	  && (gdbarch_bfd_arch_info (state->arch)->mach == bfd_mach_m16c
@@ -1415,7 +1415,7 @@ static int
 m32c_is_arg_reg (struct m32c_pv_state *state, pv_t value)
 {
   gdbarch *arch = state->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   return (value.kind == pvk_register
 	  && (gdbarch_bfd_arch_info (state->arch)->mach == bfd_mach_m16c
@@ -1440,7 +1440,7 @@ m32c_is_arg_spill (struct m32c_pv_state *st,
 		   pv_t value)
 {
   gdbarch *arch = st->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   return (m32c_is_arg_reg (st, value)
 	  && loc.kind == srcdest_mem
@@ -1464,7 +1464,7 @@ m32c_is_struct_return (struct m32c_pv_state *st,
 		       pv_t value)
 {
   gdbarch *arch = st->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   return (m32c_is_1st_arg_reg (st, value)
 	  && !st->stack->find_reg (st->arch, value.reg, 0)
@@ -1482,7 +1482,7 @@ static int
 m32c_pushm_is_reg_save (struct m32c_pv_state *st, int src)
 {
   gdbarch *arch = st->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   /* The bits in SRC indicating which registers to save are:
      r0 r1 r2 r3 a0 a1 sb fb */
@@ -1510,7 +1510,7 @@ check_for_saved (void *prologue_untyped, pv_t addr, CORE_ADDR size, pv_t value)
 {
   struct m32c_prologue *prologue = (struct m32c_prologue *) prologue_untyped;
   struct gdbarch *arch = prologue->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   /* Is this the unchanged value of some register being saved on the
      stack?  */
@@ -1550,7 +1550,7 @@ m32c_analyze_prologue (struct gdbarch *arch,
 		       CORE_ADDR start, CORE_ADDR limit,
 		       struct m32c_prologue *prologue)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   unsigned long mach = gdbarch_bfd_arch_info (arch)->mach;
   CORE_ADDR after_last_frame_related_insn;
   struct m32c_pv_state st;
@@ -1881,7 +1881,7 @@ m32c_frame_base (struct frame_info *this_frame,
   struct m32c_prologue *p
     = m32c_analyze_frame_prologue (this_frame, this_prologue_cache);
   gdbarch *arch = get_frame_arch (this_frame);
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   /* In functions that use alloca, the distance between the stack
      pointer and the frame base varies dynamically, so we can't use
@@ -1932,7 +1932,7 @@ m32c_prev_register (struct frame_info *this_frame,
 		    void **this_prologue_cache, int regnum)
 {
   gdbarch *arch = get_frame_arch (this_frame);
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   struct m32c_prologue *p
     = m32c_analyze_frame_prologue (this_frame, this_prologue_cache);
   CORE_ADDR frame_base = m32c_frame_base (this_frame, this_prologue_cache);
@@ -2015,7 +2015,7 @@ m32c_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 		      function_call_return_method return_method,
 		      CORE_ADDR struct_addr)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   unsigned long mach = gdbarch_bfd_arch_info (gdbarch)->mach;
   CORE_ADDR cfa;
@@ -2178,7 +2178,7 @@ m32c_return_value (struct gdbarch *gdbarch,
 		   gdb_byte *readbuf,
 		   const gdb_byte *writebuf)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   enum return_value_convention conv;
   ULONGEST valtype_len = TYPE_LENGTH (valtype);
@@ -2309,7 +2309,7 @@ static CORE_ADDR
 m32c_skip_trampoline_code (struct frame_info *frame, CORE_ADDR stop_pc)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   /* It would be nicer to simply look up the addresses of known
@@ -2555,7 +2555,7 @@ m32c_virtual_frame_pointer (struct gdbarch *gdbarch, CORE_ADDR pc,
   struct m32c_prologue p;
 
   struct regcache *regcache = get_current_regcache ();
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   
   if (!find_pc_partial_function (pc, &name, &func_addr, &func_end))
     internal_error (__FILE__, __LINE__,
diff --git a/gdb/m68hc11-tdep.c b/gdb/m68hc11-tdep.c
index 98f1367423e..9eb18b937be 100644
--- a/gdb/m68hc11-tdep.c
+++ b/gdb/m68hc11-tdep.c
@@ -146,14 +146,14 @@ struct m68gc11_gdbarch_tdep : gdbarch_tdep
 static int
 stack_correction (gdbarch *arch)
 {
-  m68gc11_gdbarch_tdep *tdep = (m68gc11_gdbarch_tdep *) gdbarch_tdep (arch);
+  m68gc11_gdbarch_tdep *tdep = gdbarch_tdep<m68gc11_gdbarch_tdep> (arch);
   return tdep->stack_correction;
 }
 
 static int
 use_page_register (gdbarch *arch)
 {
-  m68gc11_gdbarch_tdep *tdep = (m68gc11_gdbarch_tdep *) gdbarch_tdep (arch);
+  m68gc11_gdbarch_tdep *tdep = gdbarch_tdep<m68gc11_gdbarch_tdep> (arch);
   return tdep->stack_correction;
 }
 
@@ -642,7 +642,7 @@ m68hc11_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
       return pc;
     }
 
-  m68gc11_gdbarch_tdep *tdep = (m68gc11_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68gc11_gdbarch_tdep *tdep = gdbarch_tdep<m68gc11_gdbarch_tdep> (gdbarch);
   seq_table = tdep->prologue;
   
   /* The 68hc11 stack is as follows:
@@ -1020,7 +1020,7 @@ m68hc11_print_register (struct gdbarch *gdbarch, struct ui_file *file,
   else
     {
       m68gc11_gdbarch_tdep *tdep
-	= (m68gc11_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	= gdbarch_tdep<m68gc11_gdbarch_tdep> (gdbarch);
 
       if (regno == HARD_PC_REGNUM && tdep->use_page_register)
 	{
@@ -1125,7 +1125,7 @@ m68hc11_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file,
       gdb_printf (file, " Y=");
       m68hc11_print_register (gdbarch, file, frame, HARD_Y_REGNUM);
   
-      m68gc11_gdbarch_tdep *tdep = (m68gc11_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      m68gc11_gdbarch_tdep *tdep = gdbarch_tdep<m68gc11_gdbarch_tdep> (gdbarch);
 
       if (tdep->use_page_register)
 	{
@@ -1417,7 +1417,7 @@ m68hc11_gdbarch_init (struct gdbarch_info info,
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       m68gc11_gdbarch_tdep *tdep
-	= (m68gc11_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<m68gc11_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->elf_flags != elf_flags)
 	continue;
diff --git a/gdb/m68k-bsd-tdep.c b/gdb/m68k-bsd-tdep.c
index 9ef70f0dda4..2614c223f8e 100644
--- a/gdb/m68k-bsd-tdep.c
+++ b/gdb/m68k-bsd-tdep.c
@@ -133,7 +133,7 @@ m68kbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 static void
 m68kbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   tdep->jb_pc = 5;
   tdep->jb_elt_size = 4;
diff --git a/gdb/m68k-linux-tdep.c b/gdb/m68k-linux-tdep.c
index 85ad4741b1f..28401d3ecc6 100644
--- a/gdb/m68k-linux-tdep.c
+++ b/gdb/m68k-linux-tdep.c
@@ -384,7 +384,7 @@ m68k_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 static void
 m68k_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/m68k-tdep.c b/gdb/m68k-tdep.c
index 568bde66f93..9e59f5904c3 100644
--- a/gdb/m68k-tdep.c
+++ b/gdb/m68k-tdep.c
@@ -70,7 +70,7 @@ typedef BP_MANIPULATION (m68k_break_insn) m68k_breakpoint;
 static struct type *
 m68k_ps_type (struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (!tdep->m68k_ps_type)
     {
@@ -99,7 +99,7 @@ m68k_ps_type (struct gdbarch *gdbarch)
 static struct type *
 m68881_ext_type (struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (!tdep->m68881_ext_type)
     tdep->m68881_ext_type
@@ -120,7 +120,7 @@ m68881_ext_type (struct gdbarch *gdbarch)
 static struct type *
 m68k_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (tdep->fpregs_present)
     {
@@ -171,7 +171,7 @@ static const char * const m68k_register_names[] = {
 static const char *
 m68k_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (regnum < 0 || regnum >= ARRAY_SIZE (m68k_register_names))
     internal_error (__FILE__, __LINE__,
@@ -191,7 +191,7 @@ static int
 m68k_convert_register_p (struct gdbarch *gdbarch,
 			 int regnum, struct type *type)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (!tdep->fpregs_present)
     return 0;
@@ -300,7 +300,7 @@ m68k_extract_return_value (struct type *type, struct regcache *regcache,
   if (type->code () == TYPE_CODE_PTR && len == 4)
     {
       struct gdbarch *gdbarch = regcache->arch ();
-      m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
       regcache->raw_read (tdep->pointer_result_regnum, valbuf);
     }
   else if (len <= 4)
@@ -325,7 +325,7 @@ m68k_svr4_extract_return_value (struct type *type, struct regcache *regcache,
 {
   gdb_byte buf[M68K_MAX_REGISTER_SIZE];
   struct gdbarch *gdbarch = regcache->arch ();
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (tdep->float_return && type->code () == TYPE_CODE_FLT)
     {
@@ -348,7 +348,7 @@ m68k_store_return_value (struct type *type, struct regcache *regcache,
   if (type->code () == TYPE_CODE_PTR && len == 4)
     {
       struct gdbarch *gdbarch = regcache->arch ();
-      m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
       regcache->raw_write (tdep->pointer_result_regnum, valbuf);
       /* gdb historically also set D0 in the SVR4 case.  */
       if (tdep->pointer_result_regnum != M68K_D0_REGNUM)
@@ -371,7 +371,7 @@ m68k_svr4_store_return_value (struct type *type, struct regcache *regcache,
 			      const gdb_byte *valbuf)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (tdep->float_return && type->code () == TYPE_CODE_FLT)
     {
@@ -391,7 +391,7 @@ m68k_svr4_store_return_value (struct type *type, struct regcache *regcache,
 static int
 m68k_reg_struct_return_p (struct gdbarch *gdbarch, struct type *type)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
   enum type_code code = type->code ();
   int len = TYPE_LENGTH (type);
 
@@ -469,7 +469,7 @@ m68k_svr4_return_value (struct gdbarch *gdbarch, struct value *function,
 			gdb_byte *readbuf, const gdb_byte *writebuf)
 {
   enum type_code code = type->code ();
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   /* Aggregates with a single member are always returned like their
      sole element.  */
@@ -541,7 +541,7 @@ m68k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 		      function_call_return_method return_method,
 		      CORE_ADDR struct_addr)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   gdb_byte buf[4];
   int i;
@@ -596,7 +596,7 @@ m68k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 static int
 m68k_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int num)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (num < 8)
     /* d0..7 */
@@ -766,7 +766,7 @@ m68k_analyze_register_saves (struct gdbarch *gdbarch, CORE_ADDR pc,
 			     struct m68k_frame_cache *cache)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (cache->locals >= 0)
     {
@@ -1058,7 +1058,7 @@ m68k_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
   gdb_byte *buf;
   CORE_ADDR sp, jb_addr;
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   if (tdep->jb_pc < 0)
@@ -1104,7 +1104,7 @@ m68k_return_in_first_hidden_param_p (struct gdbarch *gdbarch,
 void
 m68k_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   /* SVR4 uses a different calling convention.  */
   set_gdbarch_return_value (gdbarch, m68k_svr4_return_value);
@@ -1122,7 +1122,7 @@ m68k_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 static void
 m68k_embedded_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   m68k_svr4_init_abi (info, gdbarch);
   tdep->pointer_result_regnum = M68K_D0_REGNUM;
@@ -1237,7 +1237,7 @@ m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
     {
       m68k_gdbarch_tdep *tdep
-	= (m68k_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
+	= gdbarch_tdep<m68k_gdbarch_tdep> (best_arch->gdbarch);
 
       if (flavour != tdep->flavour)
 	continue;
@@ -1339,7 +1339,7 @@ m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 m68k_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (tdep == NULL)
     return;
diff --git a/gdb/mep-tdep.c b/gdb/mep-tdep.c
index 6b3a62391c0..d5ba78c6df9 100644
--- a/gdb/mep-tdep.c
+++ b/gdb/mep-tdep.c
@@ -260,7 +260,7 @@ me_module_register_set (CONFIG_ATTR me_module,
        specifically excluding the generic coprocessor register sets.  */
 
   mep_gdbarch_tdep *tdep
-    = (mep_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+    = gdbarch_tdep<mep_gdbarch_tdep> (target_gdbarch ());
   CGEN_CPU_DESC desc = tdep->cpu_desc;
   const CGEN_HW_ENTRY *hw;
 
@@ -856,7 +856,7 @@ current_me_module (void)
   else
     {
       mep_gdbarch_tdep *tdep
-	= (mep_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+	= gdbarch_tdep<mep_gdbarch_tdep> (target_gdbarch ());
       return tdep->me_module;
     }
 }
@@ -2391,7 +2391,7 @@ mep_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       mep_gdbarch_tdep *tdep
-	= (mep_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<mep_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->me_module == me_module)
 	return arches->gdbarch;
diff --git a/gdb/mips-linux-tdep.c b/gdb/mips-linux-tdep.c
index d8f90ccf881..ca313a28279 100644
--- a/gdb/mips-linux-tdep.c
+++ b/gdb/mips-linux-tdep.c
@@ -1317,7 +1317,7 @@ mips_linux_get_syscall_number (struct gdbarch *gdbarch,
 			       thread_info *thread)
 {
   struct regcache *regcache = get_thread_regcache (thread);
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int regsize = register_size (gdbarch, MIPS_V0_REGNUM);
   /* The content of a register */
@@ -1527,7 +1527,7 @@ static void
 mips_linux_init_abi (struct gdbarch_info info,
 		     struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   enum mips_abi abi = mips_abi (gdbarch);
   struct tdesc_arch_data *tdesc_data = info.tdesc_data;
 
diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index fc1cb46de84..1ea16767e54 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -227,7 +227,7 @@ static const char mips_disassembler_options_n64[] = "gpr-names=64";
 const struct mips_regnum *
 mips_regnum (struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   return tdep->regnum;
 }
 
@@ -252,7 +252,7 @@ mips_float_register_p (struct gdbarch *gdbarch, int regnum)
 static bool
 mips_eabi (gdbarch *arch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (arch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (arch);
   return (tdep->mips_abi == MIPS_ABI_EABI32 \
 	  || tdep->mips_abi == MIPS_ABI_EABI64);
 }
@@ -260,21 +260,21 @@ mips_eabi (gdbarch *arch)
 static int
 mips_last_fp_arg_regnum (gdbarch *arch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (arch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (arch);
   return tdep->mips_last_fp_arg_regnum;
 }
 
 static int
 mips_last_arg_regnum (gdbarch *arch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (arch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (arch);
   return tdep->mips_last_arg_regnum;
 }
 
 static enum mips_fpu_type
 mips_get_fpu_type (gdbarch *arch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (arch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (arch);
   return tdep->mips_fpu_type;
 }
 
@@ -282,14 +282,14 @@ mips_get_fpu_type (gdbarch *arch)
 enum mips_abi
 mips_abi (struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   return tdep->mips_abi;
 }
 
 int
 mips_isa_regsize (struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
   /* If we know how big the registers are, use that size.  */
   if (tdep->register_size_valid_p)
@@ -335,7 +335,7 @@ mips_abi_regsize (struct gdbarch *gdbarch)
 static int
 is_mips16_isa (struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   return tdep->mips_isa == ISA_MIPS16;
 }
 
@@ -344,7 +344,7 @@ is_mips16_isa (struct gdbarch *gdbarch)
 static int
 is_micromips_isa (struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   return tdep->mips_isa == ISA_MICROMIPS;
 }
 
@@ -636,7 +636,7 @@ static const char * const mips_linux_reg_names[NUM_MIPS_PROCESSOR_REGS] = {
 static const char *
 mips_register_name (struct gdbarch *gdbarch, int regno)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   /* GPR names for all ABIs other than n32/n64.  */
   static const char *mips_gpr_names[] = {
     "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
@@ -777,7 +777,7 @@ mips_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
   else if (register_size (gdbarch, rawnum) >
 	   register_size (gdbarch, cookednum))
     {
-      mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
       if (tdep->mips64_transfers_32bit_regs_p)
 	return regcache->raw_read_part (rawnum, 0, 4, buf);
@@ -810,7 +810,7 @@ mips_pseudo_register_write (struct gdbarch *gdbarch,
   else if (register_size (gdbarch, rawnum) >
 	   register_size (gdbarch, cookednum))
     {
-      mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
       if (tdep->mips64_transfers_32bit_regs_p)
 	regcache->raw_write_part (rawnum, 0, 4, buf);
@@ -855,7 +855,7 @@ mips_ax_pseudo_register_push_stack (struct gdbarch *gdbarch,
       if (register_size (gdbarch, rawnum) > register_size (gdbarch, reg))
 	{
 	  mips_gdbarch_tdep *tdep
-	    = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	    = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
 	  if (!tdep->mips64_transfers_32bit_regs_p
 	      || gdbarch_byte_order (gdbarch) != BFD_ENDIAN_BIG)
@@ -1059,7 +1059,7 @@ mips_register_type (struct gdbarch *gdbarch, int regnum)
   else
     {
       int rawnum = regnum - gdbarch_num_regs (gdbarch);
-      mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
       /* The cooked or ABI registers.  These are sized according to
 	 the ABI (with a few complications).  */
@@ -1191,7 +1191,7 @@ show_mask_address (struct ui_file *file, int from_tty,
       else
 	{
 	  mips_gdbarch_tdep *tdep
-	    = (mips_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+	    = gdbarch_tdep<mips_gdbarch_tdep> (target_gdbarch ());
 
 	  if (mips_mask_address_p (tdep))
 	    additional_text = _(" (currently \"on\")");
@@ -1727,7 +1727,7 @@ mips32_next_pc (struct regcache *regcache, CORE_ADDR pc)
 	    case 12:            /* SYSCALL */
 	      {
 		mips_gdbarch_tdep *tdep
-		  = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+		  = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
 		if (tdep->syscall_next_pc != NULL)
 		  pc = tdep->syscall_next_pc (get_current_frame ());
@@ -1938,7 +1938,7 @@ micromips_next_pc (struct regcache *regcache, CORE_ADDR pc)
 		case 0x22d: /* SYSCALL:  000000 1000101101 111100 */
 		  {
 		    mips_gdbarch_tdep *tdep
-		      = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+		      = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
 		    if (tdep->syscall_next_pc != NULL)
 		      pc = tdep->syscall_next_pc (get_current_frame ());
@@ -3901,7 +3901,7 @@ mips_stub_frame_base_sniffer (struct frame_info *this_frame)
 static CORE_ADDR
 mips_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
   if (mips_mask_address_p (tdep) && (((ULONGEST) addr) >> 32 == 0xffffffffUL))
     /* This hack is a work-around for existing boards using PMON, the
@@ -4804,7 +4804,7 @@ mips_eabi_return_value (struct gdbarch *gdbarch, struct value *function,
 			struct type *type, struct regcache *regcache,
 			gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   int fp_return_type = 0;
   int offset, regnum, xfer;
 
@@ -5195,7 +5195,7 @@ mips_n32n64_return_value (struct gdbarch *gdbarch, struct value *function,
 			  struct type *type, struct regcache *regcache,
 			  gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
   /* From MIPSpro N32 ABI Handbook, Document Number: 007-2816-004
 
@@ -5704,7 +5704,7 @@ mips_o32_return_value (struct gdbarch *gdbarch, struct value *function,
 {
   CORE_ADDR func_addr = function ? find_function_addr (function, NULL) : 0;
   int mips16 = mips_pc_is_mips16 (gdbarch, func_addr);
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   enum mips_fval_reg fval_reg;
 
   fval_reg = readbuf ? mips16 ? mips_fval_gpr : mips_fval_fpr : mips_fval_both;
@@ -8101,7 +8101,7 @@ mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   else if (arches != NULL)
     {
       mips_gdbarch_tdep *tdep
-	= (mips_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<mips_gdbarch_tdep> (arches->gdbarch);
       elf_flags = tdep->elf_flags;
     }
   else
@@ -8142,7 +8142,7 @@ mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   if (found_abi == MIPS_ABI_UNKNOWN && info.abfd == NULL && arches != NULL)
     {
       mips_gdbarch_tdep *tdep
-	= (mips_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<mips_gdbarch_tdep> (arches->gdbarch);
       found_abi = tdep->found_abi;
     }
 
@@ -8459,7 +8459,7 @@ mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       mips_gdbarch_tdep *tdep
-        = (mips_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+        = gdbarch_tdep<mips_gdbarch_tdep> (arches->gdbarch);
 
       /* MIPS needs to be pedantic about which ABI and the compressed
 	 ISA variation the object is using.  */
@@ -8917,7 +8917,7 @@ mips_fpu_type_str (enum mips_fpu_type fpu_type)
 static void
 mips_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   if (tdep != NULL)
     {
       int ef_mips_arch;
diff --git a/gdb/mn10300-tdep.c b/gdb/mn10300-tdep.c
index 7a41070bb30..22511d894d4 100644
--- a/gdb/mn10300-tdep.c
+++ b/gdb/mn10300-tdep.c
@@ -1412,7 +1412,7 @@ mn10300_gdbarch_init (struct gdbarch_info info,
 static void
 mn10300_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  mn10300_gdbarch_tdep *tdep = (mn10300_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mn10300_gdbarch_tdep *tdep = gdbarch_tdep<mn10300_gdbarch_tdep> (gdbarch);
   gdb_printf (file, "mn10300_dump_tdep: am33_mode = %d\n",
 	      tdep->am33_mode);
 }
diff --git a/gdb/mn10300-tdep.h b/gdb/mn10300-tdep.h
index 10fef99c5d7..87b861ead90 100644
--- a/gdb/mn10300-tdep.h
+++ b/gdb/mn10300-tdep.h
@@ -84,7 +84,7 @@ struct mn10300_gdbarch_tdep : gdbarch_tdep
 static inline int
 get_am33_mode (gdbarch *arch)
 {
-  mn10300_gdbarch_tdep *tdep = (mn10300_gdbarch_tdep *) gdbarch_tdep (arch);
+  mn10300_gdbarch_tdep *tdep = gdbarch_tdep<mn10300_gdbarch_tdep> (arch);
   return tdep->am33_mode;
 }
 
diff --git a/gdb/msp430-tdep.c b/gdb/msp430-tdep.c
index 28268a95139..4ae8b3d5626 100644
--- a/gdb/msp430-tdep.c
+++ b/gdb/msp430-tdep.c
@@ -341,7 +341,7 @@ msp430_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc,
   int rn;
   pv_t reg[MSP430_NUM_TOTAL_REGS];
   CORE_ADDR after_last_frame_setup_insn = start_pc;
-  msp430_gdbarch_tdep *tdep = (msp430_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  msp430_gdbarch_tdep *tdep = gdbarch_tdep<msp430_gdbarch_tdep> (gdbarch);
   int code_model = tdep->code_model;
   int sz;
 
@@ -570,7 +570,7 @@ msp430_return_value (struct gdbarch *gdbarch,
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   LONGEST valtype_len = TYPE_LENGTH (valtype);
-  msp430_gdbarch_tdep *tdep = (msp430_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  msp430_gdbarch_tdep *tdep = gdbarch_tdep<msp430_gdbarch_tdep> (gdbarch);
   int code_model = tdep->code_model;
 
   if (TYPE_LENGTH (valtype) > 8
@@ -651,7 +651,7 @@ msp430_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   int write_pass;
   int sp_off = 0;
   CORE_ADDR cfa;
-  msp430_gdbarch_tdep *tdep = (msp430_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  msp430_gdbarch_tdep *tdep = gdbarch_tdep<msp430_gdbarch_tdep> (gdbarch);
   int code_model = tdep->code_model;
 
   struct type *func_type = value_type (function);
@@ -814,7 +814,7 @@ msp430_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
 
   stub_name = bms.minsym->linkage_name ();
 
-  msp430_gdbarch_tdep *tdep = (msp430_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  msp430_gdbarch_tdep *tdep = gdbarch_tdep<msp430_gdbarch_tdep> (gdbarch);
   if (tdep->code_model == MSP_SMALL_CODE_MODEL
       && msp430_in_return_stub (gdbarch, pc, stub_name))
     {
@@ -877,7 +877,7 @@ msp430_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 	  if (ca && gdbarch_bfd_arch_info (ca)->arch == bfd_arch_msp430)
 	    {
 	      msp430_gdbarch_tdep *ca_tdep
-		= (msp430_gdbarch_tdep *) gdbarch_tdep (ca);
+		= gdbarch_tdep<msp430_gdbarch_tdep> (ca);
 
 	      elf_flags = ca_tdep->elf_flags;
 	      isa = ca_tdep->isa;
@@ -904,7 +904,7 @@ msp430_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       msp430_gdbarch_tdep *candidate_tdep
-	= (msp430_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<msp430_gdbarch_tdep> (arches->gdbarch);
 
       if (candidate_tdep->elf_flags != elf_flags
 	  || candidate_tdep->isa != isa
diff --git a/gdb/nds32-tdep.c b/gdb/nds32-tdep.c
index e95ad7cc662..11bfd2d1f54 100644
--- a/gdb/nds32-tdep.c
+++ b/gdb/nds32-tdep.c
@@ -289,7 +289,7 @@ typedef BP_MANIPULATION (nds32_break_insn) nds32_breakpoint;
 static int
 nds32_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int num)
 {
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   const int FSR = 38;
   const int FDR = FSR + 32;
 
@@ -432,7 +432,7 @@ nds32_pseudo_register_read (struct gdbarch *gdbarch,
 			    readable_regcache *regcache, int regnum,
 			    gdb_byte *buf)
 {
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   gdb_byte reg_buf[8];
   int offset, fdr_regnum;
   enum register_status status;
@@ -471,7 +471,7 @@ nds32_pseudo_register_write (struct gdbarch *gdbarch,
 			     struct regcache *regcache, int regnum,
 			     const gdb_byte *buf)
 {
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   gdb_byte reg_buf[8];
   int offset, fdr_regnum;
 
@@ -608,7 +608,7 @@ static CORE_ADDR
 nds32_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
 			CORE_ADDR limit_pc, struct nds32_frame_cache *cache)
 {
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   /* Current scanning status.  */
   int in_prologue_bb = 0;
@@ -1169,7 +1169,7 @@ static int
 nds32_analyze_epilogue (struct gdbarch *gdbarch, CORE_ADDR pc,
 			struct nds32_frame_cache *cache)
 {
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   CORE_ADDR limit_pc;
   uint32_t insn, insn_len;
@@ -1220,7 +1220,7 @@ nds32_analyze_epilogue (struct gdbarch *gdbarch, CORE_ADDR pc,
 static int
 nds32_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   int insn_type = INSN_NORMAL;
   int ret_found = 0;
@@ -1424,7 +1424,7 @@ nds32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   int i;
   ULONGEST regval;
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   struct type *func_type = value_type (function);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   int abi_split = nds32_abi_split (tdep->elf_abi);
@@ -1652,7 +1652,7 @@ nds32_extract_return_value (struct gdbarch *gdbarch, struct type *type,
 			    struct regcache *regcache, gdb_byte *valbuf)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   int calling_use_fpr;
   int len;
@@ -1742,7 +1742,7 @@ nds32_store_return_value (struct gdbarch *gdbarch, struct type *type,
 			  struct regcache *regcache, const gdb_byte *valbuf)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   int calling_use_fpr;
   int len;
@@ -1965,7 +1965,7 @@ nds32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
     {
       nds32_gdbarch_tdep *idep
-	= (nds32_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
+	= gdbarch_tdep<nds32_gdbarch_tdep> (best_arch->gdbarch);
 
       if (idep->elf_abi != elf_abi)
 	continue;
diff --git a/gdb/nios2-linux-tdep.c b/gdb/nios2-linux-tdep.c
index a32f79aa28a..da69638b20b 100644
--- a/gdb/nios2-linux-tdep.c
+++ b/gdb/nios2-linux-tdep.c
@@ -217,7 +217,7 @@ nios2_linux_is_kernel_helper (CORE_ADDR pc)
 static void
 nios2_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  nios2_gdbarch_tdep *tdep = (nios2_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nios2_gdbarch_tdep *tdep = gdbarch_tdep<nios2_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/nios2-tdep.c b/gdb/nios2-tdep.c
index 159d31b2d0f..0bad229b44a 100644
--- a/gdb/nios2-tdep.c
+++ b/gdb/nios2-tdep.c
@@ -2098,7 +2098,7 @@ static CORE_ADDR
 nios2_get_next_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  nios2_gdbarch_tdep *tdep = (nios2_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nios2_gdbarch_tdep *tdep = gdbarch_tdep<nios2_gdbarch_tdep> (gdbarch);
   unsigned long mach = gdbarch_bfd_arch_info (gdbarch)->mach;
   unsigned int insn;
   const struct nios2_opcode *op = nios2_fetch_insn (gdbarch, pc, &insn);
@@ -2221,7 +2221,7 @@ static int
 nios2_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  nios2_gdbarch_tdep *tdep = (nios2_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nios2_gdbarch_tdep *tdep = gdbarch_tdep<nios2_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR jb_addr = get_frame_register_unsigned (frame, NIOS2_R4_REGNUM);
   gdb_byte buf[4];
diff --git a/gdb/or1k-tdep.c b/gdb/or1k-tdep.c
index 2b906fa69d3..4699b755d42 100644
--- a/gdb/or1k-tdep.c
+++ b/gdb/or1k-tdep.c
@@ -248,7 +248,7 @@ or1k_return_value (struct gdbarch *gdbarch, struct value *functype,
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   enum type_code rv_type = valtype->code ();
   unsigned int rv_size = TYPE_LENGTH (valtype);
-  or1k_gdbarch_tdep *tdep = (or1k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  or1k_gdbarch_tdep *tdep = gdbarch_tdep<or1k_gdbarch_tdep> (gdbarch);
   int bpw = tdep->bytes_per_word;
 
   /* Deal with struct/union as addresses.  If an array won't fit in a
@@ -353,7 +353,7 @@ or1k_delay_slot_p (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
   const CGEN_INSN *insn;
   CGEN_FIELDS tmp_fields;
-  or1k_gdbarch_tdep *tdep = (or1k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  or1k_gdbarch_tdep *tdep = gdbarch_tdep<or1k_gdbarch_tdep> (gdbarch);
 
   insn = cgen_lookup_insn (tdep->gdb_cgen_cpu_desc,
 			   NULL,
@@ -635,7 +635,7 @@ or1k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   int heap_offset = 0;
   CORE_ADDR heap_sp = sp - 128;
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  or1k_gdbarch_tdep *tdep = (or1k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  or1k_gdbarch_tdep *tdep = gdbarch_tdep<or1k_gdbarch_tdep> (gdbarch);
   int bpa = tdep->bytes_per_address;
   int bpw = tdep->bytes_per_word;
   struct type *func_type = value_type (function);
@@ -1273,7 +1273,7 @@ or1k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 or1k_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  or1k_gdbarch_tdep *tdep = (or1k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  or1k_gdbarch_tdep *tdep = gdbarch_tdep<or1k_gdbarch_tdep> (gdbarch);
 
   if (NULL == tdep)
     return; /* Nothing to report */
diff --git a/gdb/ppc-fbsd-nat.c b/gdb/ppc-fbsd-nat.c
index ce045ac55ab..d0a5778e2d3 100644
--- a/gdb/ppc-fbsd-nat.c
+++ b/gdb/ppc-fbsd-nat.c
@@ -100,7 +100,7 @@ fill_fpregset (const struct regcache *regcache,
 static int
 getfpregs_supplies (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
 	 point registers.  Traditionally, GDB's register set has still
@@ -185,7 +185,7 @@ static int
 ppcfbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i, regnum;
 
   /* The stack pointer shouldn't be zero.  */
diff --git a/gdb/ppc-fbsd-tdep.c b/gdb/ppc-fbsd-tdep.c
index 4afcc3019a4..f5b482921a7 100644
--- a/gdb/ppc-fbsd-tdep.c
+++ b/gdb/ppc-fbsd-tdep.c
@@ -126,7 +126,7 @@ ppcfbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				      void *cb_data,
 				      const struct regcache *regcache)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (tdep->wordsize == 4)
     cb (".reg", 148, 148, &ppc32_fbsd_gregset, NULL, cb_data);
@@ -200,7 +200,7 @@ static struct trad_frame_cache *
 ppcfbsd_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   struct trad_frame_cache *cache;
   CORE_ADDR addr, base, func;
   gdb_byte buf[PPC_INSN_SIZE];
@@ -287,7 +287,7 @@ static CORE_ADDR
 ppcfbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 				  CORE_ADDR lm_addr, CORE_ADDR offset)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   struct regcache *regcache;
   int tp_offset, tp_regnum;
 
@@ -319,7 +319,7 @@ ppcfbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 static void
 ppcfbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support. */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c
index 588dd7df9c0..bdcc0746f58 100644
--- a/gdb/ppc-linux-nat.c
+++ b/gdb/ppc-linux-nat.c
@@ -649,7 +649,7 @@ static int
 ppc_register_u_addr (struct gdbarch *gdbarch, int regno)
 {
   int u_addr = -1;
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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 +802,7 @@ static void
 fetch_spe_register (struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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 +911,7 @@ static void
 fetch_register (struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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;
@@ -1156,7 +1156,7 @@ static void
 fetch_gp_regs (struct regcache *regcache, int tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   if (have_ptrace_getsetregs)
@@ -1208,7 +1208,7 @@ static void
 fetch_fp_regs (struct regcache *regcache, int tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   if (have_ptrace_getsetfpregs)
@@ -1226,7 +1226,7 @@ static void
 fetch_ppc_registers (struct regcache *regcache, int tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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 +1425,7 @@ static void
 store_spe_register (const struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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 +1477,7 @@ static void
 store_register (const struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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;
@@ -1718,7 +1718,7 @@ static void
 store_gp_regs (const struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   if (have_ptrace_getsetregs)
@@ -1780,7 +1780,7 @@ static void
 store_fp_regs (const struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   if (have_ptrace_getsetfpregs)
@@ -1798,7 +1798,7 @@ static void
 store_ppc_registers (const struct regcache *regcache, int tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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)
diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c
index 4c5f8b7a281..5a8ba239343 100644
--- a/gdb/ppc-linux-tdep.c
+++ b/gdb/ppc-linux-tdep.c
@@ -332,7 +332,7 @@ ppc_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
 {
   unsigned int insnbuf[POWERPC32_PLT_CHECK_LEN];
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR target = 0;
   int scan_limit, i;
@@ -898,7 +898,7 @@ ppc_linux_vsxregset (void)
 const struct regset *
 ppc_linux_cgprregset (struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (tdep->wordsize == 4)
     {
@@ -938,7 +938,7 @@ ppc_linux_collect_core_cpgrregset (const struct regset *regset,
 				   int regnum, void *buf, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   const struct regset *cgprregset = ppc_linux_cgprregset (gdbarch);
 
@@ -985,7 +985,7 @@ ppc_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					void *cb_data,
 					const struct regcache *regcache)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int have_altivec = tdep->ppc_vr0_regnum != -1;
   int have_vsx = tdep->ppc_vsr0_upper_regnum != -1;
   int have_ppr = tdep->ppc_ppr_regnum != -1;
@@ -1170,7 +1170,7 @@ ppc_linux_sigtramp_cache (struct frame_info *this_frame,
   CORE_ADDR fpregs;
   int i;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   base = get_frame_register_unsigned (this_frame,
@@ -1341,7 +1341,7 @@ ppc_linux_get_syscall_number (struct gdbarch *gdbarch,
 			      thread_info *thread)
 {
   struct regcache *regcache = get_thread_regcache (thread);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   /* Make sure we're in a 32- or 64-bit machine */
@@ -1417,7 +1417,7 @@ static int
 ppc_linux_syscall_record (struct regcache *regcache)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   ULONGEST scnum;
   enum gdb_syscall syscall_gdb;
   int ret;
@@ -1507,7 +1507,7 @@ ppc_linux_record_signal (struct gdbarch *gdbarch, struct regcache *regcache,
   const int SIGNAL_FRAMESIZE = 128;
   const int sizeof_rt_sigframe = 1440 * 2 + 8 * 2 + 4 * 6 + 8 + 8 + 128 + 512;
   ULONGEST sp;
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   for (i = 3; i <= 12; i++)
@@ -2036,7 +2036,7 @@ static void
 ppc_linux_init_abi (struct gdbarch_info info,
 		    struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   struct tdesc_arch_data *tdesc_data = info.tdesc_data;
   static const char *const stap_integer_prefixes[] = { "i", NULL };
   static const char *const stap_register_indirection_prefixes[] = { "(",
diff --git a/gdb/ppc-netbsd-nat.c b/gdb/ppc-netbsd-nat.c
index fb2dce501a4..91f18fbb83f 100644
--- a/gdb/ppc-netbsd-nat.c
+++ b/gdb/ppc-netbsd-nat.c
@@ -52,7 +52,7 @@ static ppc_nbsd_nat_target the_ppc_nbsd_nat_target;
 static int
 getregs_supplies (struct gdbarch *gdbarch, int regnum)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   return ((regnum >= tdep->ppc_gp0_regnum
 	   && regnum < tdep->ppc_gp0_regnum + ppc_num_gprs)
@@ -68,7 +68,7 @@ getregs_supplies (struct gdbarch *gdbarch, int regnum)
 static int
 getfpregs_supplies (struct gdbarch *gdbarch, int regnum)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
      point registers.  Traditionally, GDB's register set has still
@@ -159,7 +159,7 @@ ppcnbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
   struct switchframe sf;
   struct callframe cf;
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   /* The stack pointer shouldn't be zero.  */
diff --git a/gdb/ppc-netbsd-tdep.c b/gdb/ppc-netbsd-tdep.c
index cb3d8d5e5df..d8dc494979a 100644
--- a/gdb/ppc-netbsd-tdep.c
+++ b/gdb/ppc-netbsd-tdep.c
@@ -102,7 +102,7 @@ ppcnbsd_sigtramp_cache_init (const struct tramp_frame *self,
 			     CORE_ADDR func)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   CORE_ADDR addr, base;
   int i;
 
diff --git a/gdb/ppc-obsd-nat.c b/gdb/ppc-obsd-nat.c
index 93e1024b589..e480f19dc73 100644
--- a/gdb/ppc-obsd-nat.c
+++ b/gdb/ppc-obsd-nat.c
@@ -54,7 +54,7 @@ static ppc_obsd_nat_target the_ppc_obsd_nat_target;
 static int
 getfpregs_supplies (struct gdbarch *gdbarch, int regnum)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
      point registers.  Traditionally, GDB's register set has still
@@ -154,7 +154,7 @@ static int
 ppcobsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   struct switchframe sf;
   struct callframe cf;
   int i, regnum;
diff --git a/gdb/ppc-obsd-tdep.c b/gdb/ppc-obsd-tdep.c
index a2924e35bbc..90fb5e3a399 100644
--- a/gdb/ppc-obsd-tdep.c
+++ b/gdb/ppc-obsd-tdep.c
@@ -161,7 +161,7 @@ static struct trad_frame_cache *
 ppcobsd_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct trad_frame_cache *cache;
   CORE_ADDR addr, base, func;
diff --git a/gdb/ppc-sysv-tdep.c b/gdb/ppc-sysv-tdep.c
index 6c2fd1bfc99..ed6c2d4449d 100644
--- a/gdb/ppc-sysv-tdep.c
+++ b/gdb/ppc-sysv-tdep.c
@@ -65,7 +65,7 @@ ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 			      function_call_return_method return_method,
 			      CORE_ADDR struct_addr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int opencl_abi = ppc_sysv_use_opencl_abi (value_type (function));
   ULONGEST saved_sp;
@@ -597,7 +597,7 @@ get_decimal_float_return_value (struct gdbarch *gdbarch, struct type *valtype,
 				struct regcache *regcache, gdb_byte *readbuf,
 				const gdb_byte *writebuf)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   gdb_assert (valtype->code () == TYPE_CODE_DECFLOAT);
 
@@ -675,7 +675,7 @@ do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *func_type,
 			  gdb_byte *readbuf, const gdb_byte *writebuf,
 			  int broken_gcc)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int opencl_abi = func_type? ppc_sysv_use_opencl_abi (func_type) : 0;
 
@@ -1250,7 +1250,7 @@ ppc64_sysv_abi_push_val (struct gdbarch *gdbarch,
 			 const bfd_byte *val, int len, int align,
 			 struct ppc64_sysv_argpos *argpos)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int offset = 0;
 
   /* Enforce alignment of stack location, if requested.  */
@@ -1300,7 +1300,7 @@ static void
 ppc64_sysv_abi_push_integer (struct gdbarch *gdbarch, ULONGEST val,
 			     struct ppc64_sysv_argpos *argpos)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   gdb_byte buf[PPC_MAX_REGISTER_SIZE];
 
@@ -1318,7 +1318,7 @@ ppc64_sysv_abi_push_freg (struct gdbarch *gdbarch,
 			  struct type *type, const bfd_byte *val,
 			  struct ppc64_sysv_argpos *argpos)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   if (tdep->soft_float)
     return;
 
@@ -1403,7 +1403,7 @@ static void
 ppc64_sysv_abi_push_vreg (struct gdbarch *gdbarch, const bfd_byte *val,
 			  struct ppc64_sysv_argpos *argpos)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (argpos->regcache && argpos->vreg <= 13)
     argpos->regcache->cooked_write (tdep->ppc_vr0_regnum + argpos->vreg, val);
@@ -1419,7 +1419,7 @@ ppc64_sysv_abi_push_param (struct gdbarch *gdbarch,
 			   struct type *type, const bfd_byte *val,
 			   struct ppc64_sysv_argpos *argpos)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (type->code () == TYPE_CODE_FLT
       || type->code () == TYPE_CODE_DECFLOAT)
@@ -1545,7 +1545,7 @@ ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch,
 				CORE_ADDR struct_addr)
 {
   CORE_ADDR func_addr = find_function_addr (function, NULL);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int opencl_abi = ppc_sysv_use_opencl_abi (value_type (function));
   ULONGEST back_chain;
@@ -1739,7 +1739,7 @@ ppc64_sysv_abi_return_value_base (struct gdbarch *gdbarch, struct type *valtype,
 				  struct regcache *regcache, gdb_byte *readbuf,
 				  const gdb_byte *writebuf, int index)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* Integers live in GPRs starting at r3.  */
   if ((valtype->code () == TYPE_CODE_INT
@@ -1922,7 +1922,7 @@ ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct value *function,
 			     struct type *valtype, struct regcache *regcache,
 			     gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   struct type *func_type = function ? value_type (function) : NULL;
   int opencl_abi = func_type? ppc_sysv_use_opencl_abi (func_type) : 0;
   struct type *eltype;
diff --git a/gdb/ppc64-tdep.c b/gdb/ppc64-tdep.c
index 32931f72691..0437ca7e3f3 100644
--- a/gdb/ppc64-tdep.c
+++ b/gdb/ppc64-tdep.c
@@ -89,7 +89,7 @@ ppc64_plt_entry_point (struct frame_info *frame, CORE_ADDR plt_off)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   CORE_ADDR tocp;
 
   if (execution_direction == EXEC_REVERSE)
diff --git a/gdb/riscv-linux-tdep.c b/gdb/riscv-linux-tdep.c
index 387b8bdbc2f..5bda2e5c824 100644
--- a/gdb/riscv-linux-tdep.c
+++ b/gdb/riscv-linux-tdep.c
@@ -179,7 +179,7 @@ riscv_linux_syscall_next_pc (struct frame_info *frame)
 static void
 riscv_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
index 69f2123dcdb..2d41be96b20 100644
--- a/gdb/riscv-tdep.c
+++ b/gdb/riscv-tdep.c
@@ -733,7 +733,7 @@ show_riscv_debug_variable (struct ui_file *file, int from_tty,
 int
 riscv_isa_xlen (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   return tdep->isa_features.xlen;
 }
 
@@ -742,7 +742,7 @@ riscv_isa_xlen (struct gdbarch *gdbarch)
 int
 riscv_abi_xlen (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   return tdep->abi_features.xlen;
 }
 
@@ -751,7 +751,7 @@ riscv_abi_xlen (struct gdbarch *gdbarch)
 int
 riscv_isa_flen (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   return tdep->isa_features.flen;
 }
 
@@ -760,7 +760,7 @@ riscv_isa_flen (struct gdbarch *gdbarch)
 int
 riscv_abi_flen (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   return tdep->abi_features.flen;
 }
 
@@ -769,7 +769,7 @@ riscv_abi_flen (struct gdbarch *gdbarch)
 bool
 riscv_abi_embedded (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   return tdep->abi_features.embedded;
 }
 
@@ -786,7 +786,7 @@ riscv_has_fp_regs (struct gdbarch *gdbarch)
 static bool
 riscv_has_fp_abi (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   return tdep->abi_features.flen > 0;
 }
 
@@ -910,7 +910,7 @@ riscv_register_name (struct gdbarch *gdbarch, int regnum)
      will show up in 'info register all'.  Unless, we identify the
      duplicate copies of these registers (in riscv_tdesc_unknown_reg) and
      then hide the registers here by giving them no name.  */
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   if (tdep->duplicate_fflags_regnum == regnum)
     return NULL;
   if (tdep->duplicate_frm_regnum == regnum)
@@ -938,7 +938,7 @@ riscv_register_name (struct gdbarch *gdbarch, int regnum)
 static struct type *
 riscv_fpreg_d_type (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
 
   if (tdep->riscv_fpreg_d_type == nullptr)
     {
@@ -1260,7 +1260,7 @@ riscv_is_regnum_a_named_csr (int regnum)
 static bool
 riscv_is_unknown_csr (struct gdbarch *gdbarch, int regnum)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   return (regnum >= tdep->unknown_csrs_first_regnum
 	  && regnum < (tdep->unknown_csrs_first_regnum
 		       + tdep->unknown_csrs_count));
@@ -3600,7 +3600,7 @@ riscv_tdesc_unknown_reg (struct gdbarch *gdbarch, tdesc_feature *feature,
      record their register numbers here.  */
   if (strcmp (tdesc_feature_name (feature), riscv_freg_feature.name ()) == 0)
     {
-      riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
       int *regnum_ptr = nullptr;
 
       if (strcmp (reg_name, "fflags") == 0)
@@ -3631,7 +3631,7 @@ riscv_tdesc_unknown_reg (struct gdbarch *gdbarch, tdesc_feature *feature,
      about register groups in riscv_register_reggroup_p.  */
   if (strcmp (tdesc_feature_name (feature), riscv_csr_feature.name ()) == 0)
     {
-      riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
       if (tdep->unknown_csrs_first_regnum == -1)
 	tdep->unknown_csrs_first_regnum = possible_regnum;
       gdb_assert (tdep->unknown_csrs_first_regnum
@@ -3733,7 +3733,7 @@ riscv_gdbarch_init (struct gdbarch_info info,
 	 we are looking for.  If it doesn't then we can't reuse this
 	 gdbarch.  */
       riscv_gdbarch_tdep *other_tdep
-	= (riscv_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<riscv_gdbarch_tdep> (arches->gdbarch);
 
       if (other_tdep->isa_features != features
 	  || other_tdep->abi_features != abi_features)
@@ -3858,7 +3858,7 @@ riscv_next_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   struct gdbarch *gdbarch = regcache->arch ();
   const riscv_gdbarch_tdep *tdep
-    = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+    = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   struct riscv_insn insn;
   CORE_ADDR next_pc;
 
diff --git a/gdb/rl78-tdep.c b/gdb/rl78-tdep.c
index 6ea0473081d..2462e7a191d 100644
--- a/gdb/rl78-tdep.c
+++ b/gdb/rl78-tdep.c
@@ -267,7 +267,7 @@ struct rl78_prologue
 static struct type *
 rl78_psw_type (struct gdbarch *gdbarch)
 {
-  rl78_gdbarch_tdep *tdep = (rl78_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  rl78_gdbarch_tdep *tdep = gdbarch_tdep<rl78_gdbarch_tdep> (gdbarch);
 
   if (tdep->rl78_psw_type == NULL)
     {
@@ -291,7 +291,7 @@ rl78_psw_type (struct gdbarch *gdbarch)
 static struct type *
 rl78_register_type (struct gdbarch *gdbarch, int reg_nr)
 {
-  rl78_gdbarch_tdep *tdep = (rl78_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  rl78_gdbarch_tdep *tdep = gdbarch_tdep<rl78_gdbarch_tdep> (gdbarch);
 
   if (reg_nr == RL78_PC_REGNUM)
     return tdep->rl78_code_pointer;
@@ -1248,7 +1248,7 @@ rl78_return_value (struct gdbarch *gdbarch,
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   ULONGEST valtype_len = TYPE_LENGTH (valtype);
-  rl78_gdbarch_tdep *tdep = (rl78_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  rl78_gdbarch_tdep *tdep = gdbarch_tdep<rl78_gdbarch_tdep> (gdbarch);
   int is_g10 = tdep->elf_flags & E_FLAG_RL78_G10;
 
   if (valtype_len > 8)
@@ -1394,7 +1394,7 @@ rl78_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       rl78_gdbarch_tdep *tdep
-	= (rl78_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<rl78_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->elf_flags != elf_flags)
 	continue;
diff --git a/gdb/rs6000-aix-nat.c b/gdb/rs6000-aix-nat.c
index 8563aea313a..8697d27b4ed 100644
--- a/gdb/rs6000-aix-nat.c
+++ b/gdb/rs6000-aix-nat.c
@@ -115,7 +115,7 @@ static rs6000_nat_target the_rs6000_nat_target;
 static int
 regmap (struct gdbarch *gdbarch, int regno, int *isfloat)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   *isfloat = 0;
   if (tdep->ppc_gp0_regnum <= regno
@@ -317,7 +317,7 @@ rs6000_nat_target::fetch_registers (struct regcache *regcache, int regno)
 
   else
     {
-      ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
       /* Read 32 general purpose registers.  */
       for (regno = tdep->ppc_gp0_regnum;
@@ -359,7 +359,7 @@ rs6000_nat_target::store_registers (struct regcache *regcache, int regno)
 
   else
     {
-      ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
       /* Write general purpose registers first.  */
       for (regno = tdep->ppc_gp0_regnum;
diff --git a/gdb/rs6000-aix-tdep.c b/gdb/rs6000-aix-tdep.c
index ead03bf8819..c15a10c19b4 100644
--- a/gdb/rs6000-aix-tdep.c
+++ b/gdb/rs6000-aix-tdep.c
@@ -75,7 +75,7 @@ aix_sighandle_frame_cache (struct frame_info *this_frame,
   LONGEST backchain;
   CORE_ADDR base, base_orig, func;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct trad_frame_cache *this_trad_cache;
 
@@ -261,7 +261,7 @@ rs6000_aix_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					 void *cb_data,
 					 const struct regcache *regcache)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   if (tdep->wordsize == 4)
     cb (".reg", 592, 592, &rs6000_aix32_regset, NULL, cb_data);
   else
@@ -292,7 +292,7 @@ rs6000_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 			function_call_return_method return_method,
 			CORE_ADDR struct_addr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int ii;
   int len = 0;
@@ -522,7 +522,7 @@ rs6000_return_value (struct gdbarch *gdbarch, struct value *function,
 		     struct type *valtype, struct regcache *regcache,
 		     gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   /* The calling convention this function implements assumes the
@@ -660,7 +660,7 @@ rs6000_convert_from_func_ptr_addr (struct gdbarch *gdbarch,
 				   CORE_ADDR addr,
 				   struct target_ops *targ)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct obj_section *s;
 
@@ -704,7 +704,7 @@ branch_dest (struct regcache *regcache, int opcode, int instr,
 	     CORE_ADDR pc, CORE_ADDR safety)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR dest;
   int immediate;
@@ -972,7 +972,7 @@ static struct ld_info
 rs6000_aix_extract_ld_info (struct gdbarch *gdbarch,
 			    const gdb_byte *ldi_buf)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
   const struct ld_info_desc desc
@@ -1131,7 +1131,7 @@ rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch,
 static void
 rs6000_aix_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* RS6000/AIX does not support PT_STEP.  Has to be simulated.  */
   set_gdbarch_software_single_step (gdbarch, rs6000_software_single_step);
diff --git a/gdb/rs6000-lynx178-tdep.c b/gdb/rs6000-lynx178-tdep.c
index 844d0a4ede2..dc13dd3fa73 100644
--- a/gdb/rs6000-lynx178-tdep.c
+++ b/gdb/rs6000-lynx178-tdep.c
@@ -36,7 +36,7 @@ rs6000_lynx178_push_dummy_call (struct gdbarch *gdbarch,
 				function_call_return_method return_method,
 				CORE_ADDR struct_addr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int ii;
   int len = 0;
@@ -265,7 +265,7 @@ rs6000_lynx178_return_value (struct gdbarch *gdbarch, struct value *function,
 			     struct type *valtype, struct regcache *regcache,
 			     gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   /* The calling convention this function implements assumes the
diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
index 6815dfaa820..640459f1c28 100644
--- a/gdb/rs6000-tdep.c
+++ b/gdb/rs6000-tdep.c
@@ -201,7 +201,7 @@ struct rs6000_framedata
 int
 vsx_register_p (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   if (tdep->ppc_vsr0_regnum < 0)
     return 0;
   else
@@ -213,7 +213,7 @@ vsx_register_p (struct gdbarch *gdbarch, int regno)
 int
 altivec_register_p (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   if (tdep->ppc_vr0_regnum < 0 || tdep->ppc_vrsave_regnum < 0)
     return 0;
   else
@@ -225,7 +225,7 @@ altivec_register_p (struct gdbarch *gdbarch, int regno)
 int
 spe_register_p (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   
   /* Is it a reference to EV0 -- EV31, and do we have those?  */
   if (IS_SPE_PSEUDOREG (tdep, regno))
@@ -257,7 +257,7 @@ spe_register_p (struct gdbarch *gdbarch, int regno)
 int
 ppc_floating_point_unit_p (struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   return (tdep->ppc_fp0_regnum >= 0
 	  && tdep->ppc_fpscr_regnum >= 0);
@@ -268,7 +268,7 @@ ppc_floating_point_unit_p (struct gdbarch *gdbarch)
 int
 ppc_altivec_support_p (struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   return (tdep->ppc_vr0_regnum >= 0
 	  && tdep->ppc_vrsave_regnum >= 0);
@@ -297,7 +297,7 @@ set_sim_regno (int *table, int gdb_regno, int sim_regno)
 static void
 init_sim_regno_table (struct gdbarch *arch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (arch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (arch);
   int total_regs = gdbarch_num_regs (arch);
   int *sim_regno = GDBARCH_OBSTACK_CALLOC (arch, total_regs, int);
   int i;
@@ -391,7 +391,7 @@ init_sim_regno_table (struct gdbarch *arch)
 static int
 rs6000_register_sim_regno (struct gdbarch *gdbarch, int reg)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int sim_regno;
 
   if (tdep->sim_regno == NULL)
@@ -522,7 +522,7 @@ ppc_supply_gregset (const struct regset *regset, struct regcache *regcache,
 		    int regnum, const void *gregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   const struct ppc_reg_offsets *offsets
     = (const struct ppc_reg_offsets *) regset->regmap;
   size_t offset;
@@ -578,7 +578,7 @@ ppc_supply_fpregset (const struct regset *regset, struct regcache *regcache,
   if (!ppc_floating_point_unit_p (gdbarch))
     return;
 
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   offsets = (const struct ppc_reg_offsets *) regset->regmap;
   if (regnum == -1)
     {
@@ -611,7 +611,7 @@ ppc_collect_gregset (const struct regset *regset,
 		     int regnum, void *gregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   const struct ppc_reg_offsets *offsets
     = (const struct ppc_reg_offsets *) regset->regmap;
   size_t offset;
@@ -668,7 +668,7 @@ ppc_collect_fpregset (const struct regset *regset,
   if (!ppc_floating_point_unit_p (gdbarch))
     return;
 
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   offsets = (const struct ppc_reg_offsets *) regset->regmap;
   if (regnum == -1)
     {
@@ -746,7 +746,7 @@ static int
 rs6000_in_function_epilogue_frame_p (struct frame_info *curfrm,
 				     struct gdbarch *gdbarch, CORE_ADDR pc)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   bfd_byte insn_buf[PPC_INSN_SIZE];
   CORE_ADDR scan_pc, func_start, func_end, epilogue_start, epilogue_end;
@@ -1042,7 +1042,7 @@ ppc_displaced_step_fixup (struct gdbarch *gdbarch,
       if (insn & 0x1)
 	{
 	  /* Link register needs to be set to the next instruction's PC.  */
-	  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 	  regcache_cooked_write_unsigned (regs,
 					  tdep->ppc_lr_regnum,
 					  from + PPC_INSN_SIZE);
@@ -1590,7 +1590,7 @@ skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc, CORE_ADDR lim_pc,
   int num_skip_non_prologue_insns = 0;
   int r0_contains_arg = 0;
   const struct bfd_arch_info *arch_info = gdbarch_bfd_arch_info (gdbarch);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   memset (fdata, 0, sizeof (struct rs6000_framedata));
@@ -2310,7 +2310,7 @@ static CORE_ADDR
 rs6000_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   unsigned int ii, op;
   int rel;
@@ -2368,7 +2368,7 @@ rs6000_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
 static struct type *
 rs6000_builtin_type_vec64 (struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->ppc_builtin_type_vec64)
     {
@@ -2413,7 +2413,7 @@ rs6000_builtin_type_vec64 (struct gdbarch *gdbarch)
 static struct type *
 rs6000_builtin_type_vec128 (struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->ppc_builtin_type_vec128)
     {
@@ -2467,7 +2467,7 @@ rs6000_builtin_type_vec128 (struct gdbarch *gdbarch)
 static const char *
 rs6000_register_name (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* The upper half "registers" have names in the XML description,
      but we present only the low GPRs and the full 64-bit registers
@@ -2605,7 +2605,7 @@ rs6000_register_name (struct gdbarch *gdbarch, int regno)
 static struct type *
 rs6000_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* These are the e500 pseudo-registers.  */
   if (IS_SPE_PSEUDOREG (tdep, regnum))
@@ -2644,7 +2644,7 @@ static int
 rs6000_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 				   const struct reggroup *group)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (IS_V_ALIAS_PSEUDOREG (tdep, regnum))
     return 0;
@@ -2659,7 +2659,7 @@ static int
 rs6000_convert_register_p (struct gdbarch *gdbarch, int regnum,
 			   struct type *type)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   return (tdep->ppc_fp0_regnum >= 0
 	  && regnum >= tdep->ppc_fp0_regnum
@@ -2744,7 +2744,7 @@ e500_move_ev_register (move_ev_register_func move,
 		       struct regcache *regcache, int ev_reg, void *buffer)
 {
   struct gdbarch *arch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (arch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (arch);
   int reg_index;
   gdb_byte *byte_buffer = (gdb_byte *) buffer;
   enum register_status status;
@@ -2785,7 +2785,7 @@ e500_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int ev_reg, gdb_byte *buffer)
 {
   struct gdbarch *arch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index;
   enum register_status status;
 
@@ -2826,7 +2826,7 @@ static enum register_status
 dfp_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int reg_nr, gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, fp0;
   enum register_status status;
 
@@ -2866,7 +2866,7 @@ static void
 dfp_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
 			    int reg_nr, const gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, fp0;
 
   if (IS_DFP_PSEUDOREG (tdep, reg_nr))
@@ -2903,7 +2903,7 @@ v_alias_pseudo_register_read (struct gdbarch *gdbarch,
 			      readable_regcache *regcache, int reg_nr,
 			      gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   gdb_assert (IS_V_ALIAS_PSEUDOREG (tdep, reg_nr));
 
   return regcache->raw_read (tdep->ppc_vr0_regnum
@@ -2918,7 +2918,7 @@ v_alias_pseudo_register_write (struct gdbarch *gdbarch,
 			       struct regcache *regcache,
 			       int reg_nr, const gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   gdb_assert (IS_V_ALIAS_PSEUDOREG (tdep, reg_nr));
 
   regcache->raw_write (tdep->ppc_vr0_regnum
@@ -2930,7 +2930,7 @@ static enum register_status
 vsx_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int reg_nr, gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0, fp0, vsr0_upper;
   enum register_status status;
 
@@ -2978,7 +2978,7 @@ static void
 vsx_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
 			    int reg_nr, const gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0, fp0, vsr0_upper;
 
   if (IS_VSX_PSEUDOREG (tdep, reg_nr))
@@ -3020,7 +3020,7 @@ static enum register_status
 efp_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int reg_nr, gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0;
 
   if (IS_EFP_PSEUDOREG (tdep, reg_nr))
@@ -3049,7 +3049,7 @@ static void
 efp_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
 			    int reg_nr, const gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0;
   int offset = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG ? 0 : 8;
 
@@ -3085,7 +3085,7 @@ rs6000_pseudo_register_read (struct gdbarch *gdbarch,
 			     int reg_nr, gdb_byte *buffer)
 {
   struct gdbarch *regcache_arch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   gdb_assert (regcache_arch == gdbarch);
 
@@ -3116,7 +3116,7 @@ rs6000_pseudo_register_write (struct gdbarch *gdbarch,
 			      int reg_nr, const gdb_byte *buffer)
 {
   struct gdbarch *regcache_arch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   gdb_assert (regcache_arch == gdbarch);
 
@@ -3147,7 +3147,7 @@ static void
 dfp_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				struct agent_expr *ax, int reg_nr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, fp0;
 
   if (IS_DFP_PSEUDOREG (tdep, reg_nr))
@@ -3174,7 +3174,7 @@ static void
 v_alias_pseudo_register_collect (struct gdbarch *gdbarch,
 				 struct agent_expr *ax, int reg_nr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   gdb_assert (IS_V_ALIAS_PSEUDOREG (tdep, reg_nr));
 
   ax_reg_mask (ax, tdep->ppc_vr0_regnum
@@ -3188,7 +3188,7 @@ static void
 vsx_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				struct agent_expr *ax, int reg_nr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0, fp0, vsr0_upper;
 
   if (IS_VSX_PSEUDOREG (tdep, reg_nr))
@@ -3226,7 +3226,7 @@ static void
 efp_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				struct agent_expr *ax, int reg_nr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0;
 
   if (IS_EFP_PSEUDOREG (tdep, reg_nr))
@@ -3249,7 +3249,7 @@ static int
 rs6000_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				   struct agent_expr *ax, int reg_nr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   if (IS_SPE_PSEUDOREG (tdep, reg_nr))
     {
       int reg_index = reg_nr - tdep->ppc_ev0_regnum;
@@ -3289,7 +3289,7 @@ rs6000_gen_return_address (struct gdbarch *gdbarch,
 			   struct agent_expr *ax, struct axs_value *value,
 			   CORE_ADDR scope)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   value->type = register_type (gdbarch, tdep->ppc_lr_regnum);
   value->kind = axs_lvalue_register;
   value->u.reg = tdep->ppc_lr_regnum;
@@ -3300,7 +3300,7 @@ rs6000_gen_return_address (struct gdbarch *gdbarch,
 static int
 rs6000_stab_reg_to_regnum (struct gdbarch *gdbarch, int num)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (0 <= num && num <= 31)
     return tdep->ppc_gp0_regnum + num;
@@ -3342,7 +3342,7 @@ rs6000_stab_reg_to_regnum (struct gdbarch *gdbarch, int num)
 static int
 rs6000_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int num)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (0 <= num && num <= 31)
     return tdep->ppc_gp0_regnum + num;
@@ -3561,7 +3561,7 @@ rs6000_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct rs6000_frame_cache *cache;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct rs6000_framedata fdata;
   int wordsize = tdep->wordsize;
@@ -3797,7 +3797,7 @@ rs6000_epilogue_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct rs6000_frame_cache *cache;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (*this_cache)
     return (struct rs6000_frame_cache *) *this_cache;
@@ -3918,7 +3918,7 @@ ppc_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
 			    struct dwarf2_frame_state_reg *reg,
 			    struct frame_info *this_frame)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* PPC32 and PPC64 ABI's are the same regarding volatile and
      non-volatile registers.  We will use the same code for both.  */
@@ -4229,7 +4229,7 @@ static int
 ppc_process_record_op4 (struct gdbarch *gdbarch, struct regcache *regcache,
 			CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_FIELD (insn, 21, 11);
   int vra = PPC_FIELD (insn, 11, 5);
 
@@ -4771,7 +4771,7 @@ static int
 ppc_process_record_op6 (struct gdbarch *gdbarch, struct regcache *regcache,
 			CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int subtype = PPC_FIELD (insn, 28, 4);
   CORE_ADDR ea = 0;
 
@@ -4799,7 +4799,7 @@ static int
 ppc_process_record_op19 (struct gdbarch *gdbarch, struct regcache *regcache,
 			   CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_EXTOP (insn);
 
   switch (ext & 0x01f)
@@ -4855,7 +4855,7 @@ ppc_process_record_op31_177 (struct gdbarch *gdbarch,
 {
   int RA_opcode = PPC_RA(insn);
   int as = PPC_FIELD (insn, 6, 3);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   switch (RA_opcode)
     {
@@ -4875,7 +4875,7 @@ static int
 ppc_process_record_op31 (struct gdbarch *gdbarch, struct regcache *regcache,
 			   CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_EXTOP (insn);
   int tmp, nr, nb = 0, i;
   CORE_ADDR at_dcsz, ea = 0;
@@ -5536,7 +5536,7 @@ static int
 ppc_process_record_op59 (struct gdbarch *gdbarch, struct regcache *regcache,
 			 CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_EXTOP (insn);
   int at = PPC_FIELD (insn, 6, 3);
 
@@ -5701,7 +5701,7 @@ ppc_process_record_op60_XX2 (struct gdbarch *gdbarch,
 			     struct regcache *regcache,
 			     CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int RA_opcode = PPC_RA(insn);
 
   switch (RA_opcode)
@@ -5742,7 +5742,7 @@ static int
 ppc_process_record_op60 (struct gdbarch *gdbarch, struct regcache *regcache,
 			   CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_EXTOP (insn);
 
   switch (ext >> 2)
@@ -6097,7 +6097,7 @@ static int
 ppc_process_record_op61 (struct gdbarch *gdbarch, struct regcache *regcache,
 			   CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   ULONGEST ea = 0;
   int size;
 
@@ -6156,7 +6156,7 @@ static int
 ppc_process_record_op63 (struct gdbarch *gdbarch, struct regcache *regcache,
 			   CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_EXTOP (insn);
   int tmp;
 
@@ -6453,7 +6453,7 @@ ppc_process_record_prefix_op42 (struct gdbarch *gdbarch,
 				struct regcache *regcache,
 				uint32_t insn_prefix, uint32_t insn_suffix)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST1 = PPC_FIELD (insn_prefix, 8, 1);
 
@@ -6489,7 +6489,7 @@ ppc_process_record_prefix_op59_XX3 (struct gdbarch *gdbarch,
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST4 = PPC_FIELD (insn_prefix, 8, 4);
   int at = PPC_FIELD (insn_suffix, 6, 3);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (type == 3)
     {
@@ -6603,7 +6603,7 @@ ppc_process_record_prefix_store (struct gdbarch *gdbarch,
 				 CORE_ADDR addr, uint32_t insn_prefix,
 				 uint32_t insn_suffix)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   ULONGEST iaddr = 0;
   int size;
   int R = PPC_BIT (insn_prefix, 11);
@@ -6659,7 +6659,7 @@ ppc_process_record_prefix_op32 (struct gdbarch *gdbarch,
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST1 = PPC_FIELD (insn_prefix, 8, 1);
   int ST4 = PPC_FIELD (insn_prefix, 8, 4);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (type == 1)
     {
@@ -6713,7 +6713,7 @@ ppc_process_record_prefix_op33 (struct gdbarch *gdbarch,
 {
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST4 = PPC_FIELD (insn_prefix, 8, 4);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (type == 1)
     {
@@ -6751,7 +6751,7 @@ ppc_process_record_prefix_op34 (struct gdbarch *gdbarch,
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST1 = PPC_FIELD (insn_prefix, 8, 1);
   int ST4 = PPC_FIELD (insn_prefix, 8, 4);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (type == 1)
     {
@@ -6797,7 +6797,7 @@ ppc_process_record_prefix_store_vsx_ds_form (struct gdbarch *gdbarch,
 					     uint32_t insn_prefix,
 					     uint32_t insn_suffix)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   ULONGEST ea = 0;
   int size;
   int R = PPC_BIT (insn_prefix, 11);
@@ -6850,7 +6850,7 @@ ppc_process_record_prefix_vsx_d_form (struct gdbarch *gdbarch,
 				      uint32_t insn_prefix,
 				      uint32_t insn_suffix)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   ULONGEST ea = 0;
   int size;
   int R = PPC_BIT (insn_prefix, 11);
@@ -6907,7 +6907,7 @@ ppc_process_prefix_instruction (int insn_prefix, int insn_suffix,
 {
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST1 = PPC_FIELD (insn_prefix, 8, 1);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int op6;
 
   /* D-form has uses a 5-bit opcode in the instruction suffix */
@@ -7086,7 +7086,7 @@ int
 ppc_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
 		      CORE_ADDR addr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   uint32_t insn, insn_suffix;
   int op6, tmp, i;
@@ -8150,7 +8150,7 @@ rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 	 meaningful, because 64-bit CPUs can run in 32-bit mode.  So, perform
 	 separate word size check.  */
       ppc_gdbarch_tdep *tdep
-	= (ppc_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<ppc_gdbarch_tdep> (arches->gdbarch);
       if (tdep && tdep->elf_abi != elf_abi)
 	continue;
       if (tdep && tdep->soft_float != soft_float)
@@ -8452,7 +8452,7 @@ rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 rs6000_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (tdep == NULL)
     return;
diff --git a/gdb/rx-tdep.c b/gdb/rx-tdep.c
index 2a24ebba2b6..c67d4057195 100644
--- a/gdb/rx-tdep.c
+++ b/gdb/rx-tdep.c
@@ -964,7 +964,7 @@ rx_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       rx_gdbarch_tdep *tdep
-	= (rx_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<rx_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->elf_flags != elf_flags)
 	continue;
diff --git a/gdb/s390-linux-tdep.c b/gdb/s390-linux-tdep.c
index 9d4e2d09f2a..03611fe1d23 100644
--- a/gdb/s390-linux-tdep.c
+++ b/gdb/s390-linux-tdep.c
@@ -79,7 +79,7 @@ static void
 s390_write_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
 
@@ -269,7 +269,7 @@ s390_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				   void *cb_data,
 				   const struct regcache *regcache)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   const int gregset_size = (tdep->abi == ABI_LINUX_S390 ?
 			    s390_sizeof_gregset : s390x_sizeof_gregset);
 
@@ -390,7 +390,7 @@ s390_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
 				  void **this_prologue_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   int word_size = gdbarch_ptr_bit (gdbarch) / 8;
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct s390_sigtramp_unwind_cache *info;
@@ -561,7 +561,7 @@ s390_linux_get_syscall_number (struct gdbarch *gdbarch,
 			       thread_info *thread)
 {
   struct regcache *regs = get_thread_regcache (thread);
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   ULONGEST pc;
   ULONGEST svc_number = -1;
@@ -594,7 +594,7 @@ static int
 s390_all_but_pc_registers_record (struct regcache *regcache)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   int i;
 
   for (i = 0; i < 16; i++)
@@ -802,7 +802,7 @@ static int
 s390_linux_syscall_record (struct regcache *regcache, LONGEST syscall_native)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   int ret;
   enum gdb_syscall syscall_gdb;
 
@@ -853,7 +853,7 @@ static int
 s390_linux_record_signal (struct gdbarch *gdbarch, struct regcache *regcache,
 			  enum gdb_signal signal)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   /* There are two kinds of signal frames on s390. rt_sigframe is always
      the larger one, so don't even bother with sigframe.  */
   const int sizeof_rt_sigframe = (tdep->abi == ABI_LINUX_ZSERIES ?
@@ -1117,7 +1117,7 @@ s390_init_linux_record_tdep (struct linux_record_tdep *record_tdep,
 static void
 s390_linux_init_abi_any (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   tdep->s390_syscall_record = s390_linux_syscall_record;
 
@@ -1152,7 +1152,7 @@ s390_linux_init_abi_any (struct gdbarch_info info, struct gdbarch *gdbarch)
 static void
 s390_linux_init_abi_31 (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   tdep->abi = ABI_LINUX_S390;
 
@@ -1168,7 +1168,7 @@ s390_linux_init_abi_31 (struct gdbarch_info info, struct gdbarch *gdbarch)
 static void
 s390_linux_init_abi_64 (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   tdep->abi = ABI_LINUX_ZSERIES;
 
diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c
index 14b03a167d7..2aeb3a14637 100644
--- a/gdb/s390-tdep.c
+++ b/gdb/s390-tdep.c
@@ -1045,7 +1045,7 @@ s390_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
 static int
 s390_register_call_saved (struct gdbarch *gdbarch, int regnum)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   switch (tdep->abi)
     {
@@ -1076,7 +1076,7 @@ s390_guess_tracepoint_registers (struct gdbarch *gdbarch,
 				 struct regcache *regcache,
 				 CORE_ADDR addr)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   int sz = register_size (gdbarch, S390_PSWA_REGNUM);
   gdb_byte *reg = (gdb_byte *) alloca (sz);
   ULONGEST pswm, pswa;
@@ -1172,7 +1172,7 @@ enum { s390_dwarf_reg_r0l = ARRAY_SIZE (s390_dwarf_regmap) - 16 };
 static int
 s390_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   int gdb_reg = -1;
 
   /* In a 32-on-64 debug scenario, debug info refers to the full
@@ -1231,7 +1231,7 @@ static struct value *
 s390_value_from_register (struct gdbarch *gdbarch, struct type *type,
 			  int regnum, struct frame_id frame_id)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   struct value *value = default_value_from_register (gdbarch, type,
 						     regnum, frame_id);
   check_typedef (type);
@@ -1250,7 +1250,7 @@ s390_value_from_register (struct gdbarch *gdbarch, struct type *type,
 static const char *
 s390_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   if (regnum == tdep->pc_regnum)
     return "pc";
@@ -1284,7 +1284,7 @@ s390_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 static struct type *
 s390_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   if (regnum == tdep->pc_regnum)
     return builtin_type (gdbarch)->builtin_func_ptr;
@@ -1308,7 +1308,7 @@ static enum register_status
 s390_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int regnum, gdb_byte *buf)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int regsize = register_size (gdbarch, regnum);
   ULONGEST val;
@@ -1383,7 +1383,7 @@ static void
 s390_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
 			    int regnum, const gdb_byte *buf)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int regsize = register_size (gdbarch, regnum);
   ULONGEST val, psw;
@@ -1442,7 +1442,7 @@ static int
 s390_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 				 const struct reggroup *group)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   /* We usually save/restore the whole PSW, which includes PC and CC.
      However, some older gdbservers may not support saving/restoring
@@ -1470,7 +1470,7 @@ static int
 s390_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				 struct agent_expr *ax, int regnum)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   if (regnum == tdep->pc_regnum)
     {
       ax_reg_mask (ax, S390_PSWA_REGNUM);
@@ -1504,7 +1504,7 @@ static int
 s390_ax_pseudo_register_push_stack (struct gdbarch *gdbarch,
 				    struct agent_expr *ax, int regnum)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   if (regnum == tdep->pc_regnum)
     {
       ax_reg (ax, S390_PSWA_REGNUM);
@@ -1905,7 +1905,7 @@ s390_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 		      function_call_return_method return_method,
 		      CORE_ADDR struct_addr)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   int word_size = gdbarch_ptr_bit (gdbarch) / 8;
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int i;
@@ -2084,7 +2084,7 @@ s390_return_value (struct gdbarch *gdbarch, struct value *function,
       break;
     case TYPE_CODE_ARRAY:
       {
-	s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 	rvc = (tdep->vector_abi == S390_VECTOR_ABI_128
 	       && TYPE_LENGTH (type) <= 16 && type->is_vector ())
 	  ? RETURN_VALUE_REGISTER_CONVENTION
@@ -2168,7 +2168,7 @@ s390_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
 static CORE_ADDR
 s390_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   ULONGEST pc;
   pc = frame_unwind_register_unsigned (next_frame, tdep->pc_regnum);
   return gdbarch_addr_bits_remove (gdbarch, pc);
@@ -2190,7 +2190,7 @@ static struct value *
 s390_unwind_pseudo_register (struct frame_info *this_frame, int regnum)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   struct type *type = register_type (gdbarch, regnum);
 
   /* Unwind PC via PSW address.  */
@@ -2775,7 +2775,7 @@ static CORE_ADDR
 s390_record_address_mask (struct gdbarch *gdbarch, struct regcache *regcache,
 			  CORE_ADDR val)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   ULONGEST pswm, pswa;
   int am;
   if (tdep->abi == ABI_LINUX_S390)
@@ -2842,7 +2842,7 @@ s390_record_calc_disp_vsce (struct gdbarch *gdbarch, struct regcache *regcache,
 			    uint8_t vx, uint8_t el, uint8_t es, uint16_t bd,
 			    int8_t dh, CORE_ADDR *res)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   ULONGEST x;
   gdb_byte buf[16];
@@ -2885,7 +2885,7 @@ static int s390_popcnt (unsigned int x) {
 static int
 s390_record_gpr_g (struct gdbarch *gdbarch, struct regcache *regcache, int i)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + i))
     return -1;
   if (tdep->abi == ABI_LINUX_S390)
@@ -2899,7 +2899,7 @@ s390_record_gpr_g (struct gdbarch *gdbarch, struct regcache *regcache, int i)
 static int
 s390_record_gpr_h (struct gdbarch *gdbarch, struct regcache *regcache, int i)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   if (tdep->abi == ABI_LINUX_S390)
     {
       if (record_full_arch_list_add_reg (regcache, S390_R0_UPPER_REGNUM + i))
@@ -2939,7 +2939,7 @@ static int
 s390_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
 		     CORE_ADDR addr)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   uint16_t insn[3] = {0};
   /* Instruction as bytes.  */
   uint8_t ibyte[6];
@@ -7178,7 +7178,7 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       s390_gdbarch_tdep *tmp
-	= (s390_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<s390_gdbarch_tdep> (arches->gdbarch);
 
       if (!tmp)
 	continue;
diff --git a/gdb/sh-linux-tdep.c b/gdb/sh-linux-tdep.c
index 2975a8f5d3d..f146f023add 100644
--- a/gdb/sh-linux-tdep.c
+++ b/gdb/sh-linux-tdep.c
@@ -195,7 +195,7 @@ sh_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   set_gdbarch_fetch_tls_load_module_address (gdbarch,
 					     svr4_fetch_objfile_link_map);
 
-  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
 
   /* Remember regset characteristics.  The sizes should match
      elf_gregset_t and elf_fpregset_t from Linux.  */
diff --git a/gdb/sh-netbsd-tdep.c b/gdb/sh-netbsd-tdep.c
index 4fbb53b49ff..49760337c4b 100644
--- a/gdb/sh-netbsd-tdep.c
+++ b/gdb/sh-netbsd-tdep.c
@@ -63,7 +63,7 @@ static void
 shnbsd_init_abi (struct gdbarch_info info,
 		  struct gdbarch *gdbarch)
 {
-  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
   nbsd_init_abi (info, gdbarch);
 
   tdep->core_gregmap = (struct sh_corefile_regmap *)regmap;
diff --git a/gdb/sh-tdep.c b/gdb/sh-tdep.c
index 2341a9beef6..062df860c81 100644
--- a/gdb/sh-tdep.c
+++ b/gdb/sh-tdep.c
@@ -1554,7 +1554,7 @@ sh_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 static struct type *
 sh_littlebyte_bigword_type (struct gdbarch *gdbarch)
 {
-  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
 
   if (tdep->sh_littlebyte_bigword_type == NULL)
     tdep->sh_littlebyte_bigword_type
@@ -2146,7 +2146,7 @@ sh_corefile_supply_regset (const struct regset *regset,
 			   int regnum, const void *regs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
   const struct sh_corefile_regmap *regmap = (regset == &sh_corefile_gregset
 					     ? tdep->core_gregmap
 					     : tdep->core_fpregmap);
@@ -2172,7 +2172,7 @@ sh_corefile_collect_regset (const struct regset *regset,
 			    int regnum, void *regs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
   const struct sh_corefile_regmap *regmap = (regset == &sh_corefile_gregset
 					     ? tdep->core_gregmap
 					     : tdep->core_fpregmap);
@@ -2210,7 +2210,7 @@ sh_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				 void *cb_data,
 				 const struct regcache *regcache)
 {
-  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
 
   if (tdep->core_gregmap != NULL)
     cb (".reg", tdep->sizeof_gregset, tdep->sizeof_gregset,
diff --git a/gdb/sparc-linux-tdep.c b/gdb/sparc-linux-tdep.c
index 18196b2f075..66481ea7b8a 100644
--- a/gdb/sparc-linux-tdep.c
+++ b/gdb/sparc-linux-tdep.c
@@ -254,7 +254,7 @@ static void
 sparc_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   gdbarch *arch = regcache->arch ();
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
   ULONGEST psr;
 
   regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
@@ -421,7 +421,7 @@ static const struct regset sparc32_linux_fpregset =
 static void
 sparc32_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/sparc-netbsd-tdep.c b/gdb/sparc-netbsd-tdep.c
index a97a772dba2..57c178511fa 100644
--- a/gdb/sparc-netbsd-tdep.c
+++ b/gdb/sparc-netbsd-tdep.c
@@ -295,7 +295,7 @@ static const struct regset sparc32nbsd_fpregset =
 void
 sparc32nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   nbsd_init_abi (info, gdbarch);
 
diff --git a/gdb/sparc-sol2-tdep.c b/gdb/sparc-sol2-tdep.c
index 28eb6f67601..a92e95ce71b 100644
--- a/gdb/sparc-sol2-tdep.c
+++ b/gdb/sparc-sol2-tdep.c
@@ -196,7 +196,7 @@ static const struct frame_unwind sparc32_sol2_sigtramp_frame_unwind =
 static void
 sparc32_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   tdep->gregset = &sparc32_sol2_gregset;
   tdep->sizeof_gregset = 152;
diff --git a/gdb/sparc-tdep.c b/gdb/sparc-tdep.c
index e540263a2fe..397f5489550 100644
--- a/gdb/sparc-tdep.c
+++ b/gdb/sparc-tdep.c
@@ -425,7 +425,7 @@ sparc32_register_name (struct gdbarch *gdbarch, int regnum)
 static struct type *
 sparc_psr_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->sparc_psr_type)
     {
@@ -447,7 +447,7 @@ sparc_psr_type (struct gdbarch *gdbarch)
 static struct type *
 sparc_fsr_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->sparc_fsr_type)
     {
@@ -988,7 +988,7 @@ CORE_ADDR
 sparc_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
 			CORE_ADDR current_pc, struct sparc_frame_cache *cache)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
   unsigned long insn;
   int offset = 0;
   int dest = -1;
@@ -1680,7 +1680,7 @@ sparc_analyze_control_transfer (struct regcache *regcache,
 
       /* Trap instruction (TRAP).  */
       gdbarch *arch = regcache->arch ();
-      sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
+      sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
       return tdep->step_trap (frame, insn);
     }
 
@@ -1731,7 +1731,7 @@ static std::vector<CORE_ADDR>
 sparc_software_single_step (struct regcache *regcache)
 {
   struct gdbarch *arch = regcache->arch ();
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
   CORE_ADDR npc, nnpc;
 
   CORE_ADDR pc, orig_npc;
@@ -1761,7 +1761,7 @@ static void
 sparc_write_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   gdbarch *arch = regcache->arch ();
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
 
   regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
   regcache_cooked_write_unsigned (regcache, tdep->npc_regnum, pc + 4);
@@ -1776,7 +1776,7 @@ sparc_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				    void *cb_data,
 				    const struct regcache *regcache)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   cb (".reg", tdep->sizeof_gregset, tdep->sizeof_gregset, tdep->gregset, NULL,
       cb_data);
diff --git a/gdb/sparc64-fbsd-tdep.c b/gdb/sparc64-fbsd-tdep.c
index 8a288282772..76c682fd521 100644
--- a/gdb/sparc64-fbsd-tdep.c
+++ b/gdb/sparc64-fbsd-tdep.c
@@ -222,7 +222,7 @@ static const struct regset sparc64fbsd_fpregset =
 static void
 sparc64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support. */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/sparc64-linux-tdep.c b/gdb/sparc64-linux-tdep.c
index 9ea72331e93..f5940cfcdee 100644
--- a/gdb/sparc64-linux-tdep.c
+++ b/gdb/sparc64-linux-tdep.c
@@ -262,7 +262,7 @@ static void
 sparc64_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   gdbarch *arch = regcache->arch ();
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
   ULONGEST state;
 
   regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
@@ -364,7 +364,7 @@ static const struct regset sparc64_linux_fpregset =
 static void
 sparc64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/sparc64-netbsd-tdep.c b/gdb/sparc64-netbsd-tdep.c
index 29cd3b6f3ba..db368118f23 100644
--- a/gdb/sparc64-netbsd-tdep.c
+++ b/gdb/sparc64-netbsd-tdep.c
@@ -248,7 +248,7 @@ static const struct regset sparc64nbsd_fpregset =
 static void
 sparc64nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   nbsd_init_abi (info, gdbarch);
 
diff --git a/gdb/sparc64-obsd-tdep.c b/gdb/sparc64-obsd-tdep.c
index 05ebbd2e84a..d6470a51b65 100644
--- a/gdb/sparc64-obsd-tdep.c
+++ b/gdb/sparc64-obsd-tdep.c
@@ -423,7 +423,7 @@ static const struct regset sparc64obsd_fpregset =
 static void
 sparc64obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   tdep->gregset = &sparc64obsd_gregset;
   tdep->sizeof_gregset = 288;
diff --git a/gdb/sparc64-sol2-tdep.c b/gdb/sparc64-sol2-tdep.c
index 458f0320582..e656c359efa 100644
--- a/gdb/sparc64-sol2-tdep.c
+++ b/gdb/sparc64-sol2-tdep.c
@@ -199,7 +199,7 @@ static const struct frame_unwind sparc64_sol2_sigtramp_frame_unwind =
 static void
 sparc64_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   tdep->gregset = &sparc64_sol2_gregset;
   tdep->sizeof_gregset = 304;
diff --git a/gdb/sparc64-tdep.c b/gdb/sparc64-tdep.c
index 95496d33ad4..5ca5f2dca8c 100644
--- a/gdb/sparc64-tdep.c
+++ b/gdb/sparc64-tdep.c
@@ -648,7 +648,7 @@ sparc64_structure_or_union_p (const struct type *type)
 static struct type *
 sparc64_pstate_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->sparc64_pstate_type)
     {
@@ -675,7 +675,7 @@ sparc64_pstate_type (struct gdbarch *gdbarch)
 static struct type *
 sparc64_ccr_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   if (tdep->sparc64_ccr_type == NULL)
     {
@@ -700,7 +700,7 @@ sparc64_ccr_type (struct gdbarch *gdbarch)
 static struct type *
 sparc64_fsr_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->sparc64_fsr_type)
     {
@@ -733,7 +733,7 @@ sparc64_fsr_type (struct gdbarch *gdbarch)
 static struct type *
 sparc64_fprs_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->sparc64_fprs_type)
     {
@@ -1806,7 +1806,7 @@ sparc64_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr)
 void
 sparc64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   tdep->pc_regnum = SPARC64_PC_REGNUM;
   tdep->npc_regnum = SPARC64_NPC_REGNUM;
diff --git a/gdb/tic6x-linux-tdep.c b/gdb/tic6x-linux-tdep.c
index 5a93294361a..b2422d1ccc0 100644
--- a/gdb/tic6x-linux-tdep.c
+++ b/gdb/tic6x-linux-tdep.c
@@ -45,7 +45,7 @@ static const gdb_byte tic6x_bkpt_bnop_le[] = { 0x22, 0xa1, 0x00, 0x00 };
 static unsigned int
 tic6x_register_sigcontext_offset (unsigned int regnum, struct gdbarch *gdbarch)
 {
-  tic6x_gdbarch_tdep *tdep = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  tic6x_gdbarch_tdep *tdep = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
 
   if (regnum == TIC6X_A4_REGNUM || regnum == TIC6X_A4_REGNUM + 2
       || regnum == TIC6X_A4_REGNUM + 4)
@@ -92,7 +92,7 @@ tic6x_linux_rt_sigreturn_init (const struct tramp_frame *self,
 		    + TIC6X_SIGINFO_SIZE
 		    + 4 + 4 /* uc_flags and *uc_link in struct ucontext.  */
 		    + TIC6X_STACK_T_SIZE);
-  tic6x_gdbarch_tdep *tdep = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  tic6x_gdbarch_tdep *tdep = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
   unsigned int reg_offset;
   unsigned int i;
 
@@ -165,7 +165,7 @@ extern struct target_so_ops dsbt_so_ops;
 static void
 tic6x_uclinux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  tic6x_gdbarch_tdep *tdep = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  tic6x_gdbarch_tdep *tdep = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/tic6x-tdep.c b/gdb/tic6x-tdep.c
index 3e49030ab14..b7efcf18576 100644
--- a/gdb/tic6x-tdep.c
+++ b/gdb/tic6x-tdep.c
@@ -325,7 +325,7 @@ tic6x_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 static const gdb_byte *
 tic6x_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
-  tic6x_gdbarch_tdep *tdep = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  tic6x_gdbarch_tdep *tdep = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
 
   *size = kind;
 
@@ -599,7 +599,7 @@ tic6x_get_next_pc (struct regcache *regcache, CORE_ADDR pc)
       if (inst == TIC6X_INST_SWE)
 	{
 	  tic6x_gdbarch_tdep *tdep
-	    = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	    = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
 
 	  if (tdep->syscall_next_pc != NULL)
 	    return tdep->syscall_next_pc (get_current_frame ());
@@ -1217,7 +1217,7 @@ tic6x_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       tic6x_gdbarch_tdep *tdep
-	= (tic6x_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<tic6x_gdbarch_tdep> (arches->gdbarch);
 
       if (has_gp != tdep->has_gp)
 	continue;
diff --git a/gdb/v850-tdep.c b/gdb/v850-tdep.c
index a67310a2440..4de5faa6a47 100644
--- a/gdb/v850-tdep.c
+++ b/gdb/v850-tdep.c
@@ -511,7 +511,7 @@ v850_use_struct_convention (struct gdbarch *gdbarch, struct type *type)
 {
   int i;
   struct type *fld_type, *tgt_type;
-  v850_gdbarch_tdep *tdep = (v850_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  v850_gdbarch_tdep *tdep = gdbarch_tdep<v850_gdbarch_tdep> (gdbarch);
 
   if (tdep->abi == V850_ABI_RH850)
     {
@@ -1023,7 +1023,7 @@ v850_push_dummy_call (struct gdbarch *gdbarch,
   int argnum;
   int arg_space = 0;
   int stack_offset;
-  v850_gdbarch_tdep *tdep = (v850_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  v850_gdbarch_tdep *tdep = gdbarch_tdep<v850_gdbarch_tdep> (gdbarch);
 
   if (tdep->abi == V850_ABI_RH850)
     stack_offset = 0;
@@ -1374,7 +1374,7 @@ v850_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       v850_gdbarch_tdep *tdep
-	= (v850_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<v850_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->e_flags != e_flags || tdep->e_machine != e_machine)
 	continue;
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 11f54302b11..63869b38ff9 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -471,7 +471,7 @@ windows_fetch_one_register (struct regcache *regcache,
 
   char *context_offset = context_ptr + mappings[r];
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   gdb_assert (!gdbarch_read_pc_p (gdbarch));
   gdb_assert (gdbarch_pc_regnum (gdbarch) >= 0);
diff --git a/gdb/xtensa-linux-nat.c b/gdb/xtensa-linux-nat.c
index 5a08824a680..d005c9d8f78 100644
--- a/gdb/xtensa-linux-nat.c
+++ b/gdb/xtensa-linux-nat.c
@@ -62,7 +62,7 @@ fill_gregset (const struct regcache *regcache,
   int i;
   xtensa_elf_gregset_t *regs = (xtensa_elf_gregset_t *) gregsetp;
   struct gdbarch *gdbarch = regcache->arch ();
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   if (regnum == gdbarch_pc_regnum (gdbarch) || regnum == -1)
     regcache->raw_collect (gdbarch_pc_regnum (gdbarch), &regs->pc);
@@ -124,7 +124,7 @@ supply_gregset_reg (struct regcache *regcache,
   xtensa_elf_gregset_t *regs = (xtensa_elf_gregset_t *) gregsetp;
 
   struct gdbarch *gdbarch = regcache->arch ();
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   if (regnum == gdbarch_pc_regnum (gdbarch) || regnum == -1)
     regcache->raw_supply (gdbarch_pc_regnum (gdbarch), &regs->pc);
diff --git a/gdb/xtensa-linux-tdep.c b/gdb/xtensa-linux-tdep.c
index ef55319fd09..600b59b8894 100644
--- a/gdb/xtensa-linux-tdep.c
+++ b/gdb/xtensa-linux-tdep.c
@@ -99,7 +99,7 @@ xtensa_linux_gdb_signal_to_target (struct gdbarch *gdbarch,
 static void
 xtensa_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   if (tdep->num_nopriv_regs < tdep->num_regs)
     {
diff --git a/gdb/xtensa-tdep.c b/gdb/xtensa-tdep.c
index b6558838e44..f881870e244 100644
--- a/gdb/xtensa-tdep.c
+++ b/gdb/xtensa-tdep.c
@@ -116,7 +116,7 @@ static unsigned int xtensa_debug_level = 0;
 static int
 windowing_enabled (struct gdbarch *gdbarch, unsigned int ps)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   /* If we know CALL0 ABI is set explicitly,  say it is Call0.  */
   if (tdep->call_abi == CallAbiCall0Only)
@@ -130,7 +130,7 @@ windowing_enabled (struct gdbarch *gdbarch, unsigned int ps)
 static int
 arreg_number (struct gdbarch *gdbarch, int a_regnum, ULONGEST wb)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   int arreg;
 
   arreg = a_regnum - tdep->a0_base;
@@ -145,7 +145,7 @@ arreg_number (struct gdbarch *gdbarch, int a_regnum, ULONGEST wb)
 static int
 areg_number (struct gdbarch *gdbarch, int ar_regnum, unsigned int wb)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   int areg;
 
   areg = ar_regnum - tdep->ar_base;
@@ -226,7 +226,7 @@ static int
 xtensa_find_register_by_name (struct gdbarch *gdbarch, const char *name)
 {
   int i;
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   for (i = 0; i < gdbarch_num_cooked_regs (gdbarch); i++)
     if (strcasecmp (tdep->regmap[i].name, name) == 0)
@@ -239,7 +239,7 @@ xtensa_find_register_by_name (struct gdbarch *gdbarch, const char *name)
 static const char *
 xtensa_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   /* Return the name stored in the register map.  */
   if (regnum >= 0 && regnum < gdbarch_num_cooked_regs (gdbarch))
@@ -254,7 +254,7 @@ xtensa_register_name (struct gdbarch *gdbarch, int regnum)
 static struct type *
 xtensa_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   /* Return signed integer for ARx and Ax registers.  */
   if ((regnum >= tdep->ar_base
@@ -339,7 +339,7 @@ static int
 xtensa_reg_to_regnum (struct gdbarch *gdbarch, int regnum)
 {
   int i;
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   if (regnum >= 0 && regnum < 16)
     return tdep->a0_base + regnum;
@@ -542,7 +542,7 @@ xtensa_pseudo_register_read (struct gdbarch *gdbarch,
 {
   DEBUGTRACE ("xtensa_pseudo_register_read (... regnum = %d (%s) ...)\n",
 	      regnum, xtensa_register_name (gdbarch, regnum));
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   /* Read aliases a0..a15, if this is a Windowed ABI.  */
   if (tdep->isa_use_windowed_registers
@@ -634,7 +634,7 @@ xtensa_pseudo_register_write (struct gdbarch *gdbarch,
 {
   DEBUGTRACE ("xtensa_pseudo_register_write (... regnum = %d (%s) ...)\n",
 	      regnum, xtensa_register_name (gdbarch, regnum));
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   /* Renumber register, if aliases a0..a15 on Windowed ABI.  */
   if (tdep->isa_use_windowed_registers
@@ -767,7 +767,7 @@ xtensa_register_reggroup_p (struct gdbarch *gdbarch,
 			    int regnum,
 			    const struct reggroup *group)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   xtensa_register_t* reg = &tdep->regmap[regnum];
   xtensa_register_type_t type = reg->type;
   xtensa_register_group_t rg = reg->group;
@@ -821,7 +821,7 @@ xtensa_supply_gregset (const struct regset *regset,
 {
   const xtensa_elf_gregset_t *regs = (const xtensa_elf_gregset_t *) gregs;
   struct gdbarch *gdbarch = rc->arch ();
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   int i;
 
   DEBUGTRACE ("xtensa_supply_gregset (..., regnum==%d, ...)\n", regnum);
@@ -1050,7 +1050,7 @@ static struct frame_id
 xtensa_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
 {
   CORE_ADDR pc, fp;
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   /* THIS-FRAME is a dummy frame.  Return a frame ID of that frame.  */
 
@@ -1105,7 +1105,7 @@ xtensa_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR current_pc)
 {
 #define RETURN_FP goto done
 
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   unsigned int fp_regnum = tdep->a0_base + 1;
   CORE_ADDR start_addr;
   xtensa_isa isa;
@@ -1255,7 +1255,7 @@ xtensa_frame_cache (struct frame_info *this_frame, void **this_cache)
   if (windowed)
     {
       LONGEST op1;
-      xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
       /* Get WINDOWBASE, WINDOWSTART, and PS registers.  */
       wb = get_frame_register_unsigned (this_frame, 
@@ -1417,7 +1417,7 @@ xtensa_frame_prev_register (struct frame_info *this_frame,
   struct xtensa_frame_cache *cache;
   ULONGEST saved_reg = 0;
   int done = 1;
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   if (*this_cache == NULL)
     *this_cache = xtensa_frame_cache (this_frame, this_cache);
@@ -1546,7 +1546,7 @@ xtensa_extract_return_value (struct type *type,
 
   gdb_assert(len > 0);
 
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   if (tdep->call_abi != CallAbiCall0Only)
     {
       /* First, we have to find the caller window in the register file.  */
@@ -1602,7 +1602,7 @@ xtensa_store_return_value (struct type *type,
 
   DEBUGTRACE ("xtensa_store_return_value (...)\n");
 
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   if (tdep->call_abi != CallAbiCall0Only)
     {
       regcache_raw_read_unsigned 
@@ -1686,7 +1686,7 @@ xtensa_push_dummy_call (struct gdbarch *gdbarch,
 			CORE_ADDR struct_addr)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   int size, onstack_size;
   gdb_byte *buf = (gdb_byte *) alloca (16);
   CORE_ADDR ra, ps;
@@ -1935,7 +1935,7 @@ xtensa_push_dummy_call (struct gdbarch *gdbarch,
 static int
 xtensa_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   if (tdep->isa_use_density_instructions)
     return 2;
@@ -2182,7 +2182,7 @@ call0_track_op (struct gdbarch *gdbarch, xtensa_c0reg_t dst[], xtensa_c0reg_t sr
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   unsigned litbase, litaddr, litval;
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   switch (opclass)
     {
@@ -2557,7 +2557,7 @@ call0_frame_cache (struct frame_info *this_frame,
   CORE_ADDR body_pc=UINT_MAX;	/* PC, where prologue analysis stopped.  */
   CORE_ADDR sp, fp, ra;
   int fp_regnum = C0_SP, c0_hasfp = 0, c0_frmsz = 0, prev_sp = 0, to_stk;
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
  
   sp = get_frame_register_unsigned
     (this_frame, tdep->a0_base + 1);
@@ -2710,7 +2710,7 @@ static int a11_was_saved;
 static void
 execute_l32e (struct gdbarch *gdbarch, int at, int as, int offset, CORE_ADDR wb)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   int atreg = arreg_number (gdbarch, tdep->a0_base + at, wb);
   int asreg = arreg_number (gdbarch, tdep->a0_base + as, wb);
   CORE_ADDR addr = xtensa_read_register (asreg) + offset;
@@ -2740,7 +2740,7 @@ execute_l32e (struct gdbarch *gdbarch, int at, int as, int offset, CORE_ADDR wb)
 static void
 execute_s32e (struct gdbarch *gdbarch, int at, int as, int offset, CORE_ADDR wb)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   int atreg = arreg_number (gdbarch, tdep->a0_base + at, wb);
   int asreg = arreg_number (gdbarch, tdep->a0_base + as, wb);
   CORE_ADDR addr = xtensa_read_register (asreg) + offset;
@@ -2774,7 +2774,7 @@ execute_code (struct gdbarch *gdbarch, CORE_ADDR current_pc, CORE_ADDR wb)
   xtensa_opcode opc;
   int insn_num = 0;
   void (*func) (struct gdbarch *, int, int, int, CORE_ADDR);
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   uint32_t at, as, offset;
 
@@ -2905,7 +2905,7 @@ xtensa_window_interrupt_frame_cache (struct frame_info *this_frame,
   CORE_ADDR ps, wb, ws, ra;
   int epc1_regnum, i, regnum;
   xtensa_exception_handler_t eh_type;
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   /* Read PS, WB, and WS from the hardware. Note that PS register
      must be present, if Windowed ABI is supported.  */
@@ -3019,7 +3019,7 @@ xtensa_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
 
       CORE_ADDR end_func;
 
-      xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
       if ((tdep->call_abi == CallAbiCall0Only)
 	  && call0_ret (start_pc, prologue_sal.end))
 	return start_pc;
@@ -3041,7 +3041,7 @@ xtensa_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
 static void
 xtensa_verify_config (struct gdbarch *gdbarch)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   string_file log;
 
   /* Verify that we got a reasonable number of AREGS.  */
diff --git a/gdb/z80-tdep.c b/gdb/z80-tdep.c
index c2d906d1402..62d8ed96190 100644
--- a/gdb/z80-tdep.c
+++ b/gdb/z80-tdep.c
@@ -308,7 +308,7 @@ z80_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR pc_beg, CORE_ADDR pc_end,
 		   struct z80_unwind_cache *info)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  z80_gdbarch_tdep *tdep = (z80_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  z80_gdbarch_tdep *tdep = gdbarch_tdep<z80_gdbarch_tdep> (gdbarch);
   int addr_len = tdep->addr_length;
   gdb_byte prologue[32]; /* max prologue is 24 bytes: __interrupt with local array */
   int pos = 0;
@@ -564,7 +564,7 @@ z80_frame_unwind_cache (struct frame_info *this_frame,
   gdb_byte buf[sizeof(void*)];
   struct z80_unwind_cache *info;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  z80_gdbarch_tdep *tdep = (z80_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  z80_gdbarch_tdep *tdep = gdbarch_tdep<z80_gdbarch_tdep> (gdbarch);
   int addr_len = tdep->addr_length;
 
   if (*this_prologue_cache)
@@ -697,7 +697,7 @@ z80_frame_prev_register (struct frame_info *this_frame,
 	  ULONGEST pc;
 	  gdb_byte buf[3];
 	  struct gdbarch *gdbarch = get_frame_arch (this_frame);
-	  z80_gdbarch_tdep *tdep = (z80_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	  z80_gdbarch_tdep *tdep = gdbarch_tdep<z80_gdbarch_tdep> (gdbarch);
 	  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
 	  read_memory (info->saved_regs[Z80_PC_REGNUM].addr (),
@@ -750,7 +750,7 @@ z80_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
     }
   else /* kind is non-RST address, use CALL instead, but it is dungerous */
     {
-      z80_gdbarch_tdep *tdep = (z80_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      z80_gdbarch_tdep *tdep = gdbarch_tdep<z80_gdbarch_tdep> (gdbarch);
       gdb_byte *p = break_insn;
       *p++ = 0xcd;
       *p++ = (kind >> 0) & 0xff;
-- 
2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCH 4/5] gdb: ensure the cast in gdbarch_tdep is valid
  2022-05-31 14:30 [PATCH 0/5] Handle trying to use a native target with the wrong binary Andrew Burgess
                   ` (2 preceding siblings ...)
  2022-05-31 14:30 ` [PATCH 3/5] gdb: move the type cast into gdbarch_tdep Andrew Burgess
@ 2022-05-31 14:30 ` Andrew Burgess
  2022-05-31 16:04   ` John Baldwin
  2022-05-31 14:30 ` [PATCH 5/5] gdb: native target invalid architecture detection Andrew Burgess
  2022-06-10 13:08 ` [PATCHv2 0/6] Handle trying to use a native target with the wrong binary Andrew Burgess
  5 siblings, 1 reply; 83+ messages in thread
From: Andrew Burgess @ 2022-05-31 14:30 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

This commit builds on the previous commit and modifies the
gdbarch_tdep function to ensure that the cast being performed is
valid.

To do this I make use of dynamic_cast to ensure that the generic
gdbarch_tdep pointer that we have is of the correct type.

The only problem with this approach is that, in order to use
dynamic_cast, we need RTTI information, which requires the class to
have a vtable, which currently, is not something the various tdep
classes have.

And so, in this commit, I add a virtual destructor to the gdbarch_tdep
class.

With this change I can now add an assert in the gdbarch_tdep function.

Obviously, this change comes at a cost, creation of the tdep classes
is now slightly more expensive (due to vtable initialisation),
however, this only happens when a new gdbarch is created, which is not
that frequent, so I don't see that as a huge concern.

Then, there is an increased cost each time the tdep is accessed.  This
is much more frequent, but I don't believe the cost is excessive (a
vtable pointer comparison), at least, no worse than many of our other
asserts.

If we consider the motivating example that was discussed in the
previous commit; build GDB for all targets on an x86-64 GNU/Linux
system, and then attempt to "run" a RISC-V binary using the native
x86-64 Linux target.  Previously this would trigger an assert while
accessing fields within a i386_gdbarch_tdep, like this:

  ../../src/gdb/i387-tdep.c:596: internal-error: i387_supply_fxsave: Assertion `tdep->st0_regnum >= I386_ST0_REGNUM' failed.

But with the changes from this commit in place, we now see an
assertion failure like this:

  ../../src/gdb/gdbarch.h:166: internal-error: gdbarch_tdep: Assertion `dynamic_cast<TDepType *> (tdep) != nullptr' failed.

On the face of it, this might not seem like much of an improvement,
but I think it is.

The previous assert was triggered by undefined behaviour.  There's no
guarantee that we would see an assertion at all, a different
combination of native target and binary format might not trigger an
assert (and just do the wrong thing), or might crash GDB completely.

In contrast, the new assert is based on defined behaviour, we'll
always assert if GDB goes wrong, and we assert early, at the point the
mistake is being made (casting the result of gdbarch_tdep to the wrong
type), rather than at some later point after the incorrect cast has
completed.

Obviously, when we consider the original example, trying to run a
binary of the wrong architecture on a native target, having GDB fail
with an assertion is not a real solution.  No user action should be
able to trigger an assertion failure.  In a later commit I will offer
a real solution to this architecture mismatch problem.
---
 gdb/gdbarch.h | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index b2c91db0c4f..ea507d70ec9 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -58,7 +58,13 @@ struct inferior;
 
 #include "regcache.h"
 
-struct gdbarch_tdep {};
+/* The base class for every architecture's tdep sub-class.  We include a
+   virtual destructor so that sub-classes will have RTTI information.  */
+
+struct gdbarch_tdep
+{
+  virtual ~gdbarch_tdep() = default;
+};
 
 /* The architecture associated with the inferior through the
    connection to the target.
@@ -157,6 +163,7 @@ static inline TDepType *
 gdbarch_tdep (struct gdbarch *gdbarch)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep_1 (gdbarch);
+  gdb_assert (dynamic_cast<TDepType *> (tdep) != nullptr);
   return static_cast<TDepType *> (tdep);
 }
 
-- 
2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCH 5/5] gdb: native target invalid architecture detection
  2022-05-31 14:30 [PATCH 0/5] Handle trying to use a native target with the wrong binary Andrew Burgess
                   ` (3 preceding siblings ...)
  2022-05-31 14:30 ` [PATCH 4/5] gdb: ensure the cast in gdbarch_tdep is valid Andrew Burgess
@ 2022-05-31 14:30 ` Andrew Burgess
  2022-05-31 16:08   ` John Baldwin
  2022-06-10 13:08 ` [PATCHv2 0/6] Handle trying to use a native target with the wrong binary Andrew Burgess
  5 siblings, 1 reply; 83+ messages in thread
From: Andrew Burgess @ 2022-05-31 14:30 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

If GDB is asked to start a new inferior, or attach to an existing
process, using a binary file for an architecture that does not match
the current native target, then, currently, GDB will assert.  Here's
an example session using current HEAD of master with GDB built for an
x86-64 GNU/Linux native target, the binary being used is a RISC-V ELF:

  $ ./gdb/gdb -q --data-directory ./gdb/data-directory/
  (gdb) file /tmp/hello.rv32imc.x
  Reading symbols from /tmp/hello.rv32imc.x...
  (gdb) start
  Temporary breakpoint 1 at 0x101b2: file hello.rv32.c, line 23.
  Starting program: /tmp/hello.rv32imc.x
  ../../src/gdb/gdbarch.h:166: internal-error: gdbarch_tdep: Assertion `dynamic_cast<TDepType *> (tdep) != nullptr' failed.
  A problem internal to GDB has been detected,
  further debugging may prove unreliable.

The same error is encountered if, instead of starting a new inferior,
the user tries to attach to an x86-64 process with a RISC-V binary set
as the current executable.

These errors are not specific to the x86-64/RISC-V pairing I'm using
here, any attempt to use a binary for one architecture with a native
target of a different architecture will result in a similar error.

Clearly, attempting to use this cross-architecture combination is a
user error, but I think GDB should do better than an assert; ideally a
nice error should be printed.

The problem we run into is that, when the user starts a new inferior,
or attaches to an inferior, the inferior stops.  At this point GDB
attempts to handle the stop, and this involves reading registers from
the inferior.

These register reads end up being done through the native target, so
in the example above, we end up in the amd64_supply_fxsave function.
However, these functions need a gdbarch.  The gdbarch is fetched from
the register set, which was constructed using the gdbarch from the
binary currently in use.  And so we end up in amd64_supply_fxsave
using a RISC-V gdbarch.

When we call:

  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);

this will assert as the gdbarch_tdep data within the RISC-V gdbarch is
of the type riscv_gdbarch_tdep not i386_gdbarch_tdep.

The solution I propose in this commit is to add a new target_ops
method supports_architecture_p.  This method will return true if a
target can safely be used with a specific architecture, otherwise, the
method returns false.

I imagine that a result of true from this method doesn't guarantee
that GDB can start an inferior of a given architecture, it just means
that GDB will not crash if such an attempt is made.  A result of false
is a hard stop; attempting to use this target with this architecture
is not supported, and may cause GDB to crash.

This distinction is important I think for things like remote targets,
and possibly simulator targets.  We might imagine that GDB can ask a
remote (or simulator) to start with a particular executable, and the
target might still refuse for some reason.  But my thinking is that
these refusals should be well handled (i.e. GDB should give a user
friendly error), rather than crashing, as is the case with the native
targets.

For example, if I start gdbserver on an x86-64 machine like this:

  gdbserver --multi :54321

Then make use of this from a GDB session like this:

  $ ./gdb/gdb -q --data-directory ./gdb/data-directory/
  (gdb) file /tmp/hello.rv32imc.x
  Reading symbols from /tmp/hello.rv32imc.x...
  (gdb) target extended-remote :54321
  Remote debugging using :54321
  (gdb) run
  Starting program: /tmp/hello.rv32imc.x
  Running the default executable on the remote target failed; try "set remote exec-file"?
  (gdb)

Though the error is not very helpful in diagnosing the problem, we can
see that GDB has not crashed, but has given the user an error.

And so, the supports_architecture_p method is created to return true
by default, then I override this in inf_child_target, where I compare
the architecture in question with the default_bfd_arch.

Finally, I've added calls to supports_architecture_p for the
run (which covers run, start, starti) and attach commands.

You will notice a lack of tests for this change.  I'm not sure of a
good way that I can build a binary for a different architecture as
part of a test, but if anyone has any ideas then I'll be happy to add
a test here.
---
 gdb/arch-utils.c       |  8 ++++++++
 gdb/arch-utils.h       |  5 +++++
 gdb/inf-child.c        | 19 +++++++++++++++++++
 gdb/inf-child.h        |  2 ++
 gdb/infcmd.c           |  8 ++++++++
 gdb/target-delegates.c | 28 ++++++++++++++++++++++++++++
 gdb/target.h           | 13 ++++++++++++-
 7 files changed, 82 insertions(+), 1 deletion(-)

diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index 360b8d694be..efba17e1d5d 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -1570,6 +1570,14 @@ target_gdbarch (void)
   return current_inferior ()->gdbarch;
 }
 
+/* See arch-utils.h.  */
+
+bool
+gdbarch_matches_default_arch (struct gdbarch *gdbarch)
+{
+  return gdbarch_bfd_arch_info (gdbarch)->arch == default_bfd_arch->arch;
+}
+
 void _initialize_gdbarch_utils ();
 void
 _initialize_gdbarch_utils ()
diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h
index f850e5fd6e7..5d61be36c26 100644
--- a/gdb/arch-utils.h
+++ b/gdb/arch-utils.h
@@ -300,4 +300,9 @@ extern void default_read_core_file_mappings
    struct bfd *cbfd,
    read_core_file_mappings_pre_loop_ftype pre_loop_cb,
    read_core_file_mappings_loop_ftype loop_cb);
+
+/* Return true if the bfd architecture of GDBARCH matches the default bfd
+   architecture.  */
+
+extern bool gdbarch_matches_default_arch (struct gdbarch *gdbarch);
 #endif /* ARCH_UTILS_H */
diff --git a/gdb/inf-child.c b/gdb/inf-child.c
index 56ebd2a5549..0c47a367c68 100644
--- a/gdb/inf-child.c
+++ b/gdb/inf-child.c
@@ -30,6 +30,8 @@
 #include "inferior.h"
 #include <sys/stat.h>
 #include "inf-child.h"
+#include "gdbarch.h"
+#include "arch-utils.h"
 #include "gdbsupport/fileio.h"
 #include "gdbsupport/agent.h"
 #include "gdbsupport/gdb_wait.h"
@@ -412,6 +414,23 @@ inf_child_target::follow_exec (inferior *follow_inf, ptid_t ptid,
     }
 }
 
+/* The inf_child_target represents the native target built into GDB, of
+   which there is only ever one.  If we attempt to start a native inferior
+   using a binary for an architecture not matching the native target then,
+   when we handle the first stop, we will end up trying to read registers
+   using the gdbarch functions from the native target, but passing in a
+   gdbarch object based on the architecture of the binary file.  This will
+   result in errors.
+
+   This check prevents this so long as everywhere user command that might
+   cause a new inferior to be created calls this function.  */
+
+bool
+inf_child_target::supports_architecture_p (struct gdbarch *gdbarch)
+{
+  return gdbarch_matches_default_arch (gdbarch);
+}
+
 /* See inf-child.h.  */
 
 void
diff --git a/gdb/inf-child.h b/gdb/inf-child.h
index ae5ace46f30..01a8164b0c2 100644
--- a/gdb/inf-child.h
+++ b/gdb/inf-child.h
@@ -92,6 +92,8 @@ class inf_child_target
 
   bool can_use_agent () override;
 
+  bool supports_architecture_p (struct gdbarch *gdbarch) override;
+
 protected:
   /* Unpush the target if it wasn't explicitly open with "target native"
      and there are no live inferiors left.  Note: if calling this as a
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index e909d4d4c81..b8acf858b3a 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -413,6 +413,10 @@ run_command_1 (const char *args, int from_tty, enum run_how run_how)
   if (non_stop && !run_target->supports_non_stop ())
     error (_("The target does not support running in non-stop mode."));
 
+  if (!run_target->supports_architecture_p (get_current_arch ()))
+    error (_("The target does not support architecture \"%s\"."),
+	   gdbarch_bfd_arch_info (get_current_arch ())->printable_name);
+
   /* Done.  Can now set breakpoints, change inferior args, etc.  */
 
   /* Insert temporary breakpoint in main function if requested.  */
@@ -2590,6 +2594,10 @@ attach_command (const char *args, int from_tty)
   if (non_stop && !attach_target->supports_non_stop ())
     error (_("Cannot attach to this target in non-stop mode"));
 
+  if (!attach_target->supports_architecture_p (get_current_arch ()))
+    error (_("The target does not support architecture \"%s\"."),
+	   gdbarch_bfd_arch_info (get_current_arch ())->printable_name);
+
   attach_target->attach (args, from_tty);
   /* to_attach should push the target, so after this point we
      shouldn't refer to attach_target again.  */
diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c
index 8a9986454dd..cb7bb1f2062 100644
--- a/gdb/target-delegates.c
+++ b/gdb/target-delegates.c
@@ -196,6 +196,7 @@ struct dummy_target : public target_ops
   bool supports_memory_tagging () override;
   bool fetch_memtags (CORE_ADDR arg0, size_t arg1, gdb::byte_vector &arg2, int arg3) override;
   bool store_memtags (CORE_ADDR arg0, size_t arg1, const gdb::byte_vector &arg2, int arg3) override;
+  bool supports_architecture_p (struct gdbarch *arg0) override;
 };
 
 struct debug_target : public target_ops
@@ -370,6 +371,7 @@ struct debug_target : public target_ops
   bool supports_memory_tagging () override;
   bool fetch_memtags (CORE_ADDR arg0, size_t arg1, gdb::byte_vector &arg2, int arg3) override;
   bool store_memtags (CORE_ADDR arg0, size_t arg1, const gdb::byte_vector &arg2, int arg3) override;
+  bool supports_architecture_p (struct gdbarch *arg0) override;
 };
 
 void
@@ -4536,3 +4538,29 @@ debug_target::store_memtags (CORE_ADDR arg0, size_t arg1, const gdb::byte_vector
   return result;
 }
 
+bool
+target_ops::supports_architecture_p (struct gdbarch *arg0)
+{
+  return this->beneath ()->supports_architecture_p (arg0);
+}
+
+bool
+dummy_target::supports_architecture_p (struct gdbarch *arg0)
+{
+  return true;
+}
+
+bool
+debug_target::supports_architecture_p (struct gdbarch *arg0)
+{
+  bool result;
+  gdb_printf (gdb_stdlog, "-> %s->supports_architecture_p (...)\n", this->beneath ()->shortname ());
+  result = this->beneath ()->supports_architecture_p (arg0);
+  gdb_printf (gdb_stdlog, "<- %s->supports_architecture_p (", this->beneath ()->shortname ());
+  target_debug_print_struct_gdbarch_p (arg0);
+  gdb_puts (") = ", gdb_stdlog);
+  target_debug_print_bool (result);
+  gdb_puts ("\n", gdb_stdlog);
+  return result;
+}
+
diff --git a/gdb/target.h b/gdb/target.h
index 18559feef89..5f3ae77f559 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -1320,7 +1320,18 @@ struct target_ops
     virtual bool store_memtags (CORE_ADDR address, size_t len,
 				const gdb::byte_vector &tags, int type)
       TARGET_DEFAULT_NORETURN (tcomplain ());
-  };
+
+    /* Return false if the target does not support GDBARCH, otherwise,
+       return true.
+
+       The default reply of true does not guarantee that debugging an
+       inferior with architecture GDBARCH will succeed, other errors might
+       be thrown later on, but a return value of false is a clear
+       indication that we should not proceed attempting to use this
+       architecture with this target.  */
+    virtual bool supports_architecture_p (struct gdbarch *gdbarch)
+      TARGET_DEFAULT_RETURN (true);
+};
 
 /* Deleter for std::unique_ptr.  See comments in
    target_ops::~target_ops and target_ops::close about heap-allocated
-- 
2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH 4/5] gdb: ensure the cast in gdbarch_tdep is valid
  2022-05-31 14:30 ` [PATCH 4/5] gdb: ensure the cast in gdbarch_tdep is valid Andrew Burgess
@ 2022-05-31 16:04   ` John Baldwin
  2022-05-31 17:22     ` Andrew Burgess
  0 siblings, 1 reply; 83+ messages in thread
From: John Baldwin @ 2022-05-31 16:04 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

On 5/31/22 7:30 AM, Andrew Burgess via Gdb-patches wrote:
> This commit builds on the previous commit and modifies the
> gdbarch_tdep function to ensure that the cast being performed is
> valid.
> 
> To do this I make use of dynamic_cast to ensure that the generic
> gdbarch_tdep pointer that we have is of the correct type.
> 
> The only problem with this approach is that, in order to use
> dynamic_cast, we need RTTI information, which requires the class to
> have a vtable, which currently, is not something the various tdep
> classes have.
> 
> And so, in this commit, I add a virtual destructor to the gdbarch_tdep
> class.
> 
> With this change I can now add an assert in the gdbarch_tdep function.
> 
> Obviously, this change comes at a cost, creation of the tdep classes
> is now slightly more expensive (due to vtable initialisation),
> however, this only happens when a new gdbarch is created, which is not
> that frequent, so I don't see that as a huge concern.
> 
> Then, there is an increased cost each time the tdep is accessed.  This
> is much more frequent, but I don't believe the cost is excessive (a
> vtable pointer comparison), at least, no worse than many of our other
> asserts.
> 
> If we consider the motivating example that was discussed in the
> previous commit; build GDB for all targets on an x86-64 GNU/Linux
> system, and then attempt to "run" a RISC-V binary using the native
> x86-64 Linux target.  Previously this would trigger an assert while
> accessing fields within a i386_gdbarch_tdep, like this:
> 
>    ../../src/gdb/i387-tdep.c:596: internal-error: i387_supply_fxsave: Assertion `tdep->st0_regnum >= I386_ST0_REGNUM' failed.
> 
> But with the changes from this commit in place, we now see an
> assertion failure like this:
> 
>    ../../src/gdb/gdbarch.h:166: internal-error: gdbarch_tdep: Assertion `dynamic_cast<TDepType *> (tdep) != nullptr' failed.
> 
> On the face of it, this might not seem like much of an improvement,
> but I think it is.
> 
> The previous assert was triggered by undefined behaviour.  There's no
> guarantee that we would see an assertion at all, a different
> combination of native target and binary format might not trigger an
> assert (and just do the wrong thing), or might crash GDB completely.
> 
> In contrast, the new assert is based on defined behaviour, we'll
> always assert if GDB goes wrong, and we assert early, at the point the
> mistake is being made (casting the result of gdbarch_tdep to the wrong
> type), rather than at some later point after the incorrect cast has
> completed.
> 
> Obviously, when we consider the original example, trying to run a
> binary of the wrong architecture on a native target, having GDB fail
> with an assertion is not a real solution.  No user action should be
> able to trigger an assertion failure.  In a later commit I will offer
> a real solution to this architecture mismatch problem.
> ---
>   gdb/gdbarch.h | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
> index b2c91db0c4f..ea507d70ec9 100644
> --- a/gdb/gdbarch.h
> +++ b/gdb/gdbarch.h
> @@ -58,7 +58,13 @@ struct inferior;
>   
>   #include "regcache.h"
>   
> -struct gdbarch_tdep {};
> +/* The base class for every architecture's tdep sub-class.  We include a
> +   virtual destructor so that sub-classes will have RTTI information.  */
> +
> +struct gdbarch_tdep
> +{
> +  virtual ~gdbarch_tdep() = default;
> +};
>   
>   /* The architecture associated with the inferior through the
>      connection to the target.
> @@ -157,6 +163,7 @@ static inline TDepType *
>   gdbarch_tdep (struct gdbarch *gdbarch)
>   {
>     struct gdbarch_tdep *tdep = gdbarch_tdep_1 (gdbarch);
> +  gdb_assert (dynamic_cast<TDepType *> (tdep) != nullptr);
>     return static_cast<TDepType *> (tdep);
>   }

Maybe simplify to use dynamic_cast for the returned value, e.g.

{
   TDepType *tdep = dynamic_cast<TDepType *> (gdbarch_tdep_1 (gdbarch));
   gdb_assert(tdep != nullptr);
   return (tdep);
}

-- 
John Baldwin

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH 5/5] gdb: native target invalid architecture detection
  2022-05-31 14:30 ` [PATCH 5/5] gdb: native target invalid architecture detection Andrew Burgess
@ 2022-05-31 16:08   ` John Baldwin
  2022-05-31 16:51     ` Andrew Burgess
  0 siblings, 1 reply; 83+ messages in thread
From: John Baldwin @ 2022-05-31 16:08 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

On 5/31/22 7:30 AM, Andrew Burgess via Gdb-patches wrote:
> If GDB is asked to start a new inferior, or attach to an existing
> process, using a binary file for an architecture that does not match
> the current native target, then, currently, GDB will assert.  Here's
> an example session using current HEAD of master with GDB built for an
> x86-64 GNU/Linux native target, the binary being used is a RISC-V ELF:
> 
>    $ ./gdb/gdb -q --data-directory ./gdb/data-directory/
>    (gdb) file /tmp/hello.rv32imc.x
>    Reading symbols from /tmp/hello.rv32imc.x...
>    (gdb) start
>    Temporary breakpoint 1 at 0x101b2: file hello.rv32.c, line 23.
>    Starting program: /tmp/hello.rv32imc.x
>    ../../src/gdb/gdbarch.h:166: internal-error: gdbarch_tdep: Assertion `dynamic_cast<TDepType *> (tdep) != nullptr' failed.
>    A problem internal to GDB has been detected,
>    further debugging may prove unreliable.
> 
> The same error is encountered if, instead of starting a new inferior,
> the user tries to attach to an x86-64 process with a RISC-V binary set
> as the current executable.
> 
> These errors are not specific to the x86-64/RISC-V pairing I'm using
> here, any attempt to use a binary for one architecture with a native
> target of a different architecture will result in a similar error.
> 
> Clearly, attempting to use this cross-architecture combination is a
> user error, but I think GDB should do better than an assert; ideally a
> nice error should be printed.
> 
> The problem we run into is that, when the user starts a new inferior,
> or attaches to an inferior, the inferior stops.  At this point GDB
> attempts to handle the stop, and this involves reading registers from
> the inferior.
> 
> These register reads end up being done through the native target, so
> in the example above, we end up in the amd64_supply_fxsave function.
> However, these functions need a gdbarch.  The gdbarch is fetched from
> the register set, which was constructed using the gdbarch from the
> binary currently in use.  And so we end up in amd64_supply_fxsave
> using a RISC-V gdbarch.
> 
> When we call:
> 
>    i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
> 
> this will assert as the gdbarch_tdep data within the RISC-V gdbarch is
> of the type riscv_gdbarch_tdep not i386_gdbarch_tdep.
> 
> The solution I propose in this commit is to add a new target_ops
> method supports_architecture_p.  This method will return true if a
> target can safely be used with a specific architecture, otherwise, the
> method returns false.
> 
> I imagine that a result of true from this method doesn't guarantee
> that GDB can start an inferior of a given architecture, it just means
> that GDB will not crash if such an attempt is made.  A result of false
> is a hard stop; attempting to use this target with this architecture
> is not supported, and may cause GDB to crash.
> 
> This distinction is important I think for things like remote targets,
> and possibly simulator targets.  We might imagine that GDB can ask a
> remote (or simulator) to start with a particular executable, and the
> target might still refuse for some reason.  But my thinking is that
> these refusals should be well handled (i.e. GDB should give a user
> friendly error), rather than crashing, as is the case with the native
> targets.
> 
> For example, if I start gdbserver on an x86-64 machine like this:
> 
>    gdbserver --multi :54321
> 
> Then make use of this from a GDB session like this:
> 
>    $ ./gdb/gdb -q --data-directory ./gdb/data-directory/
>    (gdb) file /tmp/hello.rv32imc.x
>    Reading symbols from /tmp/hello.rv32imc.x...
>    (gdb) target extended-remote :54321
>    Remote debugging using :54321
>    (gdb) run
>    Starting program: /tmp/hello.rv32imc.x
>    Running the default executable on the remote target failed; try "set remote exec-file"?
>    (gdb)
> 
> Though the error is not very helpful in diagnosing the problem, we can
> see that GDB has not crashed, but has given the user an error.
> 
> And so, the supports_architecture_p method is created to return true
> by default, then I override this in inf_child_target, where I compare
> the architecture in question with the default_bfd_arch.
> 
> Finally, I've added calls to supports_architecture_p for the
> run (which covers run, start, starti) and attach commands.
> 
> You will notice a lack of tests for this change.  I'm not sure of a
> good way that I can build a binary for a different architecture as
> part of a test, but if anyone has any ideas then I'll be happy to add
> a test here.

Have you considered multi-arch cases such as running i386 binaries on an x86-64
host or 32-bit arm binaries on an AArch64 host?  Will we need to override this
method in certain targets (e.g. x86-linux-nat.c or x86-fbsd-nat.c) to support
such cases?

-- 
John Baldwin

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH 5/5] gdb: native target invalid architecture detection
  2022-05-31 16:08   ` John Baldwin
@ 2022-05-31 16:51     ` Andrew Burgess
  2022-06-01  8:25       ` Luis Machado
  0 siblings, 1 reply; 83+ messages in thread
From: Andrew Burgess @ 2022-05-31 16:51 UTC (permalink / raw)
  To: John Baldwin, gdb-patches

John Baldwin <jhb@FreeBSD.org> writes:

> On 5/31/22 7:30 AM, Andrew Burgess via Gdb-patches wrote:
>> If GDB is asked to start a new inferior, or attach to an existing
>> process, using a binary file for an architecture that does not match
>> the current native target, then, currently, GDB will assert.  Here's
>> an example session using current HEAD of master with GDB built for an
>> x86-64 GNU/Linux native target, the binary being used is a RISC-V ELF:
>> 
>>    $ ./gdb/gdb -q --data-directory ./gdb/data-directory/
>>    (gdb) file /tmp/hello.rv32imc.x
>>    Reading symbols from /tmp/hello.rv32imc.x...
>>    (gdb) start
>>    Temporary breakpoint 1 at 0x101b2: file hello.rv32.c, line 23.
>>    Starting program: /tmp/hello.rv32imc.x
>>    ../../src/gdb/gdbarch.h:166: internal-error: gdbarch_tdep: Assertion `dynamic_cast<TDepType *> (tdep) != nullptr' failed.
>>    A problem internal to GDB has been detected,
>>    further debugging may prove unreliable.
>> 
>> The same error is encountered if, instead of starting a new inferior,
>> the user tries to attach to an x86-64 process with a RISC-V binary set
>> as the current executable.
>> 
>> These errors are not specific to the x86-64/RISC-V pairing I'm using
>> here, any attempt to use a binary for one architecture with a native
>> target of a different architecture will result in a similar error.
>> 
>> Clearly, attempting to use this cross-architecture combination is a
>> user error, but I think GDB should do better than an assert; ideally a
>> nice error should be printed.
>> 
>> The problem we run into is that, when the user starts a new inferior,
>> or attaches to an inferior, the inferior stops.  At this point GDB
>> attempts to handle the stop, and this involves reading registers from
>> the inferior.
>> 
>> These register reads end up being done through the native target, so
>> in the example above, we end up in the amd64_supply_fxsave function.
>> However, these functions need a gdbarch.  The gdbarch is fetched from
>> the register set, which was constructed using the gdbarch from the
>> binary currently in use.  And so we end up in amd64_supply_fxsave
>> using a RISC-V gdbarch.
>> 
>> When we call:
>> 
>>    i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>> 
>> this will assert as the gdbarch_tdep data within the RISC-V gdbarch is
>> of the type riscv_gdbarch_tdep not i386_gdbarch_tdep.
>> 
>> The solution I propose in this commit is to add a new target_ops
>> method supports_architecture_p.  This method will return true if a
>> target can safely be used with a specific architecture, otherwise, the
>> method returns false.
>> 
>> I imagine that a result of true from this method doesn't guarantee
>> that GDB can start an inferior of a given architecture, it just means
>> that GDB will not crash if such an attempt is made.  A result of false
>> is a hard stop; attempting to use this target with this architecture
>> is not supported, and may cause GDB to crash.
>> 
>> This distinction is important I think for things like remote targets,
>> and possibly simulator targets.  We might imagine that GDB can ask a
>> remote (or simulator) to start with a particular executable, and the
>> target might still refuse for some reason.  But my thinking is that
>> these refusals should be well handled (i.e. GDB should give a user
>> friendly error), rather than crashing, as is the case with the native
>> targets.
>> 
>> For example, if I start gdbserver on an x86-64 machine like this:
>> 
>>    gdbserver --multi :54321
>> 
>> Then make use of this from a GDB session like this:
>> 
>>    $ ./gdb/gdb -q --data-directory ./gdb/data-directory/
>>    (gdb) file /tmp/hello.rv32imc.x
>>    Reading symbols from /tmp/hello.rv32imc.x...
>>    (gdb) target extended-remote :54321
>>    Remote debugging using :54321
>>    (gdb) run
>>    Starting program: /tmp/hello.rv32imc.x
>>    Running the default executable on the remote target failed; try "set remote exec-file"?
>>    (gdb)
>> 
>> Though the error is not very helpful in diagnosing the problem, we can
>> see that GDB has not crashed, but has given the user an error.
>> 
>> And so, the supports_architecture_p method is created to return true
>> by default, then I override this in inf_child_target, where I compare
>> the architecture in question with the default_bfd_arch.
>> 
>> Finally, I've added calls to supports_architecture_p for the
>> run (which covers run, start, starti) and attach commands.
>> 
>> You will notice a lack of tests for this change.  I'm not sure of a
>> good way that I can build a binary for a different architecture as
>> part of a test, but if anyone has any ideas then I'll be happy to add
>> a test here.
>
> Have you considered multi-arch cases such as running i386 binaries on an x86-64
> host or 32-bit arm binaries on an AArch64 host?  Will we need to override this
> method in certain targets (e.g. x86-linux-nat.c or x86-fbsd-nat.c) to support
> such cases?

For the x86 examples you gave, I think these all have the bfd_arch_i386
bfd architecture, so should work just fine.

But for the aarch64 case, I admit I don't know how this works.  A 32-bit
ARM binary is going to have bfd_arch_arm, while the AArch64 target will
be expecting a gdbarch with bfd_arch_aarch64.  But how GDB supports
running the former on the latter, I don't know.

I notice there's aarch64-linux-nat.c and aarch32-linux-nat.c, I wonder
if this has something to do with it...

Maybe someone with more ARM/AArch64 knowledge will chip in to fill in
some of the blanks.

But to answer the general question, if there is a case that the existing
code doesn't handle, then we can for sure override the new method in
specific *-nat.c targets in order to handle weird cases.

Thanks,
Andrew


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH 4/5] gdb: ensure the cast in gdbarch_tdep is valid
  2022-05-31 16:04   ` John Baldwin
@ 2022-05-31 17:22     ` Andrew Burgess
  0 siblings, 0 replies; 83+ messages in thread
From: Andrew Burgess @ 2022-05-31 17:22 UTC (permalink / raw)
  To: John Baldwin, gdb-patches

John Baldwin <jhb@FreeBSD.org> writes:

> On 5/31/22 7:30 AM, Andrew Burgess via Gdb-patches wrote:
>> This commit builds on the previous commit and modifies the
>> gdbarch_tdep function to ensure that the cast being performed is
>> valid.
>> 
>> To do this I make use of dynamic_cast to ensure that the generic
>> gdbarch_tdep pointer that we have is of the correct type.
>> 
>> The only problem with this approach is that, in order to use
>> dynamic_cast, we need RTTI information, which requires the class to
>> have a vtable, which currently, is not something the various tdep
>> classes have.
>> 
>> And so, in this commit, I add a virtual destructor to the gdbarch_tdep
>> class.
>> 
>> With this change I can now add an assert in the gdbarch_tdep function.
>> 
>> Obviously, this change comes at a cost, creation of the tdep classes
>> is now slightly more expensive (due to vtable initialisation),
>> however, this only happens when a new gdbarch is created, which is not
>> that frequent, so I don't see that as a huge concern.
>> 
>> Then, there is an increased cost each time the tdep is accessed.  This
>> is much more frequent, but I don't believe the cost is excessive (a
>> vtable pointer comparison), at least, no worse than many of our other
>> asserts.
>> 
>> If we consider the motivating example that was discussed in the
>> previous commit; build GDB for all targets on an x86-64 GNU/Linux
>> system, and then attempt to "run" a RISC-V binary using the native
>> x86-64 Linux target.  Previously this would trigger an assert while
>> accessing fields within a i386_gdbarch_tdep, like this:
>> 
>>    ../../src/gdb/i387-tdep.c:596: internal-error: i387_supply_fxsave: Assertion `tdep->st0_regnum >= I386_ST0_REGNUM' failed.
>> 
>> But with the changes from this commit in place, we now see an
>> assertion failure like this:
>> 
>>    ../../src/gdb/gdbarch.h:166: internal-error: gdbarch_tdep: Assertion `dynamic_cast<TDepType *> (tdep) != nullptr' failed.
>> 
>> On the face of it, this might not seem like much of an improvement,
>> but I think it is.
>> 
>> The previous assert was triggered by undefined behaviour.  There's no
>> guarantee that we would see an assertion at all, a different
>> combination of native target and binary format might not trigger an
>> assert (and just do the wrong thing), or might crash GDB completely.
>> 
>> In contrast, the new assert is based on defined behaviour, we'll
>> always assert if GDB goes wrong, and we assert early, at the point the
>> mistake is being made (casting the result of gdbarch_tdep to the wrong
>> type), rather than at some later point after the incorrect cast has
>> completed.
>> 
>> Obviously, when we consider the original example, trying to run a
>> binary of the wrong architecture on a native target, having GDB fail
>> with an assertion is not a real solution.  No user action should be
>> able to trigger an assertion failure.  In a later commit I will offer
>> a real solution to this architecture mismatch problem.
>> ---
>>   gdb/gdbarch.h | 9 ++++++++-
>>   1 file changed, 8 insertions(+), 1 deletion(-)
>> 
>> diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
>> index b2c91db0c4f..ea507d70ec9 100644
>> --- a/gdb/gdbarch.h
>> +++ b/gdb/gdbarch.h
>> @@ -58,7 +58,13 @@ struct inferior;
>>   
>>   #include "regcache.h"
>>   
>> -struct gdbarch_tdep {};
>> +/* The base class for every architecture's tdep sub-class.  We include a
>> +   virtual destructor so that sub-classes will have RTTI information.  */
>> +
>> +struct gdbarch_tdep
>> +{
>> +  virtual ~gdbarch_tdep() = default;
>> +};
>>   
>>   /* The architecture associated with the inferior through the
>>      connection to the target.
>> @@ -157,6 +163,7 @@ static inline TDepType *
>>   gdbarch_tdep (struct gdbarch *gdbarch)
>>   {
>>     struct gdbarch_tdep *tdep = gdbarch_tdep_1 (gdbarch);
>> +  gdb_assert (dynamic_cast<TDepType *> (tdep) != nullptr);
>>     return static_cast<TDepType *> (tdep);
>>   }
>
> Maybe simplify to use dynamic_cast for the returned value, e.g.
>
> {
>    TDepType *tdep = dynamic_cast<TDepType *> (gdbarch_tdep_1 (gdbarch));
>    gdb_assert(tdep != nullptr);
>    return (tdep);

I didn't do that originally so as to keep the "slower" code enclosed
within the assert.  If in some future world we added a mode in which we
could compile out the assert, then the slower dynamic cast would be
skipped.

But we don't currently support compiling out asserts, so this was
probably premature optimisation.

I'll update the code as you suggest.

Thanks,
Andrew


> }
>
> -- 
> John Baldwin


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH 1/5] gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope
  2022-05-31 14:30 ` [PATCH 1/5] gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope Andrew Burgess
@ 2022-06-01  7:58   ` Luis Machado
  0 siblings, 0 replies; 83+ messages in thread
From: Luis Machado @ 2022-06-01  7:58 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

On 5/31/22 15:30, Andrew Burgess via Gdb-patches wrote:
> This is a small refactor to resolve an issue before it becomes a
> problem in a later commit.
> 
> Move the fetching of an arm_gdbarch_tdep into a more inner scope
> within two functions in arm-tdep.c.
> 
> The problem with the current code is that the functions in question
> are used as the callbacks for two set/show parameters.  These set/show
> parameters are available no matter the current architecture, but are
> really about controlling an ARM architecture specific setting.  And
> so, if I build GDB for all targets on an x86-64/GNU-Linux system, I
> can still do this:
> 
>    (gdb) show arm fpu
>    (gdb) show arm abi
> 
> After these calls we end up in show_fp_model and arm_show_abi
> respectively, where we unconditionally do this:
> 
>    arm_gdbarch_tdep *tdep
>      = (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
> 
> However, the gdbarch_tdep() result will only be a arm_gdbarch_tdep if
> the current architecture is ARM, otherwise the result will actually be
> of some other type.
> 
> This isn't actually a problem, as in both cases the use of tdep is
> guarded by a later check that the gdbarch architecture is
> bfd_arch_arm.
> 
> This commit just moves the call to gdbarch_tdep() after the
> architecture check.
> 
> In a later commit gdbarch_tdep() will be able to spot when we are
> casting the result to the wrong type, and this function will trigger
> assertion failures if things are not fixed.
> 
> There should be not user visible changes after this commit.
> ---
>   gdb/arm-tdep.c | 24 ++++++++++++++----------
>   1 file changed, 14 insertions(+), 10 deletions(-)
> 
> diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
> index 49664093f00..d39342e19c6 100644
> --- a/gdb/arm-tdep.c
> +++ b/gdb/arm-tdep.c
> @@ -9015,14 +9015,16 @@ static void
>   show_fp_model (struct ui_file *file, int from_tty,
>   	       struct cmd_list_element *c, const char *value)
>   {
> -  arm_gdbarch_tdep *tdep
> -    = (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
> -
>     if (arm_fp_model == ARM_FLOAT_AUTO
>         && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm)
> -    gdb_printf (file, _("\
> +    {
> +      arm_gdbarch_tdep *tdep
> +	= (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
> +
> +      gdb_printf (file, _("\
>   The current ARM floating point model is \"auto\" (currently \"%s\").\n"),
> -		fp_model_strings[tdep->fp_model]);
> +		  fp_model_strings[tdep->fp_model]);
> +    }
>     else
>       gdb_printf (file, _("\
>   The current ARM floating point model is \"%s\".\n"),
> @@ -9053,14 +9055,16 @@ static void
>   arm_show_abi (struct ui_file *file, int from_tty,
>   	     struct cmd_list_element *c, const char *value)
>   {
> -  arm_gdbarch_tdep *tdep
> -    = (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
> -
>     if (arm_abi_global == ARM_ABI_AUTO
>         && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm)
> -    gdb_printf (file, _("\
> +    {
> +      arm_gdbarch_tdep *tdep
> +	= (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
> +
> +      gdb_printf (file, _("\
>   The current ARM ABI is \"auto\" (currently \"%s\").\n"),
> -		arm_abi_strings[tdep->arm_abi]);
> +		  arm_abi_strings[tdep->arm_abi]);
> +    }
>     else
>       gdb_printf (file, _("The current ARM ABI is \"%s\".\n"),
>   		arm_abi_string);

LGTM

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH 3/5] gdb: move the type cast into gdbarch_tdep
  2022-05-31 14:30 ` [PATCH 3/5] gdb: move the type cast into gdbarch_tdep Andrew Burgess
@ 2022-06-01  8:01   ` Luis Machado
  0 siblings, 0 replies; 83+ messages in thread
From: Luis Machado @ 2022-06-01  8:01 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

On 5/31/22 15:30, Andrew Burgess via Gdb-patches wrote:
> I built GDB for all targets on a x86-64/GNU-Linux system, and
> then (accidentally) passed GDB a RISC-V binary, and asked GDB to "run"
> the binary on the native target.  I got this error:
> 
>    (gdb) show architecture
>    The target architecture is set to "auto" (currently "i386").
>    (gdb) file /tmp/hello.rv32.exe
>    Reading symbols from /tmp/hello.rv32.exe...
>    (gdb) show architecture
>    The target architecture is set to "auto" (currently "riscv:rv32").
>    (gdb) run
>    Starting program: /tmp/hello.rv32.exe
>    ../../src/gdb/i387-tdep.c:596: internal-error: i387_supply_fxsave: Assertion `tdep->st0_regnum >= I386_ST0_REGNUM' failed.
> 
> What's going on here is this; initially the architecture is i386, this
> is based on the default architecture, which is set based on the native
> target.  After loading the RISC-V executable the architecture of the
> current inferior is updated based on the architecture of the
> executable.
> 
> When we "run", GDB does a fork & exec, with the inferior being
> controlled through ptrace.  GDB sees an initial stop from the inferior
> as soon as the inferior comes to life.  In response to this stop GDB
> ends up calling save_stop_reason (linux-nat.c), which ends up trying
> to read register from the inferior, to do this we end up calling
> target_ops::fetch_registers, which, for the x86-64 native target,
> calls amd64_linux_nat_target::fetch_registers.
> 
> After this I eventually end up in i387_supply_fxsave, different x86
> based targets will end in different functions to fetch registers, but
> it doesn't really matter which function we end up in, the problem is
> this line, which is repeated in many places:
> 
>    i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
> 
> The problem here is that the ARCH in this line comes from the current
> inferior, which, as we discussed above, will be a RISC-V gdbarch, the
> tdep field will actually be of type riscv_gdbarch_tdep, not
> i386_gdbarch_tdep.  After this cast we are relying on undefined
> behaviour, in my case I happen to trigger an assert, but this might
> not always be the case.
> 
> The thing I tried that exposed this problem was of course, trying to
> start an executable of the wrong architecture on a native target.  I
> don't think that the correct solution for this problem is to detect,
> at the point of cast, that the gdbarch_tdep object is of the wrong
> type, but, I did wonder, is there a way that we could protect
> ourselves from incorrectly casting the gdbarch_tdep object?
> 
> I think that there is something we can do here, and this commit is the
> first step in that direction, though no actual check is added by this
> commit.
> 
> This commit can be split into two parts:
> 
>   (1) In gdbarch.h and arch-utils.c.  In these files I have modified
>   gdbarch_tdep (the function) so that it now takes a template argument,
>   like this:
> 
>      template<typename TDepType>
>      static inline TDepType *
>      gdbarch_tdep (struct gdbarch *gdbarch)
>      {
>        struct gdbarch_tdep *tdep = gdbarch_tdep_1 (gdbarch);
>        return static_cast<TDepType *> (tdep);
>      }
> 
>    After this change we are no better protected, but the cast is now
>    done within the gdbarch_tdep function rather than at the call sites,
>    this leads to the second, much larger change in this commit,
> 
>    (2) Everywhere gdbarch_tdep is called, we make changes like this:
> 
>      -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
>      +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
> 
> There should be no functional change after this commit.
> 
> In the next commit I will build on this change to add an assertion in
> gdbarch_tdep that checks we are casting to the correct type.
> ---
>   gdb/aarch64-fbsd-nat.c     |   4 +-
>   gdb/aarch64-fbsd-tdep.c    |   6 +-
>   gdb/aarch64-linux-nat.c    |  16 ++---
>   gdb/aarch64-linux-tdep.c   |  10 +--
>   gdb/aarch64-newlib-tdep.c  |   2 +-
>   gdb/aarch64-tdep.c         |  48 +++++++-------
>   gdb/aix-thread.c           |  28 ++++----
>   gdb/alpha-linux-tdep.c     |   2 +-
>   gdb/alpha-netbsd-tdep.c    |   2 +-
>   gdb/alpha-obsd-tdep.c      |   2 +-
>   gdb/alpha-tdep.c           |  14 ++--
>   gdb/amd64-darwin-tdep.c    |   2 +-
>   gdb/amd64-fbsd-nat.c       |   4 +-
>   gdb/amd64-fbsd-tdep.c      |   4 +-
>   gdb/amd64-linux-tdep.c     |   8 +--
>   gdb/amd64-netbsd-tdep.c    |   2 +-
>   gdb/amd64-obsd-tdep.c      |   2 +-
>   gdb/amd64-sol2-tdep.c      |   2 +-
>   gdb/amd64-tdep.c           |  34 +++++-----
>   gdb/amd64-windows-tdep.c   |   2 +-
>   gdb/arc-linux-tdep.c       |   4 +-
>   gdb/arc-newlib-tdep.c      |   2 +-
>   gdb/arc-tdep.c             |   8 +--
>   gdb/arch-utils.c           |   6 +-
>   gdb/arm-fbsd-nat.c         |   4 +-
>   gdb/arm-fbsd-tdep.c        |   6 +-
>   gdb/arm-linux-nat.c        |   8 +--
>   gdb/arm-linux-tdep.c       |   4 +-
>   gdb/arm-netbsd-nat.c       |   8 +--
>   gdb/arm-netbsd-tdep.c      |   4 +-
>   gdb/arm-none-tdep.c        |   2 +-
>   gdb/arm-obsd-tdep.c        |   2 +-
>   gdb/arm-tdep.c             | 110 +++++++++++++++----------------
>   gdb/arm-wince-tdep.c       |   2 +-
>   gdb/avr-tdep.c             |  12 ++--
>   gdb/bfin-tdep.c            |   4 +-
>   gdb/cris-linux-tdep.c      |   2 +-
>   gdb/cris-tdep.c            |  18 ++---
>   gdb/frv-tdep.c             |   4 +-
>   gdb/ft32-tdep.c            |   2 +-
>   gdb/gdbarch.h              |  17 ++++-
>   gdb/hppa-bsd-tdep.c        |   2 +-
>   gdb/hppa-linux-tdep.c      |   4 +-
>   gdb/hppa-tdep.c            |  12 ++--
>   gdb/i386-bsd-tdep.c        |   2 +-
>   gdb/i386-darwin-tdep.c     |   4 +-
>   gdb/i386-fbsd-tdep.c       |   4 +-
>   gdb/i386-gnu-tdep.c        |   2 +-
>   gdb/i386-go32-tdep.c       |   2 +-
>   gdb/i386-linux-tdep.c      |   4 +-
>   gdb/i386-netbsd-tdep.c     |   4 +-
>   gdb/i386-nto-tdep.c        |   6 +-
>   gdb/i386-obsd-tdep.c       |   2 +-
>   gdb/i386-sol2-tdep.c       |   2 +-
>   gdb/i386-tdep.c            |  98 +++++++++++++--------------
>   gdb/i386-windows-tdep.c    |   2 +-
>   gdb/i387-tdep.c            |  20 +++---
>   gdb/ia64-linux-tdep.c      |   2 +-
>   gdb/ia64-tdep.c            |  12 ++--
>   gdb/loongarch-linux-nat.c  |   6 +-
>   gdb/loongarch-linux-tdep.c |   8 +--
>   gdb/loongarch-tdep.c       |  10 +--
>   gdb/m32c-tdep.c            |  58 ++++++++--------
>   gdb/m68hc11-tdep.c         |  12 ++--
>   gdb/m68k-bsd-tdep.c        |   2 +-
>   gdb/m68k-linux-tdep.c      |   2 +-
>   gdb/m68k-tdep.c            |  38 +++++------
>   gdb/mep-tdep.c             |   6 +-
>   gdb/mips-linux-tdep.c      |   4 +-
>   gdb/mips-tdep.c            |  50 +++++++-------
>   gdb/mn10300-tdep.c         |   2 +-
>   gdb/mn10300-tdep.h         |   2 +-
>   gdb/msp430-tdep.c          |  12 ++--
>   gdb/nds32-tdep.c           |  20 +++---
>   gdb/nios2-linux-tdep.c     |   2 +-
>   gdb/nios2-tdep.c           |   4 +-
>   gdb/or1k-tdep.c            |   8 +--
>   gdb/ppc-fbsd-nat.c         |   4 +-
>   gdb/ppc-fbsd-tdep.c        |   8 +--
>   gdb/ppc-linux-nat.c        |  22 +++----
>   gdb/ppc-linux-tdep.c       |  18 ++---
>   gdb/ppc-netbsd-nat.c       |   6 +-
>   gdb/ppc-netbsd-tdep.c      |   2 +-
>   gdb/ppc-obsd-nat.c         |   4 +-
>   gdb/ppc-obsd-tdep.c        |   2 +-
>   gdb/ppc-sysv-tdep.c        |  22 +++----
>   gdb/ppc64-tdep.c           |   2 +-
>   gdb/riscv-linux-tdep.c     |   2 +-
>   gdb/riscv-tdep.c           |  26 ++++----
>   gdb/rl78-tdep.c            |   8 +--
>   gdb/rs6000-aix-nat.c       |   6 +-
>   gdb/rs6000-aix-tdep.c      |  16 ++---
>   gdb/rs6000-lynx178-tdep.c  |   4 +-
>   gdb/rs6000-tdep.c          | 132 ++++++++++++++++++-------------------
>   gdb/rx-tdep.c              |   2 +-
>   gdb/s390-linux-tdep.c      |  20 +++---
>   gdb/s390-tdep.c            |  42 ++++++------
>   gdb/sh-linux-tdep.c        |   2 +-
>   gdb/sh-netbsd-tdep.c       |   2 +-
>   gdb/sh-tdep.c              |   8 +--
>   gdb/sparc-linux-tdep.c     |   4 +-
>   gdb/sparc-netbsd-tdep.c    |   2 +-
>   gdb/sparc-sol2-tdep.c      |   2 +-
>   gdb/sparc-tdep.c           |  14 ++--
>   gdb/sparc64-fbsd-tdep.c    |   2 +-
>   gdb/sparc64-linux-tdep.c   |   4 +-
>   gdb/sparc64-netbsd-tdep.c  |   2 +-
>   gdb/sparc64-obsd-tdep.c    |   2 +-
>   gdb/sparc64-sol2-tdep.c    |   2 +-
>   gdb/sparc64-tdep.c         |  10 +--
>   gdb/tic6x-linux-tdep.c     |   6 +-
>   gdb/tic6x-tdep.c           |   6 +-
>   gdb/v850-tdep.c            |   6 +-
>   gdb/windows-nat.c          |   2 +-
>   gdb/xtensa-linux-nat.c     |   4 +-
>   gdb/xtensa-linux-tdep.c    |   2 +-
>   gdb/xtensa-tdep.c          |  54 +++++++--------
>   gdb/z80-tdep.c             |   8 +--
>   118 files changed, 681 insertions(+), 664 deletions(-)
> 
> diff --git a/gdb/aarch64-fbsd-nat.c b/gdb/aarch64-fbsd-nat.c
> index d8cf6227e73..708ddc40d58 100644
> --- a/gdb/aarch64-fbsd-nat.c
> +++ b/gdb/aarch64-fbsd-nat.c
> @@ -90,7 +90,7 @@ aarch64_fbsd_nat_target::fetch_registers (struct regcache *regcache,
>   				    &aarch64_fbsd_fpregset);
>   
>     gdbarch *gdbarch = regcache->arch ();
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>     if (tdep->has_tls ())
>       {
>         const struct regcache_map_entry aarch64_fbsd_tls_regmap[] =
> @@ -123,7 +123,7 @@ aarch64_fbsd_nat_target::store_registers (struct regcache *regcache,
>   				    PT_SETFPREGS, &aarch64_fbsd_fpregset);
>   
>     gdbarch *gdbarch = regcache->arch ();
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>     if (tdep->has_tls ())
>       {
>         const struct regcache_map_entry aarch64_fbsd_tls_regmap[] =
> diff --git a/gdb/aarch64-fbsd-tdep.c b/gdb/aarch64-fbsd-tdep.c
> index 891546b3c64..4a6b4115234 100644
> --- a/gdb/aarch64-fbsd-tdep.c
> +++ b/gdb/aarch64-fbsd-tdep.c
> @@ -143,7 +143,7 @@ aarch64_fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   					   void *cb_data,
>   					   const struct regcache *regcache)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     cb (".reg", AARCH64_FBSD_SIZEOF_GREGSET, AARCH64_FBSD_SIZEOF_GREGSET,
>         &aarch64_fbsd_gregset, NULL, cb_data);
> @@ -190,7 +190,7 @@ static CORE_ADDR
>   aarch64_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
>   				       CORE_ADDR lm_addr, CORE_ADDR offset)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>     struct regcache *regcache;
>   
>     regcache = get_thread_arch_regcache (current_inferior ()->process_target (),
> @@ -213,7 +213,7 @@ aarch64_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
>   static void
>   aarch64_fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     /* Generic FreeBSD support.  */
>     fbsd_init_abi (info, gdbarch);
> diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c
> index 9cde72b247b..77b1f5525e1 100644
> --- a/gdb/aarch64-linux-nat.c
> +++ b/gdb/aarch64-linux-nat.c
> @@ -358,7 +358,7 @@ static void
>   fetch_pauth_masks_from_thread (struct regcache *regcache)
>   {
>     aarch64_gdbarch_tdep *tdep
> -    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
>     int ret;
>     struct iovec iovec;
>     uint64_t pauth_regset[2] = {0, 0};
> @@ -384,7 +384,7 @@ static void
>   fetch_mteregs_from_thread (struct regcache *regcache)
>   {
>     aarch64_gdbarch_tdep *tdep
> -    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
>     int regno = tdep->mte_reg_base;
>   
>     gdb_assert (regno != -1);
> @@ -409,7 +409,7 @@ static void
>   store_mteregs_to_thread (struct regcache *regcache)
>   {
>     aarch64_gdbarch_tdep *tdep
> -    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
>     int regno = tdep->mte_reg_base;
>   
>     gdb_assert (regno != -1);
> @@ -438,7 +438,7 @@ static void
>   fetch_tlsregs_from_thread (struct regcache *regcache)
>   {
>     aarch64_gdbarch_tdep *tdep
> -    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
>     int regno = tdep->tls_regnum;
>   
>     gdb_assert (regno != -1);
> @@ -463,7 +463,7 @@ static void
>   store_tlsregs_to_thread (struct regcache *regcache)
>   {
>     aarch64_gdbarch_tdep *tdep
> -    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
>     int regno = tdep->tls_regnum;
>   
>     gdb_assert (regno != -1);
> @@ -492,7 +492,7 @@ aarch64_linux_nat_target::fetch_registers (struct regcache *regcache,
>   					   int regno)
>   {
>     aarch64_gdbarch_tdep *tdep
> -    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
>   
>     if (regno == -1)
>       {
> @@ -541,7 +541,7 @@ aarch64_linux_nat_target::store_registers (struct regcache *regcache,
>   					   int regno)
>   {
>     aarch64_gdbarch_tdep *tdep
> -    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
>   
>     if (regno == -1)
>       {
> @@ -808,7 +808,7 @@ aarch64_linux_nat_target::thread_architecture (ptid_t ptid)
>     inferior *inf = find_inferior_ptid (this, ptid);
>     gdb_assert (inf != NULL);
>     aarch64_gdbarch_tdep *tdep
> -    = (aarch64_gdbarch_tdep *) gdbarch_tdep (inf->gdbarch);
> +    = gdbarch_tdep<aarch64_gdbarch_tdep> (inf->gdbarch);
>     if (vq == tdep->vq)
>       return inf->gdbarch;
>   
> diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c
> index 453692df2f4..4c96662efb3 100644
> --- a/gdb/aarch64-linux-tdep.c
> +++ b/gdb/aarch64-linux-tdep.c
> @@ -286,7 +286,7 @@ aarch64_linux_sigframe_init (const struct tramp_frame *self,
>   {
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>     CORE_ADDR sp = get_frame_register_unsigned (this_frame, AARCH64_SP_REGNUM);
>     CORE_ADDR sigcontext_addr = (sp + AARCH64_RT_SIGFRAME_UCONTEXT_OFFSET
>   			       + AARCH64_UCONTEXT_SIGCONTEXT_OFFSET );
> @@ -640,7 +640,7 @@ aarch64_linux_collect_sve_regset (const struct regset *regset,
>     gdb_byte *header = (gdb_byte *) buf;
>     struct gdbarch *gdbarch = regcache->arch ();
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>     uint64_t vq = tdep->vq;
>   
>     gdb_assert (buf != NULL);
> @@ -676,7 +676,7 @@ aarch64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   					    void *cb_data,
>   					    const struct regcache *regcache)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     cb (".reg", AARCH64_LINUX_SIZEOF_GREGSET, AARCH64_LINUX_SIZEOF_GREGSET,
>         &aarch64_linux_gregset, NULL, cb_data);
> @@ -1743,7 +1743,7 @@ aarch64_linux_report_signal_info (struct gdbarch *gdbarch,
>   				  struct ui_out *uiout,
>   				  enum gdb_signal siggnal)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->has_mte () || siggnal != GDB_SIGNAL_SEGV)
>       return;
> @@ -1812,7 +1812,7 @@ aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   								    NULL };
>     static const char *const stap_register_indirection_suffixes[] = { "]",
>   								    NULL };
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     tdep->lowest_pc = 0x8000;
>   
> diff --git a/gdb/aarch64-newlib-tdep.c b/gdb/aarch64-newlib-tdep.c
> index 507b7fc5a51..c9236b17801 100644
> --- a/gdb/aarch64-newlib-tdep.c
> +++ b/gdb/aarch64-newlib-tdep.c
> @@ -29,7 +29,7 @@
>   static void
>   aarch64_newlib_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     /* Jump buffer - support for longjmp.
>        Offset of original PC in jump buffer (in registers).  */
> diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
> index 67a3f96e1a7..bf8ad0f5525 100644
> --- a/gdb/aarch64-tdep.c
> +++ b/gdb/aarch64-tdep.c
> @@ -502,7 +502,7 @@ aarch64_analyze_prologue (struct gdbarch *gdbarch,
>         else if (inst.opcode->iclass == ic_system)
>   	{
>   	  aarch64_gdbarch_tdep *tdep
> -	    = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +	    = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   	  int ra_state_val = 0;
>   
>   	  if (insn == 0xd503233f /* paciasp.  */
> @@ -640,7 +640,7 @@ aarch64_analyze_prologue_test (void)
>     struct aarch64_prologue_cache cache;
>     cache.saved_regs = trad_frame_alloc_saved_regs (gdbarch);
>   
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     /* Test the simple prologue in which frame pointer is used.  */
>     {
> @@ -1076,7 +1076,7 @@ aarch64_prologue_frame_unwind_stop_reason (struct frame_info *this_frame,
>   
>     /* Halt the backtrace at "_start".  */
>     gdbarch *arch = get_frame_arch (this_frame);
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (arch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (arch);
>     if (cache->prev_pc <= tdep->lowest_pc)
>       return UNWIND_OUTERMOST;
>   
> @@ -1120,7 +1120,7 @@ aarch64_prologue_prev_register (struct frame_info *this_frame,
>         CORE_ADDR lr;
>         struct gdbarch *gdbarch = get_frame_arch (this_frame);
>         aarch64_gdbarch_tdep *tdep
> -	= (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +	= gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>         lr = frame_unwind_register_unsigned (this_frame, AARCH64_LR_REGNUM);
>   
> @@ -1289,7 +1289,7 @@ aarch64_dwarf2_prev_register (struct frame_info *this_frame,
>   			      void **this_cache, int regnum)
>   {
>     gdbarch *arch = get_frame_arch (this_frame);
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (arch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (arch);
>     CORE_ADDR lr;
>   
>     switch (regnum)
> @@ -1315,7 +1315,7 @@ aarch64_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
>   			       struct dwarf2_frame_state_reg *reg,
>   			       struct frame_info *this_frame)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     switch (regnum)
>       {
> @@ -1355,7 +1355,7 @@ static bool
>   aarch64_execute_dwarf_cfa_vendor_op (struct gdbarch *gdbarch, gdb_byte op,
>   				     struct dwarf2_frame_state *fs)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>     struct dwarf2_frame_state_reg *ra_state;
>   
>     if (op == DW_CFA_AARCH64_negate_ra_state)
> @@ -1996,7 +1996,7 @@ aarch64_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
>   static struct type *
>   aarch64_vnq_type (struct gdbarch *gdbarch)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->vnq_type == NULL)
>       {
> @@ -2023,7 +2023,7 @@ aarch64_vnq_type (struct gdbarch *gdbarch)
>   static struct type *
>   aarch64_vnd_type (struct gdbarch *gdbarch)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->vnd_type == NULL)
>       {
> @@ -2053,7 +2053,7 @@ aarch64_vnd_type (struct gdbarch *gdbarch)
>   static struct type *
>   aarch64_vns_type (struct gdbarch *gdbarch)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->vns_type == NULL)
>       {
> @@ -2083,7 +2083,7 @@ aarch64_vns_type (struct gdbarch *gdbarch)
>   static struct type *
>   aarch64_vnh_type (struct gdbarch *gdbarch)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->vnh_type == NULL)
>       {
> @@ -2116,7 +2116,7 @@ aarch64_vnh_type (struct gdbarch *gdbarch)
>   static struct type *
>   aarch64_vnb_type (struct gdbarch *gdbarch)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->vnb_type == NULL)
>       {
> @@ -2143,7 +2143,7 @@ aarch64_vnb_type (struct gdbarch *gdbarch)
>   static struct type *
>   aarch64_vnv_type (struct gdbarch *gdbarch)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->vnv_type == NULL)
>       {
> @@ -2214,7 +2214,7 @@ aarch64_vnv_type (struct gdbarch *gdbarch)
>   static int
>   aarch64_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     if (reg >= AARCH64_DWARF_X0 && reg <= AARCH64_DWARF_X0 + 30)
>       return AARCH64_X0_REGNUM + reg - AARCH64_DWARF_X0;
> @@ -2518,7 +2518,7 @@ aarch64_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
>     CORE_ADDR jb_addr;
>     gdb_byte buf[X_REGISTER_SIZE];
>     struct gdbarch *gdbarch = get_frame_arch (frame);
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>   
>     jb_addr = get_frame_register_unsigned (frame, AARCH64_X0_REGNUM);
> @@ -2549,7 +2549,7 @@ aarch64_gen_return_address (struct gdbarch *gdbarch,
>   static const char *
>   aarch64_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     static const char *const q_name[] =
>       {
> @@ -2663,7 +2663,7 @@ aarch64_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
>   static struct type *
>   aarch64_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     int p_regnum = regnum - gdbarch_num_regs (gdbarch);
>   
> @@ -2700,7 +2700,7 @@ static int
>   aarch64_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
>   				    const struct reggroup *group)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     int p_regnum = regnum - gdbarch_num_regs (gdbarch);
>   
> @@ -2754,7 +2754,7 @@ static struct value *
>   aarch64_pseudo_read_value (struct gdbarch *gdbarch, readable_regcache *regcache,
>   			   int regnum)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>     struct value *result_value = allocate_value (register_type (gdbarch, regnum));
>   
>     VALUE_LVAL (result_value) = lval_register;
> @@ -2824,7 +2824,7 @@ static void
>   aarch64_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache,
>   		      int regnum, const gdb_byte *buf)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>     regnum -= gdbarch_num_regs (gdbarch);
>   
>     if (regnum >= AARCH64_Q0_REGNUM && regnum < AARCH64_Q0_REGNUM + 32)
> @@ -3377,7 +3377,7 @@ aarch64_get_tdesc_vq (const struct target_desc *tdesc)
>   static int
>   aarch64_cannot_store_register (struct gdbarch *gdbarch, int regnum)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->has_pauth ())
>       return 0;
> @@ -3444,7 +3444,7 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
>       {
>         aarch64_gdbarch_tdep *tdep
> -	= (aarch64_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
> +	= gdbarch_tdep<aarch64_gdbarch_tdep> (best_arch->gdbarch);
>         if (tdep && tdep->vq == vq)
>   	return best_arch->gdbarch;
>       }
> @@ -3693,7 +3693,7 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>   static void
>   aarch64_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     if (tdep == NULL)
>       return;
> @@ -3915,7 +3915,7 @@ aarch64_record_branch_except_sys (insn_decode_record *aarch64_insn_r)
>   {
>   
>     aarch64_gdbarch_tdep *tdep
> -    = (aarch64_gdbarch_tdep *) gdbarch_tdep (aarch64_insn_r->gdbarch);
> +    = gdbarch_tdep<aarch64_gdbarch_tdep> (aarch64_insn_r->gdbarch);
>     uint8_t insn_bits24_27, insn_bits28_31, insn_bits22_23;
>     uint32_t record_buf[4];
>   
> diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c
> index ecd8200b692..3d76b8c6d01 100644
> --- a/gdb/aix-thread.c
> +++ b/gdb/aix-thread.c
> @@ -1114,7 +1114,7 @@ static void
>   supply_gprs64 (struct regcache *regcache, uint64_t *vals)
>   {
>     ppc_gdbarch_tdep *tdep
> -    = (ppc_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<ppc_gdbarch_tdep> (regcache->arch ());
>     int regno;
>   
>     for (regno = 0; regno < ppc_num_gprs; regno++)
> @@ -1136,7 +1136,7 @@ static void
>   supply_fprs (struct regcache *regcache, double *vals)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int regno;
>   
>     /* This function should never be called on architectures without
> @@ -1154,7 +1154,7 @@ supply_fprs (struct regcache *regcache, double *vals)
>   static int
>   special_register_p (struct gdbarch *gdbarch, int regno)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     return regno == gdbarch_pc_regnum (gdbarch)
>         || regno == tdep->ppc_ps_regnum
> @@ -1177,7 +1177,7 @@ supply_sprs64 (struct regcache *regcache,
>   	       uint32_t fpscr)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     regcache->raw_supply (gdbarch_pc_regnum (gdbarch), (char *) &iar);
>     regcache->raw_supply (tdep->ppc_ps_regnum, (char *) &msr);
> @@ -1199,7 +1199,7 @@ supply_sprs32 (struct regcache *regcache,
>   	       uint32_t fpscr)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     regcache->raw_supply (gdbarch_pc_regnum (gdbarch), (char *) &iar);
>     regcache->raw_supply (tdep->ppc_ps_regnum, (char *) &msr);
> @@ -1222,7 +1222,7 @@ static void
>   fetch_regs_user_thread (struct regcache *regcache, pthdb_pthread_t pdtid)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int status, i;
>     pthdb_context_t ctx;
>   
> @@ -1277,7 +1277,7 @@ fetch_regs_kernel_thread (struct regcache *regcache, int regno,
>   			  pthdb_tid_t tid)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     uint64_t gprs64[ppc_num_gprs];
>     uint32_t gprs32[ppc_num_gprs];
>     double fprs[ppc_num_fprs];
> @@ -1380,7 +1380,7 @@ static void
>   fill_gprs64 (const struct regcache *regcache, uint64_t *vals)
>   {
>     ppc_gdbarch_tdep *tdep
> -    = (ppc_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<ppc_gdbarch_tdep> (regcache->arch ());
>     int regno;
>   
>     for (regno = 0; regno < ppc_num_gprs; regno++)
> @@ -1393,7 +1393,7 @@ static void
>   fill_gprs32 (const struct regcache *regcache, uint32_t *vals)
>   {
>     ppc_gdbarch_tdep *tdep
> -    = (ppc_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<ppc_gdbarch_tdep> (regcache->arch ());
>     int regno;
>   
>     for (regno = 0; regno < ppc_num_gprs; regno++)
> @@ -1407,7 +1407,7 @@ static void
>   fill_fprs (const struct regcache *regcache, double *vals)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int regno;
>   
>     /* This function should never be called on architectures without
> @@ -1431,7 +1431,7 @@ fill_sprs64 (const struct regcache *regcache,
>   	     uint32_t *fpscr)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     /* Verify that the size of the size of the IAR buffer is the
>        same as the raw size of the PC (in the register cache).  If
> @@ -1465,7 +1465,7 @@ fill_sprs32 (const struct regcache *regcache,
>   	     uint32_t *fpscr)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     /* Verify that the size of the size of the IAR buffer is the
>        same as the raw size of the PC (in the register cache).  If
> @@ -1502,7 +1502,7 @@ static void
>   store_regs_user_thread (const struct regcache *regcache, pthdb_pthread_t pdtid)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int status, i;
>     pthdb_context_t ctx;
>     uint32_t int32;
> @@ -1592,7 +1592,7 @@ store_regs_kernel_thread (const struct regcache *regcache, int regno,
>   			  pthdb_tid_t tid)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     uint64_t gprs64[ppc_num_gprs];
>     uint32_t gprs32[ppc_num_gprs];
>     double fprs[ppc_num_fprs];
> diff --git a/gdb/alpha-linux-tdep.c b/gdb/alpha-linux-tdep.c
> index 6cea40d3f34..c103aafc1ff 100644
> --- a/gdb/alpha-linux-tdep.c
> +++ b/gdb/alpha-linux-tdep.c
> @@ -362,7 +362,7 @@ alpha_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>     /* Hook into the MDEBUG frame unwinder.  */
>     alpha_mdebug_init_abi (info, gdbarch);
>   
> -  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
>     tdep->dynamic_sigtramp_offset = alpha_linux_sigtramp_offset;
>     tdep->sigcontext_addr = alpha_linux_sigcontext_addr;
>     tdep->pc_in_sigtramp = alpha_linux_pc_in_sigtramp;
> diff --git a/gdb/alpha-netbsd-tdep.c b/gdb/alpha-netbsd-tdep.c
> index 6b604cfa9c6..72d7019377f 100644
> --- a/gdb/alpha-netbsd-tdep.c
> +++ b/gdb/alpha-netbsd-tdep.c
> @@ -250,7 +250,7 @@ static void
>   alphanbsd_init_abi (struct gdbarch_info info,
>   		    struct gdbarch *gdbarch)
>   {
> -  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
>   
>     /* Hook into the DWARF CFI frame unwinder.  */
>     alpha_dwarf2_init_abi (info, gdbarch);
> diff --git a/gdb/alpha-obsd-tdep.c b/gdb/alpha-obsd-tdep.c
> index 8baa8cc32c4..c0d672c3f72 100644
> --- a/gdb/alpha-obsd-tdep.c
> +++ b/gdb/alpha-obsd-tdep.c
> @@ -97,7 +97,7 @@ alphaobsd_sigcontext_addr (struct frame_info *this_frame)
>   static void
>   alphaobsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
>   
>     /* Hook into the DWARF CFI frame unwinder.  */
>     alpha_dwarf2_init_abi (info, gdbarch);
> diff --git a/gdb/alpha-tdep.c b/gdb/alpha-tdep.c
> index f04bad6bed8..44efc8e4bbb 100644
> --- a/gdb/alpha-tdep.c
> +++ b/gdb/alpha-tdep.c
> @@ -615,7 +615,7 @@ alpha_return_value (struct gdbarch *gdbarch, struct value *function,
>   		    gdb_byte *readbuf, const gdb_byte *writebuf)
>   {
>     enum type_code code = type->code ();
> -  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
>   
>     if ((code == TYPE_CODE_STRUCT
>          || code == TYPE_CODE_UNION
> @@ -851,7 +851,7 @@ static int
>   alpha_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (frame);
> -  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     CORE_ADDR jb_addr;
>     gdb_byte raw_buffer[ALPHA_REGISTER_SIZE];
> @@ -891,7 +891,7 @@ alpha_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
>     *this_prologue_cache = info;
>   
>     gdbarch *arch = get_frame_arch (this_frame);
> -  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (arch);
> +  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (arch);
>     info->sigcontext_addr = tdep->sigcontext_addr (this_frame);
>   
>     return info;
> @@ -904,7 +904,7 @@ static CORE_ADDR
>   alpha_sigtramp_register_address (struct gdbarch *gdbarch,
>   				 CORE_ADDR sigcontext_addr, int regnum)
>   {
> -  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
>   
>     if (regnum >= 0 && regnum < 32)
>       return sigcontext_addr + tdep->sc_regs_offset + regnum * 8;
> @@ -925,7 +925,7 @@ alpha_sigtramp_frame_this_id (struct frame_info *this_frame,
>   			      struct frame_id *this_id)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
>     struct alpha_sigtramp_unwind_cache *info
>       = alpha_sigtramp_frame_unwind_cache (this_frame, this_prologue_cache);
>     CORE_ADDR stack_addr, code_addr;
> @@ -1000,7 +1000,7 @@ alpha_sigtramp_frame_sniffer (const struct frame_unwind *self,
>   
>     /* We shouldn't even bother to try if the OSABI didn't register a
>        sigcontext_addr handler or pc_in_sigtramp handler.  */
> -  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
>     if (tdep->sigcontext_addr == NULL)
>       return 0;
>   
> @@ -1041,7 +1041,7 @@ static int heuristic_fence_post = 0;
>   static CORE_ADDR
>   alpha_heuristic_proc_start (struct gdbarch *gdbarch, CORE_ADDR pc)
>   {
> -  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
>     CORE_ADDR last_non_nop = pc;
>     CORE_ADDR fence = pc - heuristic_fence_post;
>     CORE_ADDR orig_pc = pc;
> diff --git a/gdb/amd64-darwin-tdep.c b/gdb/amd64-darwin-tdep.c
> index 74906f6a02d..7fc35536bc6 100644
> --- a/gdb/amd64-darwin-tdep.c
> +++ b/gdb/amd64-darwin-tdep.c
> @@ -97,7 +97,7 @@ amd64_darwin_sigcontext_addr (struct frame_info *this_frame)
>   static void
>   x86_darwin_init_abi_64 (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     amd64_init_abi (info, gdbarch,
>   		  amd64_target_description (X86_XSTATE_SSE_MASK, true));
> diff --git a/gdb/amd64-fbsd-nat.c b/gdb/amd64-fbsd-nat.c
> index d125d582a21..7023a182e78 100644
> --- a/gdb/amd64-fbsd-nat.c
> +++ b/gdb/amd64-fbsd-nat.c
> @@ -102,7 +102,7 @@ amd64_fbsd_nat_target::fetch_registers (struct regcache *regcache, int regnum)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
>   #if defined(PT_GETFSBASE) || defined(PT_GETGSBASE)
> -  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   #endif
>     pid_t pid = get_ptrace_pid (regcache->ptid ());
>     const struct regset *gregset = find_gregset (gdbarch);
> @@ -174,7 +174,7 @@ amd64_fbsd_nat_target::store_registers (struct regcache *regcache, int regnum)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
>   #if defined(PT_GETFSBASE) || defined(PT_GETGSBASE)
> -  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   #endif
>     pid_t pid = get_ptrace_pid (regcache->ptid ());
>     const struct regset *gregset = find_gregset (gdbarch);
> diff --git a/gdb/amd64-fbsd-tdep.c b/gdb/amd64-fbsd-tdep.c
> index 55764beaad2..8e40283d838 100644
> --- a/gdb/amd64-fbsd-tdep.c
> +++ b/gdb/amd64-fbsd-tdep.c
> @@ -262,7 +262,7 @@ amd64fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   					void *cb_data,
>   					const struct regcache *regcache)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     cb (".reg", AMD64_FBSD_SIZEOF_GREGSET, AMD64_FBSD_SIZEOF_GREGSET,
>         &amd64_fbsd_gregset, NULL, cb_data);
> @@ -299,7 +299,7 @@ amd64fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
>   static void
>   amd64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* Generic FreeBSD support. */
>     fbsd_init_abi (info, gdbarch);
> diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
> index 9a0759d639c..aa9c56586ab 100644
> --- a/gdb/amd64-linux-tdep.c
> +++ b/gdb/amd64-linux-tdep.c
> @@ -1656,7 +1656,7 @@ amd64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   					  void *cb_data,
>   					  const struct regcache *regcache)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     cb (".reg", 27 * 8, 27 * 8, &i386_gregset, NULL, cb_data);
>     cb (".reg2", 512, 512, &amd64_fpregset, NULL, cb_data);
> @@ -1793,7 +1793,7 @@ static void
>   amd64_linux_init_abi_common(struct gdbarch_info info, struct gdbarch *gdbarch,
>   			    int num_disp_step_buffers)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     linux_init_abi (info, gdbarch, num_disp_step_buffers);
>   
> @@ -1846,7 +1846,7 @@ amd64_linux_init_abi_common(struct gdbarch_info info, struct gdbarch *gdbarch,
>   static void
>   amd64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     struct tdesc_arch_data *tdesc_data = info.tdesc_data;
>     const struct tdesc_feature *feature;
>     int valid_p;
> @@ -2060,7 +2060,7 @@ amd64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   static void
>   amd64_x32_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     struct tdesc_arch_data *tdesc_data = info.tdesc_data;
>     const struct tdesc_feature *feature;
>     int valid_p;
> diff --git a/gdb/amd64-netbsd-tdep.c b/gdb/amd64-netbsd-tdep.c
> index 3ab0267060d..59d723caa55 100644
> --- a/gdb/amd64-netbsd-tdep.c
> +++ b/gdb/amd64-netbsd-tdep.c
> @@ -97,7 +97,7 @@ int amd64nbsd_r_reg_offset[] =
>   static void
>   amd64nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* Initialize general-purpose register set details first.  */
>     tdep->gregset_reg_offset = amd64nbsd_r_reg_offset;
> diff --git a/gdb/amd64-obsd-tdep.c b/gdb/amd64-obsd-tdep.c
> index 3cb64fe924f..f0bc7c474a6 100644
> --- a/gdb/amd64-obsd-tdep.c
> +++ b/gdb/amd64-obsd-tdep.c
> @@ -420,7 +420,7 @@ static const struct frame_unwind amd64obsd_trapframe_unwind =
>   static void
>   amd64obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     amd64_init_abi (info, gdbarch,
>   		  amd64_target_description (X86_XSTATE_SSE_MASK, true));
> diff --git a/gdb/amd64-sol2-tdep.c b/gdb/amd64-sol2-tdep.c
> index 22a48e476a5..ce96eb045ec 100644
> --- a/gdb/amd64-sol2-tdep.c
> +++ b/gdb/amd64-sol2-tdep.c
> @@ -80,7 +80,7 @@ amd64_sol2_mcontext_addr (struct frame_info *this_frame)
>   static void
>   amd64_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     tdep->gregset_reg_offset = amd64_sol2_gregset_reg_offset;
>     tdep->gregset_num_regs = ARRAY_SIZE (amd64_sol2_gregset_reg_offset);
> diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
> index b95ab1e87b8..0563b32a54b 100644
> --- a/gdb/amd64-tdep.c
> +++ b/gdb/amd64-tdep.c
> @@ -247,7 +247,7 @@ static const int amd64_dwarf_regmap_len =
>   static int
>   amd64_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int ymm0_regnum = tdep->ymm0_regnum;
>     int regnum = -1;
>   
> @@ -331,7 +331,7 @@ static const char * const amd64_dword_names[] =
>   static const char *
>   amd64_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     if (i386_byte_regnum_p (gdbarch, regnum))
>       return amd64_byte_names[regnum - tdep->al_regnum];
>     else if (i386_zmm_regnum_p (gdbarch, regnum))
> @@ -353,7 +353,7 @@ amd64_pseudo_register_read_value (struct gdbarch *gdbarch,
>   				  readable_regcache *regcache,
>   				  int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     value *result_value = allocate_value (register_type (gdbarch, regnum));
>     VALUE_LVAL (result_value) = lval_register;
> @@ -413,7 +413,7 @@ amd64_pseudo_register_write (struct gdbarch *gdbarch,
>   			     struct regcache *regcache,
>   			     int regnum, const gdb_byte *buf)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     if (i386_byte_regnum_p (gdbarch, regnum))
>       {
> @@ -465,7 +465,7 @@ static int
>   amd64_ax_pseudo_register_collect (struct gdbarch *gdbarch,
>   				  struct agent_expr *ax, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     if (i386_byte_regnum_p (gdbarch, regnum))
>       {
> @@ -2749,7 +2749,7 @@ static struct amd64_frame_cache *
>   amd64_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     struct amd64_frame_cache *cache;
>     CORE_ADDR addr;
> @@ -2832,7 +2832,7 @@ amd64_sigtramp_frame_sniffer (const struct frame_unwind *self,
>   			      void **this_cache)
>   {
>     gdbarch *arch = get_frame_arch (this_frame);
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
>   
>     /* We shouldn't even bother if we don't have a sigcontext_addr
>        handler.  */
> @@ -3032,7 +3032,7 @@ amd64_supply_fpregset (const struct regset *regset, struct regcache *regcache,
>   		       int regnum, const void *fpregs, size_t len)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     gdb_assert (len >= tdep->sizeof_fpregset);
>     amd64_supply_fxsave (regcache, regnum, fpregs);
> @@ -3049,7 +3049,7 @@ amd64_collect_fpregset (const struct regset *regset,
>   			int regnum, void *fpregs, size_t len)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     gdb_assert (len >= tdep->sizeof_fpregset);
>     amd64_collect_fxsave (regcache, regnum, fpregs);
> @@ -3073,7 +3073,7 @@ amd64_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
>     gdb_byte buf[8];
>     CORE_ADDR jb_addr;
>     struct gdbarch *gdbarch = get_frame_arch (frame);
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int jb_pc_offset = tdep->jb_pc_offset;
>     int len = TYPE_LENGTH (builtin_type (gdbarch)->builtin_func_ptr);
>   
> @@ -3117,7 +3117,7 @@ void
>   amd64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch,
>   		const target_desc *default_tdesc)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     const struct target_desc *tdesc = info.target_desc;
>     static const char *const stap_integer_prefixes[] = { "$", NULL };
>     static const char *const stap_register_prefixes[] = { "%", NULL };
> @@ -3296,7 +3296,7 @@ amd64_none_init_abi (gdbarch_info info, gdbarch *arch)
>   static struct type *
>   amd64_x32_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     switch (regnum - tdep->eax_regnum)
>       {
> @@ -3314,7 +3314,7 @@ void
>   amd64_x32_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch,
>   		    const target_desc *default_tdesc)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     amd64_init_abi (info, gdbarch, default_tdesc);
>   
> @@ -3384,7 +3384,7 @@ amd64_supply_fxsave (struct regcache *regcache, int regnum,
>   		     const void *fxsave)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     i387_supply_fxsave (regcache, regnum, fxsave);
>   
> @@ -3407,7 +3407,7 @@ amd64_supply_xsave (struct regcache *regcache, int regnum,
>   		    const void *xsave)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     i387_supply_xsave (regcache, regnum, xsave);
>   
> @@ -3442,7 +3442,7 @@ amd64_collect_fxsave (const struct regcache *regcache, int regnum,
>   		      void *fxsave)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     gdb_byte *regs = (gdb_byte *) fxsave;
>   
>     i387_collect_fxsave (regcache, regnum, fxsave);
> @@ -3463,7 +3463,7 @@ amd64_collect_xsave (const struct regcache *regcache, int regnum,
>   		     void *xsave, int gcore)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     gdb_byte *regs = (gdb_byte *) xsave;
>   
>     i387_collect_xsave (regcache, regnum, xsave, gcore);
> diff --git a/gdb/amd64-windows-tdep.c b/gdb/amd64-windows-tdep.c
> index eca94f2ea7c..a9aef0bab88 100644
> --- a/gdb/amd64-windows-tdep.c
> +++ b/gdb/amd64-windows-tdep.c
> @@ -1277,7 +1277,7 @@ amd64_windows_auto_wide_charset (void)
>   static void
>   amd64_windows_init_abi_common (gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* The dwarf2 unwinder (appended very early by i386_gdbarch_init) is
>        preferred over the SEH one.  The reasons are:
> diff --git a/gdb/arc-linux-tdep.c b/gdb/arc-linux-tdep.c
> index 13595f2e8e9..9c1febcd900 100644
> --- a/gdb/arc-linux-tdep.c
> +++ b/gdb/arc-linux-tdep.c
> @@ -411,7 +411,7 @@ static std::vector<CORE_ADDR>
>   arc_linux_software_single_step (struct regcache *regcache)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
>     struct disassemble_info di = arc_disassemble_info (gdbarch);
>   
>     /* Read current instruction.  */
> @@ -693,7 +693,7 @@ arc_linux_core_read_description (struct gdbarch *gdbarch,
>   static void
>   arc_linux_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
>   
>     arc_linux_debug_printf ("GNU/Linux OS/ABI initialization.");
>   
> diff --git a/gdb/arc-newlib-tdep.c b/gdb/arc-newlib-tdep.c
> index 7d7406c501c..2499dff43ec 100644
> --- a/gdb/arc-newlib-tdep.c
> +++ b/gdb/arc-newlib-tdep.c
> @@ -36,7 +36,7 @@ arc_newlib_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
>     arc_newlib_debug_printf ("Initialization.");
>   
> -  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
>   
>     /* Offset of original PC in longjmp jump buffer (in registers).  Value of PC
>        offset can be found in newlib/libc/machine/arc/setjmp.S.  */
> diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c
> index 3edfd466f3b..b9c734210fe 100644
> --- a/gdb/arc-tdep.c
> +++ b/gdb/arc-tdep.c
> @@ -1002,7 +1002,7 @@ arc_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
>     arc_debug_printf ("called");
>   
>     struct gdbarch *gdbarch = get_frame_arch (frame);
> -  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
>     int pc_offset = tdep->jb_pc * ARC_REGISTER_SIZE;
>     gdb_byte buf[ARC_REGISTER_SIZE];
>     CORE_ADDR jb_addr = get_frame_register_unsigned (frame, ARC_FIRST_ARG_REGNUM);
> @@ -1827,7 +1827,7 @@ arc_make_sigtramp_frame_cache (struct frame_info *this_frame)
>     arc_debug_printf ("called");
>   
>     gdbarch *arch = get_frame_arch (this_frame);
> -  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (arch);
> +  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (arch);
>   
>     /* Allocate new frame cache instance and space for saved register info.  */
>     struct arc_frame_cache *cache = FRAME_OBSTACK_ZALLOC (struct arc_frame_cache);
> @@ -1904,7 +1904,7 @@ arc_sigtramp_frame_sniffer (const struct frame_unwind *self,
>     arc_debug_printf ("called");
>   
>     gdbarch *arch = get_frame_arch (this_frame);
> -  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (arch);
> +  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (arch);
>   
>     /* If we have a sigcontext_addr handler, then just return 1 (same as the
>        "default_frame_sniffer ()").  */
> @@ -2431,7 +2431,7 @@ arc_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>   static void
>   arc_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
>   {
> -  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
>   
>     gdb_printf (file, "arc_dump_tdep: jb_pc = %i\n", tdep->jb_pc);
>   
> diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
> index ff946ee3767..360b8d694be 100644
> --- a/gdb/arch-utils.c
> +++ b/gdb/arch-utils.c
> @@ -1198,11 +1198,13 @@ gdbarch_free (struct gdbarch *arch)
>     xfree (obstack);
>   }
>   
> +/* See gdbarch.h.  */
> +
>   struct gdbarch_tdep *
> -gdbarch_tdep (struct gdbarch *gdbarch)
> +gdbarch_tdep_1 (struct gdbarch *gdbarch)
>   {
>     if (gdbarch_debug >= 2)
> -    gdb_printf (gdb_stdlog, "gdbarch_tdep called\n");
> +    gdb_printf (gdb_stdlog, "gdbarch_tdep_1 called\n");
>     return gdbarch->tdep;
>   }
>   
> diff --git a/gdb/arm-fbsd-nat.c b/gdb/arm-fbsd-nat.c
> index a306e1e2ee0..b161b7ed908 100644
> --- a/gdb/arm-fbsd-nat.c
> +++ b/gdb/arm-fbsd-nat.c
> @@ -55,7 +55,7 @@ arm_fbsd_nat_target::fetch_registers (struct regcache *regcache, int regnum)
>   #endif
>   #ifdef PT_GETREGSET
>     gdbarch *gdbarch = regcache->arch ();
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->tls_regnum > 0)
>       {
> @@ -90,7 +90,7 @@ arm_fbsd_nat_target::store_registers (struct regcache *regcache, int regnum)
>   #endif
>   #ifdef PT_GETREGSET
>     gdbarch *gdbarch = regcache->arch ();
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->tls_regnum > 0)
>       {
> diff --git a/gdb/arm-fbsd-tdep.c b/gdb/arm-fbsd-tdep.c
> index 483820c1092..61c8f0cecad 100644
> --- a/gdb/arm-fbsd-tdep.c
> +++ b/gdb/arm-fbsd-tdep.c
> @@ -159,7 +159,7 @@ arm_fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   				       void *cb_data,
>   				       const struct regcache *regcache)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     cb (".reg", ARM_FBSD_SIZEOF_GREGSET, ARM_FBSD_SIZEOF_GREGSET,
>         &arm_fbsd_gregset, NULL, cb_data);
> @@ -233,7 +233,7 @@ static CORE_ADDR
>   arm_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
>   				   CORE_ADDR lm_addr, CORE_ADDR offset)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>     struct regcache *regcache;
>   
>     regcache = get_thread_arch_regcache (current_inferior ()->process_target (),
> @@ -256,7 +256,7 @@ arm_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
>   static void
>   arm_fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     /* Generic FreeBSD support.  */
>     fbsd_init_abi (info, gdbarch);
> diff --git a/gdb/arm-linux-nat.c b/gdb/arm-linux-nat.c
> index 2abaf5a675d..9dd1cdcb0b0 100644
> --- a/gdb/arm-linux-nat.c
> +++ b/gdb/arm-linux-nat.c
> @@ -339,7 +339,7 @@ fetch_vfp_regs (struct regcache *regcache)
>     gdb_byte regbuf[ARM_VFP3_REGS_SIZE];
>     int ret, tid;
>     struct gdbarch *gdbarch = regcache->arch ();
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     /* Get the thread id for the ptrace call.  */
>     tid = regcache->ptid ().lwp ();
> @@ -368,7 +368,7 @@ store_vfp_regs (const struct regcache *regcache)
>     gdb_byte regbuf[ARM_VFP3_REGS_SIZE];
>     int ret, tid;
>     struct gdbarch *gdbarch = regcache->arch ();
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     /* Get the thread id for the ptrace call.  */
>     tid = regcache->ptid ().lwp ();
> @@ -413,7 +413,7 @@ void
>   arm_linux_nat_target::fetch_registers (struct regcache *regcache, int regno)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (-1 == regno)
>       {
> @@ -450,7 +450,7 @@ void
>   arm_linux_nat_target::store_registers (struct regcache *regcache, int regno)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (-1 == regno)
>       {
> diff --git a/gdb/arm-linux-tdep.c b/gdb/arm-linux-tdep.c
> index f299e9665d5..d530b7f59a8 100644
> --- a/gdb/arm-linux-tdep.c
> +++ b/gdb/arm-linux-tdep.c
> @@ -712,7 +712,7 @@ arm_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   					void *cb_data,
>   					const struct regcache *regcache)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     cb (".reg", ARM_LINUX_SIZEOF_GREGSET, ARM_LINUX_SIZEOF_GREGSET,
>         &arm_linux_gregset, NULL, cb_data);
> @@ -1715,7 +1715,7 @@ arm_linux_init_abi (struct gdbarch_info info,
>   								    NULL };
>     static const char *const stap_register_indirection_suffixes[] = { "]",
>   								    NULL };
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     linux_init_abi (info, gdbarch, 1);
>   
> diff --git a/gdb/arm-netbsd-nat.c b/gdb/arm-netbsd-nat.c
> index 764bbe8cd3d..251159154c9 100644
> --- a/gdb/arm-netbsd-nat.c
> +++ b/gdb/arm-netbsd-nat.c
> @@ -50,7 +50,7 @@ static arm_netbsd_nat_target the_arm_netbsd_nat_target;
>   static void
>   arm_supply_vfpregset (struct regcache *regcache, struct fpreg *fpregset)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
>     if (tdep->vfp_register_count == 0)
>       return;
>   
> @@ -97,7 +97,7 @@ fetch_fp_register (struct regcache *regcache, int regno)
>         return;
>       }
>   
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
>     if (regno == ARM_FPSCR_REGNUM && tdep->vfp_register_count != 0)
>       regcache->raw_supply (ARM_FPSCR_REGNUM, (char *) &vfp.vfp_fpscr);
>     else if (regno >= ARM_D0_REGNUM
> @@ -279,7 +279,7 @@ store_fp_register (const struct regcache *regcache, int regno)
>         return;
>       }
>   
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
>     if (regno == ARM_FPSCR_REGNUM && tdep->vfp_register_count != 0)
>       regcache->raw_collect (ARM_FPSCR_REGNUM, (char *) &vfp.vfp_fpscr);
>     else if (regno >= ARM_D0_REGNUM
> @@ -301,7 +301,7 @@ store_fp_register (const struct regcache *regcache, int regno)
>   static void
>   store_fp_regs (const struct regcache *regcache)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
>     int lwp = regcache->ptid ().lwp ();
>     if (tdep->vfp_register_count == 0)
>       return;
> diff --git a/gdb/arm-netbsd-tdep.c b/gdb/arm-netbsd-tdep.c
> index a6a78f0b893..aa4d15df4c6 100644
> --- a/gdb/arm-netbsd-tdep.c
> +++ b/gdb/arm-netbsd-tdep.c
> @@ -111,7 +111,7 @@ static void
>   arm_netbsd_init_abi_common (struct gdbarch_info info,
>   			    struct gdbarch *gdbarch)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     tdep->lowest_pc = 0x8000;
>     switch (info.byte_order)
> @@ -148,7 +148,7 @@ static void
>   arm_netbsd_elf_init_abi (struct gdbarch_info info,
>   			 struct gdbarch *gdbarch)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     arm_netbsd_init_abi_common (info, gdbarch);
>   
> diff --git a/gdb/arm-none-tdep.c b/gdb/arm-none-tdep.c
> index 510ce4fa3c5..0d5eb04826e 100644
> --- a/gdb/arm-none-tdep.c
> +++ b/gdb/arm-none-tdep.c
> @@ -177,7 +177,7 @@ arm_none_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   				       void *cb_data,
>   				       const struct regcache *regcache)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     cb (".reg", ARM_NONE_SIZEOF_GREGSET, ARM_NONE_SIZEOF_GREGSET,
>         &arm_none_gregset, nullptr, cb_data);
> diff --git a/gdb/arm-obsd-tdep.c b/gdb/arm-obsd-tdep.c
> index 37cb30b9a2a..634c76b7561 100644
> --- a/gdb/arm-obsd-tdep.c
> +++ b/gdb/arm-obsd-tdep.c
> @@ -76,7 +76,7 @@ static void
>   armobsd_init_abi (struct gdbarch_info info,
>   		  struct gdbarch *gdbarch)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->fp_model == ARM_FLOAT_AUTO)
>       tdep->fp_model = ARM_FLOAT_SOFT_VFP;
> diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
> index d39342e19c6..99b73f64cd1 100644
> --- a/gdb/arm-tdep.c
> +++ b/gdb/arm-tdep.c
> @@ -338,7 +338,7 @@ static void
>   arm_cache_init (struct arm_prologue_cache *cache, struct frame_info *frame)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (frame);
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     arm_cache_init (cache, gdbarch);
>   
> @@ -520,7 +520,7 @@ bool arm_unwind_secure_frames = true;
>   int
>   arm_psr_thumb_bit (struct gdbarch *gdbarch)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->is_m)
>       return XPSR_T;
> @@ -628,7 +628,7 @@ arm_pc_is_thumb (struct gdbarch *gdbarch, CORE_ADDR memaddr)
>     struct bound_minimal_symbol sym;
>     char type;
>     arm_displaced_step_copy_insn_closure *dsc = nullptr;
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (gdbarch_displaced_step_copy_insn_closure_by_addr_p (gdbarch))
>       dsc = ((arm_displaced_step_copy_insn_closure * )
> @@ -732,7 +732,7 @@ arm_pc_is_thumb (struct gdbarch *gdbarch, CORE_ADDR memaddr)
>   static int
>   arm_m_addr_is_magic (struct gdbarch *gdbarch, CORE_ADDR addr)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>     if (tdep->have_sec_ext)
>       {
>         switch ((addr & 0xff000000))
> @@ -774,7 +774,7 @@ arm_m_addr_is_magic (struct gdbarch *gdbarch, CORE_ADDR addr)
>   static CORE_ADDR
>   arm_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR val)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     /* On M-profile devices, do not strip the low bit from EXC_RETURN
>        (the magic exception return address).  */
> @@ -1378,7 +1378,7 @@ thumb_analyze_prologue (struct gdbarch *gdbarch,
>   	    }
>   
>   	  arm_gdbarch_tdep *tdep
> -	    = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +	    = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>   	  /* Make sure we are dealing with a target that supports ARMv8.1-m
>   	     PACBTI.  */
> @@ -1840,7 +1840,7 @@ arm_analyze_prologue (struct gdbarch *gdbarch,
>     CORE_ADDR offset, current_pc;
>     pv_t regs[ARM_FPS_REGNUM];
>     CORE_ADDR unrecognized_pc = 0;
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     /* Search the prologue looking for instructions that set up the
>        frame pointer, adjust the stack pointer, and save registers.
> @@ -2084,7 +2084,7 @@ arm_scan_prologue (struct frame_info *this_frame,
>     CORE_ADDR prologue_start, prologue_end;
>     CORE_ADDR prev_pc = get_frame_pc (this_frame);
>     CORE_ADDR block_addr = get_frame_address_in_block (this_frame);
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     /* Assume there is no frame until proven otherwise.  */
>     cache->framereg = ARM_SP_REGNUM;
> @@ -2189,7 +2189,7 @@ arm_make_prologue_cache (struct frame_info *this_frame)
>       return cache;
>   
>     arm_gdbarch_tdep *tdep =
> -    (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
> +    gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
>   
>     arm_cache_set_active_sp_value (cache, tdep, unwound_fp + cache->framesize);
>   
> @@ -2219,7 +2219,7 @@ arm_prologue_unwind_stop_reason (struct frame_info *this_frame,
>     /* This is meant to halt the backtrace at "_start".  */
>     pc = get_frame_pc (this_frame);
>     gdbarch *arch = get_frame_arch (this_frame);
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (arch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (arch);
>     if (pc <= tdep->lowest_pc)
>       return UNWIND_OUTERMOST;
>   
> @@ -2247,7 +2247,7 @@ arm_prologue_this_id (struct frame_info *this_frame,
>     cache = (struct arm_prologue_cache *) *this_cache;
>   
>     arm_gdbarch_tdep *tdep
> -    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
> +    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
>   
>     /* Use function start address as part of the frame ID.  If we cannot
>        identify the start address (due to missing symbol information),
> @@ -2274,7 +2274,7 @@ arm_prologue_prev_register (struct frame_info *this_frame,
>       *this_cache = arm_make_prologue_cache (this_frame);
>     cache = (struct arm_prologue_cache *) *this_cache;
>   
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     /* If this frame has signed the return address, mark it as so.  */
>     if (tdep->have_pacbti && cache->ra_signed_state.has_value ()
> @@ -2947,7 +2947,7 @@ arm_exidx_fill_cache (struct frame_info *this_frame, gdb_byte *entry)
>   
>     /* We already got the previous SP.  */
>     arm_gdbarch_tdep *tdep
> -    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
> +    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
>     arm_cache_set_active_sp_value (cache, tdep, vsp);
>   
>     return cache;
> @@ -3072,7 +3072,7 @@ arm_make_epilogue_frame_cache (struct frame_info *this_frame)
>   
>     /* Since we are in epilogue, the SP has been restored.  */
>     arm_gdbarch_tdep *tdep
> -    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
> +    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
>     arm_cache_set_active_sp_value (cache, tdep,
>   				 get_frame_register_unsigned (this_frame,
>   							      ARM_SP_REGNUM));
> @@ -3111,7 +3111,7 @@ arm_epilogue_frame_this_id (struct frame_info *this_frame,
>       func = pc;
>   
>     arm_gdbarch_tdep *tdep
> -    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
> +    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
>     *this_id = frame_id_build (arm_cache_get_prev_sp_value (cache, tdep), pc);
>   }
>   
> @@ -3235,7 +3235,7 @@ arm_make_stub_cache (struct frame_info *this_frame)
>     arm_cache_init (cache, this_frame);
>   
>     arm_gdbarch_tdep *tdep
> -    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
> +    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
>     arm_cache_set_active_sp_value (cache, tdep,
>   				 get_frame_register_unsigned (this_frame,
>   							      ARM_SP_REGNUM));
> @@ -3257,7 +3257,7 @@ arm_stub_this_id (struct frame_info *this_frame,
>     cache = (struct arm_prologue_cache *) *this_cache;
>   
>     arm_gdbarch_tdep *tdep
> -    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
> +    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
>     *this_id = frame_id_build (arm_cache_get_prev_sp_value (cache, tdep),
>   			     get_frame_pc (this_frame));
>   }
> @@ -3305,7 +3305,7 @@ static struct arm_prologue_cache *
>   arm_m_exception_cache (struct frame_info *this_frame)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     struct arm_prologue_cache *cache;
>     CORE_ADDR lr;
> @@ -3523,7 +3523,7 @@ arm_m_exception_this_id (struct frame_info *this_frame,
>   
>     /* Our frame ID for a stub frame is the current SP and LR.  */
>     arm_gdbarch_tdep *tdep
> -    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
> +    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
>     *this_id = frame_id_build (arm_cache_get_prev_sp_value (cache, tdep),
>   			     get_frame_pc (this_frame));
>   }
> @@ -3545,7 +3545,7 @@ arm_m_exception_prev_register (struct frame_info *this_frame,
>   
>     /* The value was already reconstructed into PREV_SP.  */
>     arm_gdbarch_tdep *tdep
> -    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
> +    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
>     if (prev_regnum == ARM_SP_REGNUM)
>       return frame_unwind_got_constant (this_frame, prev_regnum,
>   				      arm_cache_get_prev_sp_value (cache, tdep));
> @@ -3612,7 +3612,7 @@ arm_normal_frame_base (struct frame_info *this_frame, void **this_cache)
>     cache = (struct arm_prologue_cache *) *this_cache;
>   
>     arm_gdbarch_tdep *tdep
> -    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
> +    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
>     return arm_cache_get_prev_sp_value (cache, tdep) - cache->framesize;
>   }
>   
> @@ -3628,7 +3628,7 @@ arm_dwarf2_prev_register (struct frame_info *this_frame, void **this_cache,
>   			  int regnum)
>   {
>     struct gdbarch * gdbarch = get_frame_arch (this_frame);
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>     CORE_ADDR lr, cpsr;
>     ULONGEST t_bit = arm_psr_thumb_bit (gdbarch);
>   
> @@ -4154,7 +4154,7 @@ arm_vfp_call_candidate (struct type *t, enum arm_vfp_cprc_base_type *base_type,
>   static int
>   arm_vfp_abi_for_function (struct gdbarch *gdbarch, struct type *func_type)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     /* Variadic functions always use the base ABI.  Assume that functions
>        without debug info are not variadic.  */
> @@ -4188,7 +4188,7 @@ arm_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>     int use_vfp_abi;
>     struct type *ftype;
>     unsigned vfp_regs_free = (1 << 16) - 1;
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     /* Determine the type of this function and whether the VFP ABI
>        applies.  */
> @@ -4460,7 +4460,7 @@ arm_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
>   static struct type *
>   arm_ext_type (struct gdbarch *gdbarch)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->arm_ext_type)
>       tdep->arm_ext_type
> @@ -4473,7 +4473,7 @@ arm_ext_type (struct gdbarch *gdbarch)
>   static struct type *
>   arm_neon_double_type (struct gdbarch *gdbarch)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->neon_double_type == NULL)
>       {
> @@ -4512,7 +4512,7 @@ arm_neon_double_type (struct gdbarch *gdbarch)
>   static struct type *
>   arm_neon_quad_type (struct gdbarch *gdbarch)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->neon_quad_type == NULL)
>       {
> @@ -4550,7 +4550,7 @@ arm_neon_quad_type (struct gdbarch *gdbarch)
>   static bool
>   is_q_pseudo (struct gdbarch *gdbarch, int regnum)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     /* Q pseudo registers are available for both NEON (Q0~Q15) and
>        MVE (Q0~Q7) features.  */
> @@ -4571,7 +4571,7 @@ is_q_pseudo (struct gdbarch *gdbarch, int regnum)
>   static bool
>   is_s_pseudo (struct gdbarch *gdbarch, int regnum)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->have_s_pseudos
>         && regnum >= tdep->s_pseudo_base
> @@ -4590,7 +4590,7 @@ is_s_pseudo (struct gdbarch *gdbarch, int regnum)
>   static bool
>   is_mve_pseudo (struct gdbarch *gdbarch, int regnum)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->have_mve
>         && regnum >= tdep->mve_pseudo_base
> @@ -4609,7 +4609,7 @@ is_mve_pseudo (struct gdbarch *gdbarch, int regnum)
>   static bool
>   is_pacbti_pseudo (struct gdbarch *gdbarch, int regnum)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->have_pacbti
>         && regnum >= tdep->pacbti_pseudo_base
> @@ -4625,7 +4625,7 @@ is_pacbti_pseudo (struct gdbarch *gdbarch, int regnum)
>   static struct type *
>   arm_register_type (struct gdbarch *gdbarch, int regnum)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (is_s_pseudo (gdbarch, regnum))
>       return builtin_type (gdbarch)->builtin_float;
> @@ -4704,7 +4704,7 @@ arm_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
>     /* PACBTI register containing the Pointer Authentication Code.  */
>     if (reg == ARM_DWARF_RA_AUTH_CODE)
>       {
> -      arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>         if (tdep->have_pacbti)
>   	return tdep->pacbti_pseudo_base;
> @@ -4850,7 +4850,7 @@ arm_adjust_breakpoint_address (struct gdbarch *gdbarch, CORE_ADDR bpaddr)
>     int buf_len;
>     enum bfd_endian order = gdbarch_byte_order_for_code (gdbarch);
>     int i, any, last_it, last_it_count;
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     /* If we are using BKPT breakpoints, none of this is necessary.  */
>     if (tdep->thumb2_breakpoint == NULL)
> @@ -8158,7 +8158,7 @@ arm_displaced_init_closure (struct gdbarch *gdbarch, CORE_ADDR from,
>   			    CORE_ADDR to,
>   			    arm_displaced_step_copy_insn_closure *dsc)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>     unsigned int i, len, offset;
>     enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
>     int size = dsc->is_thumb? 2 : 4;
> @@ -8321,7 +8321,7 @@ static const gdb_byte arm_default_thumb_be_breakpoint[] = THUMB_BE_BREAKPOINT;
>   static int
>   arm_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
>   
>     if (arm_pc_is_thumb (gdbarch, *pcptr))
> @@ -8356,7 +8356,7 @@ arm_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
>   static const gdb_byte *
>   arm_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     switch (kind)
>       {
> @@ -8428,7 +8428,7 @@ arm_extract_return_value (struct type *type, struct regcache *regs,
>   {
>     struct gdbarch *gdbarch = regs->arch ();
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (TYPE_CODE_FLT == type->code ())
>       {
> @@ -8539,7 +8539,7 @@ arm_return_in_memory (struct gdbarch *gdbarch, struct type *type)
>         return (TYPE_LENGTH (type) > 16);
>       }
>   
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>     if (tdep->arm_abi != ARM_ABI_APCS)
>       {
>         /* The AAPCS says all aggregates not larger than a word are returned
> @@ -8645,7 +8645,7 @@ arm_store_return_value (struct type *type, struct regcache *regs,
>     if (type->code () == TYPE_CODE_FLT)
>       {
>         gdb_byte buf[ARM_FP_REGISTER_SIZE];
> -      arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>         switch (tdep->fp_model)
>   	{
> @@ -8734,7 +8734,7 @@ arm_return_value (struct gdbarch *gdbarch, struct value *function,
>   		  struct type *valtype, struct regcache *regcache,
>   		  gdb_byte *readbuf, const gdb_byte *writebuf)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>     struct type *func_type = function ? value_type (function) : NULL;
>     enum arm_vfp_cprc_base_type vfp_base_type;
>     int vfp_base_count;
> @@ -8826,7 +8826,7 @@ static int
>   arm_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (frame);
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     CORE_ADDR jb_addr;
>     gdb_byte buf[ARM_INT_REGISTER_SIZE];
> @@ -9019,7 +9019,7 @@ show_fp_model (struct ui_file *file, int from_tty,
>         && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm)
>       {
>         arm_gdbarch_tdep *tdep
> -	= (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
> +	= gdbarch_tdep<arm_gdbarch_tdep> (target_gdbarch ());
>   
>         gdb_printf (file, _("\
>   The current ARM floating point model is \"auto\" (currently \"%s\").\n"),
> @@ -9059,7 +9059,7 @@ arm_show_abi (struct ui_file *file, int from_tty,
>         && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm)
>       {
>         arm_gdbarch_tdep *tdep
> -	= (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
> +	= gdbarch_tdep<arm_gdbarch_tdep> (target_gdbarch ());
>   
>         gdb_printf (file, _("\
>   The current ARM ABI is \"auto\" (currently \"%s\").\n"),
> @@ -9138,7 +9138,7 @@ show_disassembly_style_sfunc (struct ui_file *file, int from_tty,
>   static const char *
>   arm_register_name (struct gdbarch *gdbarch, int i)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (is_s_pseudo (gdbarch, i))
>       {
> @@ -9309,7 +9309,7 @@ static enum register_status
>   arm_mve_pseudo_read (struct gdbarch *gdbarch, readable_regcache *regcache,
>   		     int regnum, gdb_byte *buf)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     /* P0 is the first 16 bits of VPR.  */
>     return regcache->raw_read_part (tdep->mve_vpr_regnum, 0, 2, buf);
> @@ -9323,7 +9323,7 @@ arm_pseudo_read (struct gdbarch *gdbarch, readable_regcache *regcache,
>     char name_buf[4];
>     gdb_byte reg_buf[8];
>     int offset, double_regnum;
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     gdb_assert (regnum >= num_regs);
>   
> @@ -9395,7 +9395,7 @@ static void
>   arm_mve_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache,
>   		      int regnum, const gdb_byte *buf)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     /* P0 is the first 16 bits of VPR.  */
>     regcache->raw_write_part (tdep->mve_vpr_regnum, 0, 2, buf);
> @@ -9409,7 +9409,7 @@ arm_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache,
>     char name_buf[4];
>     gdb_byte reg_buf[8];
>     int offset, double_regnum;
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     gdb_assert (regnum >= num_regs);
>   
> @@ -9497,7 +9497,7 @@ arm_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
>   static void
>   arm_register_g_packet_guesses (struct gdbarch *gdbarch)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->is_m)
>       {
> @@ -9540,7 +9540,7 @@ arm_register_g_packet_guesses (struct gdbarch *gdbarch)
>   static int
>   arm_code_of_frame_writable (struct gdbarch *gdbarch, struct frame_info *frame)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->is_m && get_frame_type (frame) == SIGTRAMP_FRAME)
>       {
> @@ -10099,7 +10099,7 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
>       {
>         arm_gdbarch_tdep *tdep
> -	= (arm_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
> +	= gdbarch_tdep<arm_gdbarch_tdep> (best_arch->gdbarch);
>   
>         if (arm_abi != ARM_ABI_AUTO && arm_abi != tdep->arm_abi)
>   	continue;
> @@ -10419,7 +10419,7 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>   static void
>   arm_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (tdep == NULL)
>       return;
> @@ -12628,7 +12628,7 @@ arm_record_coproc_data_proc (insn_decode_record *arm_insn_r)
>   {
>     uint32_t op, op1_ebit, coproc, bits_24_25;
>     arm_gdbarch_tdep *tdep
> -    = (arm_gdbarch_tdep *) gdbarch_tdep (arm_insn_r->gdbarch);
> +    = gdbarch_tdep<arm_gdbarch_tdep> (arm_insn_r->gdbarch);
>     struct regcache *reg_cache = arm_insn_r->regcache;
>   
>     arm_insn_r->opcode = bits (arm_insn_r->arm_insn, 24, 27);
> @@ -13116,7 +13116,7 @@ static int
>   thumb_record_ldm_stm_swi (insn_decode_record *thumb_insn_r)
>   {
>     arm_gdbarch_tdep *tdep
> -    = (arm_gdbarch_tdep *) gdbarch_tdep  (thumb_insn_r->gdbarch);
> +    = gdbarch_tdep<arm_gdbarch_tdep>  (thumb_insn_r->gdbarch);
>     struct regcache *reg_cache = thumb_insn_r->regcache;
>   
>     uint32_t ret = 0; /* function return value: -1:record failure ;  0:success  */
> diff --git a/gdb/arm-wince-tdep.c b/gdb/arm-wince-tdep.c
> index 354c6fbca7f..5063b308809 100644
> --- a/gdb/arm-wince-tdep.c
> +++ b/gdb/arm-wince-tdep.c
> @@ -115,7 +115,7 @@ arm_wince_skip_main_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
>   static void
>   arm_wince_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     windows_init_abi (info, gdbarch);
>   
> diff --git a/gdb/avr-tdep.c b/gdb/avr-tdep.c
> index 9e73c507b2e..30042162edb 100644
> --- a/gdb/avr-tdep.c
> +++ b/gdb/avr-tdep.c
> @@ -232,7 +232,7 @@ avr_register_type (struct gdbarch *gdbarch, int reg_nr)
>     if (reg_nr == AVR_PC_REGNUM)
>       return builtin_type (gdbarch)->builtin_uint32;
>   
> -  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
>     if (reg_nr == AVR_PSEUDO_PC_REGNUM)
>       return tdep->pc_type;
>   
> @@ -750,7 +750,7 @@ avr_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR pc_beg, CORE_ADDR pc_end,
>     gdb_assert (vpc < AVR_MAX_PROLOGUE_SIZE);
>   
>     /* Handle static small stack allocation using rcall or push.  */
> -  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
>     while (scan_stage == 1 && vpc < len)
>       {
>         insn = extract_unsigned_integer (&prologue[vpc], 2, byte_order);
> @@ -1053,7 +1053,7 @@ avr_frame_unwind_cache (struct frame_info *this_frame,
>   
>     /* The previous frame's SP needed to be computed.  Save the computed
>        value.  */
> -  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
>     info->saved_regs[AVR_SP_REGNUM].set_value (info->prev_sp
>   					     - 1 + tdep->call_length);
>   
> @@ -1135,7 +1135,7 @@ avr_frame_prev_register (struct frame_info *this_frame,
>   	  int i;
>   	  gdb_byte buf[3];
>   	  struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -	  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +	  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
>   
>   	  read_memory (info->saved_regs[AVR_PC_REGNUM].addr (),
>   		       buf, tdep->call_length);
> @@ -1277,7 +1277,7 @@ avr_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>   {
>     int i;
>     gdb_byte buf[3];
> -  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
>     int call_length = tdep->call_length;
>     CORE_ADDR return_pc = avr_convert_iaddr_to_raw (bp_addr);
>     int regnum = AVR_ARGN_REGNUM;
> @@ -1461,7 +1461,7 @@ avr_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
>       {
>         avr_gdbarch_tdep *tdep
> -	= (avr_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
> +	= gdbarch_tdep<avr_gdbarch_tdep> (best_arch->gdbarch);
>   
>         if (tdep->call_length == call_length)
>   	return best_arch->gdbarch;
> diff --git a/gdb/bfin-tdep.c b/gdb/bfin-tdep.c
> index 573eed94793..f232e22c37c 100644
> --- a/gdb/bfin-tdep.c
> +++ b/gdb/bfin-tdep.c
> @@ -766,7 +766,7 @@ bfin_frame_align (struct gdbarch *gdbarch, CORE_ADDR address)
>   enum bfin_abi
>   bfin_abi (struct gdbarch *gdbarch)
>   {
> -  bfin_gdbarch_tdep *tdep = (bfin_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  bfin_gdbarch_tdep *tdep = gdbarch_tdep<bfin_gdbarch_tdep> (gdbarch);
>     return tdep->bfin_abi;
>   }
>   
> @@ -792,7 +792,7 @@ bfin_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          arches = gdbarch_list_lookup_by_info (arches->next, &info))
>       {
>         bfin_gdbarch_tdep *tdep
> -	= (bfin_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<bfin_gdbarch_tdep> (arches->gdbarch);
>   
>         if (tdep->bfin_abi != abi)
>   	continue;
> diff --git a/gdb/cris-linux-tdep.c b/gdb/cris-linux-tdep.c
> index f55f9b9083c..b3ed7450e99 100644
> --- a/gdb/cris-linux-tdep.c
> +++ b/gdb/cris-linux-tdep.c
> @@ -33,7 +33,7 @@
>   static void
>   cris_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
>   
>     linux_init_abi (info, gdbarch, 0);
>   
> diff --git a/gdb/cris-tdep.c b/gdb/cris-tdep.c
> index 898d277b3fe..7cd73d34ca6 100644
> --- a/gdb/cris-tdep.c
> +++ b/gdb/cris-tdep.c
> @@ -313,7 +313,7 @@ cris_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
>   				  void **this_cache)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     struct cris_unwind_cache *info;
>     CORE_ADDR addr;
> @@ -450,7 +450,7 @@ static int
>   crisv32_single_step_through_delay (struct gdbarch *gdbarch,
>   				   struct frame_info *this_frame)
>   {
> -  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
>     ULONGEST erp;
>     int ret = 0;
>   
> @@ -695,7 +695,7 @@ cris_frame_unwind_cache (struct frame_info *this_frame,
>   			 void **this_prologue_cache)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
>     struct cris_unwind_cache *info;
>   
>     if ((*this_prologue_cache))
> @@ -1333,7 +1333,7 @@ crisv32_scan_prologue (CORE_ADDR pc, struct frame_info *this_frame,
>   static CORE_ADDR
>   cris_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
>   {
> -  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
>     CORE_ADDR func_addr, func_end;
>     struct symtab_and_line sal;
>     CORE_ADDR pc_after_prologue;
> @@ -1368,7 +1368,7 @@ cris_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
>   static const gdb_byte *
>   cris_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
>   {
> -  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
>     static unsigned char break8_insn[] = {0x38, 0xe9};
>     static unsigned char break15_insn[] = {0x3f, 0xe9};
>   
> @@ -1387,7 +1387,7 @@ static int
>   cris_spec_reg_applicable (struct gdbarch *gdbarch,
>   			  struct cris_spec_reg spec_reg)
>   {
> -  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
>     unsigned int version = tdep->cris_version;
>     
>     switch (spec_reg.applicable_version)
> @@ -3766,7 +3766,7 @@ cris_supply_gregset (const struct regset *regset, struct regcache *regcache,
>   		     int regnum, const void *gregs, size_t len)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
>     int i;
>     const cris_elf_greg_t *regp = static_cast<const cris_elf_greg_t *>(gregs);
>   
> @@ -3860,7 +3860,7 @@ Makes GDB use the NRP register instead of the ERP register in certain cases."),
>   static void
>   cris_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
>   {
> -  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
>     if (tdep != NULL)
>       {
>         gdb_printf (file, "cris_dump_tdep: tdep->cris_version = %i\n",
> @@ -3940,7 +3940,7 @@ cris_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          arches = gdbarch_list_lookup_by_info (arches->next, &info))
>       {
>         cris_gdbarch_tdep *tdep
> -	= (cris_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<cris_gdbarch_tdep> (arches->gdbarch);
>   
>         if (tdep->cris_version == usr_cmd_cris_version
>   	  && tdep->cris_mode == usr_cmd_cris_mode
> diff --git a/gdb/frv-tdep.c b/gdb/frv-tdep.c
> index 2328791a540..34f437764a9 100644
> --- a/gdb/frv-tdep.c
> +++ b/gdb/frv-tdep.c
> @@ -93,7 +93,7 @@ struct frv_gdbarch_tdep : gdbarch_tdep
>   enum frv_abi
>   frv_abi (struct gdbarch *gdbarch)
>   {
> -  frv_gdbarch_tdep *tdep = (frv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  frv_gdbarch_tdep *tdep = gdbarch_tdep<frv_gdbarch_tdep> (gdbarch);
>     return tdep->frv_abi;
>   }
>   
> @@ -275,7 +275,7 @@ frv_register_name (struct gdbarch *gdbarch, int reg)
>     if (reg >= frv_num_regs + frv_num_pseudo_regs)
>       return "?toolarge?";
>   
> -  frv_gdbarch_tdep *tdep = (frv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  frv_gdbarch_tdep *tdep = gdbarch_tdep<frv_gdbarch_tdep> (gdbarch);
>     return tdep->register_names[reg];
>   }
>   
> diff --git a/gdb/ft32-tdep.c b/gdb/ft32-tdep.c
> index f77e313e0dd..024ca47ce4d 100644
> --- a/gdb/ft32-tdep.c
> +++ b/gdb/ft32-tdep.c
> @@ -110,7 +110,7 @@ ft32_register_type (struct gdbarch *gdbarch, int reg_nr)
>   {
>     if (reg_nr == FT32_PC_REGNUM)
>       {
> -      ft32_gdbarch_tdep *tdep = (ft32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      ft32_gdbarch_tdep *tdep = gdbarch_tdep<ft32_gdbarch_tdep> (gdbarch);
>         return tdep->pc_type;
>       }
>     else if (reg_nr == FT32_SP_REGNUM || reg_nr == FT32_FP_REGNUM)
> diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
> index 3a7b7f92ef7..b2c91db0c4f 100644
> --- a/gdb/gdbarch.h
> +++ b/gdb/gdbarch.h
> @@ -142,8 +142,23 @@ using read_core_file_mappings_loop_ftype =
>   
>   #include "gdbarch-gen.h"
>   
> -extern struct gdbarch_tdep *gdbarch_tdep (struct gdbarch *gdbarch);
> +/* An internal function that should _only_ be called from gdbarch_tdep.
> +   Returns the gdbarch_tdep field held within GDBARCH.  */
>   
> +extern struct gdbarch_tdep *gdbarch_tdep_1 (struct gdbarch *gdbarch);
> +
> +/* Return the gdbarch_tdep object held within GDBARCH cast to the type
> +   TDepType, which should be a sub-class of gdbarch_tdep.  There is no
> +   checking done that the gdbarch_tdep within GDBARCH actually is of the
> +   type TDepType, we just assume the caller knows what they are doing.  */
> +
> +template<typename TDepType>
> +static inline TDepType *
> +gdbarch_tdep (struct gdbarch *gdbarch)
> +{
> +  struct gdbarch_tdep *tdep = gdbarch_tdep_1 (gdbarch);
> +  return static_cast<TDepType *> (tdep);
> +}
>   
>   /* Mechanism for co-ordinating the selection of a specific
>      architecture.
> diff --git a/gdb/hppa-bsd-tdep.c b/gdb/hppa-bsd-tdep.c
> index 34f57d2512a..c405511529d 100644
> --- a/gdb/hppa-bsd-tdep.c
> +++ b/gdb/hppa-bsd-tdep.c
> @@ -118,7 +118,7 @@ hppabsd_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
>   void
>   hppabsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
>   
>     /* OpenBSD and NetBSD have a 64-bit 'long double'.  */
>     set_gdbarch_long_double_bit (gdbarch, 64);
> diff --git a/gdb/hppa-linux-tdep.c b/gdb/hppa-linux-tdep.c
> index 40e32c115d2..f17d2ae6b02 100644
> --- a/gdb/hppa-linux-tdep.c
> +++ b/gdb/hppa-linux-tdep.c
> @@ -476,7 +476,7 @@ hppa_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   					 void *cb_data,
>   					 const struct regcache *regcache)
>   {
> -  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
>   
>     cb (".reg", 80 * tdep->bytes_per_address, 80 * tdep->bytes_per_address,
>         &hppa_linux_regset, NULL, cb_data);
> @@ -486,7 +486,7 @@ hppa_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   static void
>   hppa_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
>   
>     linux_init_abi (info, gdbarch, 0);
>   
> diff --git a/gdb/hppa-tdep.c b/gdb/hppa-tdep.c
> index f9ececbb04f..9f93a945a6a 100644
> --- a/gdb/hppa-tdep.c
> +++ b/gdb/hppa-tdep.c
> @@ -247,7 +247,7 @@ internalize_unwinds (struct objfile *objfile, struct unwind_table_entry *table,
>     if (size > 0)
>       {
>         struct gdbarch *gdbarch = objfile->arch ();
> -      hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
>         unsigned long tmp;
>         unsigned i;
>         char *buf = (char *) alloca (size);
> @@ -718,7 +718,7 @@ hppa32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>     /* Global pointer (r19) of the function we are trying to call.  */
>     CORE_ADDR gp;
>   
> -  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
>   
>     for (write_pass = 0; write_pass < 2; write_pass++)
>       {
> @@ -955,7 +955,7 @@ hppa64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>   			function_call_return_method return_method,
>   			CORE_ADDR struct_addr)
>   {
> -  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     int i, offset = 0;
>     CORE_ADDR gp;
> @@ -2241,7 +2241,7 @@ hppa_frame_cache (struct frame_info *this_frame, void **this_cache)
>     }
>   
>     {
> -    hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +    hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
>   
>       if (tdep->unwind_adjust_stub)
>         tdep->unwind_adjust_stub (this_frame, cache->base, cache->saved_regs);
> @@ -2471,7 +2471,7 @@ hppa_stub_unwind_sniffer (const struct frame_unwind *self,
>   {
>     CORE_ADDR pc = get_frame_address_in_block (this_frame);
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
>   
>     if (pc == 0
>         || (tdep->in_solib_call_trampoline != NULL
> @@ -3147,7 +3147,7 @@ hppa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>   static void
>   hppa_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
>   {
> -  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
>   
>     gdb_printf (file, "bytes_per_address = %d\n",
>   	      tdep->bytes_per_address);
> diff --git a/gdb/i386-bsd-tdep.c b/gdb/i386-bsd-tdep.c
> index b38f8d05887..dbbd3c786c3 100644
> --- a/gdb/i386-bsd-tdep.c
> +++ b/gdb/i386-bsd-tdep.c
> @@ -74,7 +74,7 @@ int i386bsd_sc_reg_offset[] =
>   void
>   i386bsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     tdep->jb_pc_offset = 0;
>   
> diff --git a/gdb/i386-darwin-tdep.c b/gdb/i386-darwin-tdep.c
> index dc780583766..2a9198aceb3 100644
> --- a/gdb/i386-darwin-tdep.c
> +++ b/gdb/i386-darwin-tdep.c
> @@ -156,7 +156,7 @@ i386_darwin_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>   			     function_call_return_method return_method,
>   			     CORE_ADDR struct_addr)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     gdb_byte buf[4];
>     int i;
> @@ -248,7 +248,7 @@ i386_darwin_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>   static void
>   i386_darwin_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* We support the SSE registers.  */
>     tdep->num_xmm_regs = I386_NUM_XREGS - 1;
> diff --git a/gdb/i386-fbsd-tdep.c b/gdb/i386-fbsd-tdep.c
> index d68498cd5e9..b7a524db68c 100644
> --- a/gdb/i386-fbsd-tdep.c
> +++ b/gdb/i386-fbsd-tdep.c
> @@ -325,7 +325,7 @@ i386fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   				       void *cb_data,
>   				       const struct regcache *regcache)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     cb (".reg", I386_FBSD_SIZEOF_GREGSET, I386_FBSD_SIZEOF_GREGSET,
>         &i386_fbsd_gregset, NULL, cb_data);
> @@ -365,7 +365,7 @@ i386fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
>   static void
>   i386fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* Generic FreeBSD support. */
>     fbsd_init_abi (info, gdbarch);
> diff --git a/gdb/i386-gnu-tdep.c b/gdb/i386-gnu-tdep.c
> index 51c253d2dfe..3d97fe36a85 100644
> --- a/gdb/i386-gnu-tdep.c
> +++ b/gdb/i386-gnu-tdep.c
> @@ -173,7 +173,7 @@ static int i386gnu_gregset_reg_offset[] =
>   static void
>   i386gnu_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* GNU uses ELF.  */
>     i386_elf_init_abi (info, gdbarch);
> diff --git a/gdb/i386-go32-tdep.c b/gdb/i386-go32-tdep.c
> index 15ac38dc12f..0c0c08e3579 100644
> --- a/gdb/i386-go32-tdep.c
> +++ b/gdb/i386-go32-tdep.c
> @@ -26,7 +26,7 @@
>   static void
>   i386_go32_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* DJGPP doesn't have any special frames for signal handlers.  */
>     tdep->sigtramp_p = NULL;
> diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c
> index 5d7f54194af..6033104230f 100644
> --- a/gdb/i386-linux-tdep.c
> +++ b/gdb/i386-linux-tdep.c
> @@ -763,7 +763,7 @@ i386_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   					 void *cb_data,
>   					 const struct regcache *regcache)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     cb (".reg", 68, 68, &i386_gregset, NULL, cb_data);
>   
> @@ -825,7 +825,7 @@ i386_linux_displaced_step_copy_insn (struct gdbarch *gdbarch,
>   static void
>   i386_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     const struct target_desc *tdesc = info.target_desc;
>     struct tdesc_arch_data *tdesc_data = info.tdesc_data;
>     const struct tdesc_feature *feature;
> diff --git a/gdb/i386-netbsd-tdep.c b/gdb/i386-netbsd-tdep.c
> index 2cee1b94760..a9ebc3dd827 100644
> --- a/gdb/i386-netbsd-tdep.c
> +++ b/gdb/i386-netbsd-tdep.c
> @@ -372,7 +372,7 @@ i386nbsd_sigtramp_cache_init (const struct tramp_frame *self,
>   static void
>   i386nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* Obviously NetBSD is BSD-based.  */
>     i386bsd_init_abi (info, gdbarch);
> @@ -407,7 +407,7 @@ i386nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   static void
>   i386nbsdelf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* It's still NetBSD.  */
>     i386nbsd_init_abi (info, gdbarch);
> diff --git a/gdb/i386-nto-tdep.c b/gdb/i386-nto-tdep.c
> index 6716329149b..259867f262b 100644
> --- a/gdb/i386-nto-tdep.c
> +++ b/gdb/i386-nto-tdep.c
> @@ -77,7 +77,7 @@ static void
>   i386nto_supply_gregset (struct regcache *regcache, char *gpregs)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     gdb_assert (tdep->gregset_reg_offset == i386nto_gregset_reg_offset);
>     i386_gregset.supply_regset (&i386_gregset, regcache, -1,
> @@ -126,7 +126,7 @@ static int
>   i386nto_register_area (struct gdbarch *gdbarch,
>   		       int regno, int regset, unsigned *off)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     *off = 0;
>     if (regset == NTO_REG_GENERAL)
> @@ -315,7 +315,7 @@ init_i386nto_ops (void)
>   static void
>   i386nto_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     static struct target_so_ops nto_svr4_so_ops;
>   
>     /* Deal with our strange signals.  */
> diff --git a/gdb/i386-obsd-tdep.c b/gdb/i386-obsd-tdep.c
> index b1f4d6c5e8d..798094509c6 100644
> --- a/gdb/i386-obsd-tdep.c
> +++ b/gdb/i386-obsd-tdep.c
> @@ -407,7 +407,7 @@ static const struct frame_unwind i386obsd_trapframe_unwind = {
>   static void
>   i386obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* Obviously OpenBSD is BSD-based.  */
>     i386bsd_init_abi (info, gdbarch);
> diff --git a/gdb/i386-sol2-tdep.c b/gdb/i386-sol2-tdep.c
> index e8a3ba20045..5ee108d3578 100644
> --- a/gdb/i386-sol2-tdep.c
> +++ b/gdb/i386-sol2-tdep.c
> @@ -65,7 +65,7 @@ i386_sol2_mcontext_addr (struct frame_info *this_frame)
>   static void
>   i386_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* Solaris is SVR4-based.  */
>     i386_svr4_init_abi (info, gdbarch);
> diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
> index 8501e12e241..d500f6998c5 100644
> --- a/gdb/i386-tdep.c
> +++ b/gdb/i386-tdep.c
> @@ -169,7 +169,7 @@ const int num_lower_zmm_regs = 16;
>   static int
>   i386_mmx_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int mm0_regnum = tdep->mm0_regnum;
>   
>     if (mm0_regnum < 0)
> @@ -184,7 +184,7 @@ i386_mmx_regnum_p (struct gdbarch *gdbarch, int regnum)
>   int
>   i386_byte_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     regnum -= tdep->al_regnum;
>     return regnum >= 0 && regnum < tdep->num_byte_regs;
> @@ -195,7 +195,7 @@ i386_byte_regnum_p (struct gdbarch *gdbarch, int regnum)
>   int
>   i386_word_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     regnum -= tdep->ax_regnum;
>     return regnum >= 0 && regnum < tdep->num_word_regs;
> @@ -206,7 +206,7 @@ i386_word_regnum_p (struct gdbarch *gdbarch, int regnum)
>   int
>   i386_dword_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int eax_regnum = tdep->eax_regnum;
>   
>     if (eax_regnum < 0)
> @@ -221,7 +221,7 @@ i386_dword_regnum_p (struct gdbarch *gdbarch, int regnum)
>   int
>   i386_zmmh_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int zmm0h_regnum = tdep->zmm0h_regnum;
>   
>     if (zmm0h_regnum < 0)
> @@ -234,7 +234,7 @@ i386_zmmh_regnum_p (struct gdbarch *gdbarch, int regnum)
>   int
>   i386_zmm_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int zmm0_regnum = tdep->zmm0_regnum;
>   
>     if (zmm0_regnum < 0)
> @@ -247,7 +247,7 @@ i386_zmm_regnum_p (struct gdbarch *gdbarch, int regnum)
>   int
>   i386_k_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int k0_regnum = tdep->k0_regnum;
>   
>     if (k0_regnum < 0)
> @@ -260,7 +260,7 @@ i386_k_regnum_p (struct gdbarch *gdbarch, int regnum)
>   static int
>   i386_ymmh_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int ymm0h_regnum = tdep->ymm0h_regnum;
>   
>     if (ymm0h_regnum < 0)
> @@ -275,7 +275,7 @@ i386_ymmh_regnum_p (struct gdbarch *gdbarch, int regnum)
>   int
>   i386_ymm_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int ymm0_regnum = tdep->ymm0_regnum;
>   
>     if (ymm0_regnum < 0)
> @@ -288,7 +288,7 @@ i386_ymm_regnum_p (struct gdbarch *gdbarch, int regnum)
>   static int
>   i386_ymmh_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int ymm16h_regnum = tdep->ymm16h_regnum;
>   
>     if (ymm16h_regnum < 0)
> @@ -301,7 +301,7 @@ i386_ymmh_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
>   int
>   i386_ymm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int ymm16_regnum = tdep->ymm16_regnum;
>   
>     if (ymm16_regnum < 0)
> @@ -316,7 +316,7 @@ i386_ymm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
>   int
>   i386_bnd_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int bnd0_regnum = tdep->bnd0_regnum;
>   
>     if (bnd0_regnum < 0)
> @@ -331,7 +331,7 @@ i386_bnd_regnum_p (struct gdbarch *gdbarch, int regnum)
>   int
>   i386_xmm_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int num_xmm_regs = I387_NUM_XMM_REGS (tdep);
>   
>     if (num_xmm_regs == 0)
> @@ -346,7 +346,7 @@ i386_xmm_regnum_p (struct gdbarch *gdbarch, int regnum)
>   int
>   i386_xmm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int num_xmm_avx512_regs = I387_NUM_XMM_AVX512_REGS (tdep);
>   
>     if (num_xmm_avx512_regs == 0)
> @@ -359,7 +359,7 @@ i386_xmm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
>   static int
>   i386_mxcsr_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     if (I387_NUM_XMM_REGS (tdep) == 0)
>       return 0;
> @@ -372,7 +372,7 @@ i386_mxcsr_regnum_p (struct gdbarch *gdbarch, int regnum)
>   int
>   i386_fp_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     if (I387_ST0_REGNUM (tdep) < 0)
>       return 0;
> @@ -384,7 +384,7 @@ i386_fp_regnum_p (struct gdbarch *gdbarch, int regnum)
>   int
>   i386_fpc_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     if (I387_ST0_REGNUM (tdep) < 0)
>       return 0;
> @@ -398,7 +398,7 @@ i386_fpc_regnum_p (struct gdbarch *gdbarch, int regnum)
>   static int
>   i386_bndr_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>      if (I387_BND0R_REGNUM (tdep) < 0)
>        return 0;
> @@ -412,7 +412,7 @@ i386_bndr_regnum_p (struct gdbarch *gdbarch, int regnum)
>   static int
>   i386_mpx_ctrl_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>      if (I387_BNDCFGU_REGNUM (tdep) < 0)
>        return 0;
> @@ -426,7 +426,7 @@ i386_mpx_ctrl_regnum_p (struct gdbarch *gdbarch, int regnum)
>   bool
>   i386_pkru_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int pkru_regnum = tdep->pkru_regnum;
>   
>     if (pkru_regnum < 0)
> @@ -462,7 +462,7 @@ i386_register_name (struct gdbarch *gdbarch, int regnum)
>   const char *
>   i386_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     if (i386_bnd_regnum_p (gdbarch, regnum))
>       return i386_bnd_names[regnum - tdep->bnd0_regnum];
>     if (i386_mmx_regnum_p (gdbarch, regnum))
> @@ -485,7 +485,7 @@ i386_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
>   static int
>   i386_dbx_reg_to_regnum (struct gdbarch *gdbarch, int reg)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* This implements what GCC calls the "default" register map
>        (dbx_register_map[]).  */
> @@ -532,7 +532,7 @@ i386_dbx_reg_to_regnum (struct gdbarch *gdbarch, int reg)
>   static int
>   i386_svr4_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* This implements the GCC register map that tries to be compatible
>        with the SVR4 C compiler for DWARF (svr4_dbx_register_map[]).  */
> @@ -2434,7 +2434,7 @@ static struct i386_frame_cache *
>   i386_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     struct i386_frame_cache *cache;
>     CORE_ADDR addr;
> @@ -2524,7 +2524,7 @@ i386_sigtramp_frame_sniffer (const struct frame_unwind *self,
>   			     void **this_prologue_cache)
>   {
>     gdbarch *arch = get_frame_arch (this_frame);
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
>   
>     /* We shouldn't even bother if we don't have a sigcontext_addr
>        handler.  */
> @@ -2611,7 +2611,7 @@ i386_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
>     CORE_ADDR sp, jb_addr;
>     struct gdbarch *gdbarch = get_frame_arch (frame);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int jb_pc_offset = tdep->jb_pc_offset;
>   
>     /* If JB_PC_OFFSET is -1, we have no way to find out where the
> @@ -2860,7 +2860,7 @@ static void
>   i386_extract_return_value (struct gdbarch *gdbarch, struct type *type,
>   			   struct regcache *regcache, gdb_byte *valbuf)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int len = TYPE_LENGTH (type);
>     gdb_byte buf[I386_MAX_REGISTER_SIZE];
>   
> @@ -2918,7 +2918,7 @@ static void
>   i386_store_return_value (struct gdbarch *gdbarch, struct type *type,
>   			 struct regcache *regcache, const gdb_byte *valbuf)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int len = TYPE_LENGTH (type);
>   
>     if (type->code () == TYPE_CODE_FLT)
> @@ -2997,7 +2997,7 @@ static const char *struct_convention = default_struct_convention;
>   static int
>   i386_reg_struct_return_p (struct gdbarch *gdbarch, struct type *type)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     enum type_code code = type->code ();
>     int len = TYPE_LENGTH (type);
>   
> @@ -3099,7 +3099,7 @@ i386_return_value (struct gdbarch *gdbarch, struct value *function,
>   struct type *
>   i387_ext_type (struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->i387_ext_type)
>       {
> @@ -3117,7 +3117,7 @@ i387_ext_type (struct gdbarch *gdbarch)
>   static struct type *
>   i386_bnd_type (struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>   
>     if (!tdep->i386_bnd_type)
> @@ -3153,7 +3153,7 @@ i386_bnd_type (struct gdbarch *gdbarch)
>   static struct type *
>   i386_zmm_type (struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->i386_zmm_type)
>       {
> @@ -3212,7 +3212,7 @@ i386_zmm_type (struct gdbarch *gdbarch)
>   static struct type *
>   i386_ymm_type (struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->i386_ymm_type)
>       {
> @@ -3269,7 +3269,7 @@ i386_ymm_type (struct gdbarch *gdbarch)
>   static struct type *
>   i386_mmx_type (struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->i386_mmx_type)
>       {
> @@ -3346,7 +3346,7 @@ static int
>   i386_mmx_regnum_to_fp_regnum (readable_regcache *regcache, int regnum)
>   {
>     gdbarch *arch = regcache->arch ();
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
>     int mmxreg, fpreg;
>     ULONGEST fstat;
>     int tos;
> @@ -3387,7 +3387,7 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
>       }
>     else
>       {
> -      i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>         if (i386_bnd_regnum_p (gdbarch, regnum))
>   	{
>   	  regnum -= tdep->bnd0_regnum;
> @@ -3577,7 +3577,7 @@ i386_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
>       }
>     else
>       {
> -      i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>         if (i386_bnd_regnum_p (gdbarch, regnum))
>   	{
> @@ -3685,7 +3685,7 @@ int
>   i386_ax_pseudo_register_collect (struct gdbarch *gdbarch,
>   				 struct agent_expr *ax, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     if (i386_mmx_regnum_p (gdbarch, regnum))
>       {
> @@ -3902,7 +3902,7 @@ i386_supply_gregset (const struct regset *regset, struct regcache *regcache,
>   		     int regnum, const void *gregs, size_t len)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     const gdb_byte *regs = (const gdb_byte *) gregs;
>     int i;
>   
> @@ -3927,7 +3927,7 @@ i386_collect_gregset (const struct regset *regset,
>   		      int regnum, void *gregs, size_t len)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     gdb_byte *regs = (gdb_byte *) gregs;
>     int i;
>   
> @@ -3950,7 +3950,7 @@ i386_supply_fpregset (const struct regset *regset, struct regcache *regcache,
>   		      int regnum, const void *fpregs, size_t len)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     if (len == I387_SIZEOF_FXSAVE)
>       {
> @@ -3973,7 +3973,7 @@ i386_collect_fpregset (const struct regset *regset,
>   		       int regnum, void *fpregs, size_t len)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     if (len == I387_SIZEOF_FXSAVE)
>       {
> @@ -4005,7 +4005,7 @@ i386_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   				   void *cb_data,
>   				   const struct regcache *regcache)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     cb (".reg", tdep->sizeof_gregset, tdep->sizeof_gregset, &i386_gregset, NULL,
>         cb_data);
> @@ -4510,7 +4510,7 @@ i386_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   void
>   i386_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* System V Release 4 uses ELF.  */
>     i386_elf_init_abi (info, gdbarch);
> @@ -4552,7 +4552,7 @@ int
>   i386_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
>   			  const struct reggroup *group)
>   {
> -  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int fp_regnum_p, mmx_regnum_p, xmm_regnum_p, mxcsr_regnum_p,
>         ymm_regnum_p, ymmh_regnum_p, ymm_avx512_regnum_p, ymmh_avx512_regnum_p,
>         bndr_regnum_p, bnd_regnum_p, zmm_regnum_p, zmmh_regnum_p,
> @@ -4997,7 +4997,7 @@ static int i386_record_floats (struct gdbarch *gdbarch,
>   			       struct i386_record_s *ir,
>   			       uint32_t iregnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int i;
>   
>     /* Oza: Because of floating point insn push/pop of fpu stack is going to
> @@ -5068,7 +5068,7 @@ i386_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
>     ULONGEST addr;
>     gdb_byte buf[I386_MAX_REGISTER_SIZE];
>     struct i386_record_s ir;
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     uint8_t rex_w = -1;
>     uint8_t rex_r = 0;
>   
> @@ -8839,7 +8839,7 @@ i386_mpx_bd_base (void)
>   
>     rcache = get_current_regcache ();
>     gdbarch *arch = rcache->arch ();
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
>   
>     regstatus = regcache_raw_read_unsigned (rcache, tdep->bndcfgu_regnum, &ret);
>   
> @@ -8853,7 +8853,7 @@ int
>   i386_mpx_enabled (void)
>   {
>     gdbarch *arch = get_current_arch ();
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
>     const struct target_desc *tdesc = tdep->tdesc;
>   
>     return (tdesc_find_feature (tdesc, "org.gnu.gdb.i386.mpx") != NULL);
> diff --git a/gdb/i386-windows-tdep.c b/gdb/i386-windows-tdep.c
> index 8e1cc17b91c..9eec6e28109 100644
> --- a/gdb/i386-windows-tdep.c
> +++ b/gdb/i386-windows-tdep.c
> @@ -136,7 +136,7 @@ i386_windows_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>   static void
>   i386_windows_init_abi_common (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     set_gdbarch_skip_trampoline_code (gdbarch, i386_windows_skip_trampoline_code);
>   
> diff --git a/gdb/i387-tdep.c b/gdb/i387-tdep.c
> index f056ea59347..42ed4eebc2c 100644
> --- a/gdb/i387-tdep.c
> +++ b/gdb/i387-tdep.c
> @@ -204,7 +204,7 @@ void
>   i387_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
>   		       struct frame_info *frame, const char *args)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     ULONGEST fctrl;
>     int fctrl_p;
>     ULONGEST fstat;
> @@ -440,7 +440,7 @@ void
>   i387_supply_fsave (struct regcache *regcache, int regnum, const void *fsave)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     const gdb_byte *regs = (const gdb_byte *) fsave;
>     int i;
> @@ -495,7 +495,7 @@ void
>   i387_collect_fsave (const struct regcache *regcache, int regnum, void *fsave)
>   {
>     gdbarch *arch = regcache->arch ();
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
>     gdb_byte *regs = (gdb_byte *) fsave;
>     int i;
>   
> @@ -589,7 +589,7 @@ void
>   i387_supply_fxsave (struct regcache *regcache, int regnum, const void *fxsave)
>   {
>     gdbarch *arch = regcache->arch ();
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
>     const gdb_byte *regs = (const gdb_byte *) fxsave;
>     int i;
>   
> @@ -673,7 +673,7 @@ void
>   i387_collect_fxsave (const struct regcache *regcache, int regnum, void *fxsave)
>   {
>     gdbarch *arch = regcache->arch ();
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
>     gdb_byte *regs = (gdb_byte *) fxsave;
>     int i;
>   
> @@ -906,7 +906,7 @@ i387_xsave_get_clear_bv (struct gdbarch *gdbarch, const void *xsave)
>   {
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     const gdb_byte *regs = (const gdb_byte *) xsave;
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* Get `xstat_bv'.  The supported bits in `xstat_bv' are 8 bytes.  */
>     ULONGEST xstate_bv = extract_unsigned_integer (XSAVE_XSTATE_BV_ADDR (regs),
> @@ -926,7 +926,7 @@ i387_supply_xsave (struct regcache *regcache, int regnum,
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     const gdb_byte *regs = (const gdb_byte *) xsave;
>     int i;
>     /* In 64-bit mode the split between "low" and "high" ZMM registers is at
> @@ -1349,7 +1349,7 @@ i387_collect_xsave (const struct regcache *regcache, int regnum,
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     gdb_byte *p, *regs = (gdb_byte *) xsave;
>     gdb_byte raw[I386_MAX_REGISTER_SIZE];
>     ULONGEST initial_xstate_bv, clear_bv, xstate_bv = 0;
> @@ -1934,7 +1934,7 @@ i387_tag (const gdb_byte *raw)
>   void
>   i387_return_value (struct gdbarch *gdbarch, struct regcache *regcache)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     ULONGEST fstat;
>   
>     /* Set the top of the floating-point register stack to 7.  The
> @@ -1957,7 +1957,7 @@ i387_return_value (struct gdbarch *gdbarch, struct regcache *regcache)
>   void
>   i387_reset_bnd_regs (struct gdbarch *gdbarch, struct regcache *regcache)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     if (I387_BND0R_REGNUM (tdep) > 0)
>       {
> diff --git a/gdb/ia64-linux-tdep.c b/gdb/ia64-linux-tdep.c
> index 64a57f5bf2f..508d4e6f7c6 100644
> --- a/gdb/ia64-linux-tdep.c
> +++ b/gdb/ia64-linux-tdep.c
> @@ -216,7 +216,7 @@ ia64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   static void
>   ia64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
>     static const char *const stap_register_prefixes[] = { "r", NULL };
>     static const char *const stap_register_indirection_prefixes[] = { "[",
>   								    NULL };
> diff --git a/gdb/ia64-tdep.c b/gdb/ia64-tdep.c
> index dd6d5b199b2..eb0b9ec6a52 100644
> --- a/gdb/ia64-tdep.c
> +++ b/gdb/ia64-tdep.c
> @@ -310,7 +310,7 @@ static const struct floatformat *floatformats_ia64_ext[2] =
>   static struct type *
>   ia64_ext_type (struct gdbarch *gdbarch)
>   {
> -  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->ia64_ext_type)
>       tdep->ia64_ext_type
> @@ -2177,7 +2177,7 @@ ia64_sigtramp_frame_init_saved_regs (struct frame_info *this_frame,
>   				     struct ia64_frame_cache *cache)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->sigcontext_register_address)
>       {
> @@ -2336,7 +2336,7 @@ ia64_sigtramp_frame_sniffer (const struct frame_unwind *self,
>   			     void **this_cache)
>   {
>     gdbarch *arch = get_frame_arch (this_frame);
> -  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (arch);
> +  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (arch);
>     if (tdep->pc_in_sigtramp)
>       {
>         CORE_ADDR pc = get_frame_pc (this_frame);
> @@ -2485,7 +2485,7 @@ ia64_access_reg (unw_addr_space_t as, unw_regnum_t uw_regnum, unw_word_t *val,
>     unw_word_t bsp, sof, cfm, psr, ip;
>     struct frame_info *this_frame = (struct frame_info *) arg;
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
>     
>     /* We never call any libunwind routines that need to write registers.  */
>     gdb_assert (!write);
> @@ -3484,7 +3484,7 @@ ia64_find_global_pointer_from_dynamic_section (struct gdbarch *gdbarch,
>   static CORE_ADDR
>   ia64_find_global_pointer (struct gdbarch *gdbarch, CORE_ADDR faddr)
>   {
> -  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
>     CORE_ADDR addr = 0;
>   
>     if (tdep->find_global_pointer_from_solib)
> @@ -3679,7 +3679,7 @@ ia64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>   		      function_call_return_method return_method,
>   		      CORE_ADDR struct_addr)
>   {
> -  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     int argno;
>     struct value *arg;
> diff --git a/gdb/loongarch-linux-nat.c b/gdb/loongarch-linux-nat.c
> index edc3d697d7b..689c10bd57e 100644
> --- a/gdb/loongarch-linux-nat.c
> +++ b/gdb/loongarch-linux-nat.c
> @@ -51,7 +51,7 @@ static void
>   fetch_gregs_from_thread (struct regcache *regcache, int regno, pid_t tid)
>   {
>     loongarch_gdbarch_tdep *tdep
> -    = (loongarch_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<loongarch_gdbarch_tdep> (regcache->arch ());
>     auto regs = tdep->regs;
>     elf_gregset_t regset;
>   
> @@ -78,7 +78,7 @@ static void
>   store_gregs_to_thread (struct regcache *regcache, int regno, pid_t tid)
>   {
>     loongarch_gdbarch_tdep *tdep
> -    = (loongarch_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<loongarch_gdbarch_tdep> (regcache->arch ());
>     auto regs = tdep->regs;
>     elf_gregset_t regset;
>   
> @@ -131,7 +131,7 @@ loongarch_linux_nat_target::register_u_offset (struct gdbarch *gdbarch,
>   					       int regno, int store_p)
>   {
>     loongarch_gdbarch_tdep *tdep
> -    = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +    = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
>     auto regs = tdep->regs;
>   
>     /* According to <asm/ptrace.h> */
> diff --git a/gdb/loongarch-linux-tdep.c b/gdb/loongarch-linux-tdep.c
> index f6854298569..b76d8240f6e 100644
> --- a/gdb/loongarch-linux-tdep.c
> +++ b/gdb/loongarch-linux-tdep.c
> @@ -42,7 +42,7 @@ loongarch_supply_gregset (const struct regset *r,
>   			  const void *gprs, size_t len)
>   {
>     loongarch_gdbarch_tdep *tdep
> -    = (loongarch_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<loongarch_gdbarch_tdep> (regcache->arch ());
>     auto regs = tdep->regs;
>   
>     int regsize = register_size (regcache->arch (), regs.r);
> @@ -86,7 +86,7 @@ loongarch_fill_gregset (const struct regset *r,
>   			void *gprs, size_t len)
>   {
>     loongarch_gdbarch_tdep *tdep
> -    = (loongarch_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<loongarch_gdbarch_tdep> (regcache->arch ());
>     auto regs = tdep->regs;
>     int regsize = register_size (regcache->arch (), regs.r);
>     gdb_byte *buf = nullptr;
> @@ -137,7 +137,7 @@ loongarch_linux_rt_sigframe_init (const struct tramp_frame *self,
>   				  CORE_ADDR func)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  loongarch_gdbarch_tdep *tdep = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
>     auto regs = tdep->regs;
>   
>     CORE_ADDR frame_sp = get_frame_sp (this_frame);
> @@ -178,7 +178,7 @@ loongarch_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   					const struct regcache *regcache)
>   {
>     loongarch_gdbarch_tdep *tdep
> -    = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +    = gdbarch_tdep<loongarch_gdbarch_tdep> (regcache->arch ());
>     auto regs = tdep->regs;
>     int regsize = register_size (gdbarch, regs.r);
>   
> diff --git a/gdb/loongarch-tdep.c b/gdb/loongarch-tdep.c
> index 8e74c9b779d..30ac9bd298b 100644
> --- a/gdb/loongarch-tdep.c
> +++ b/gdb/loongarch-tdep.c
> @@ -74,7 +74,7 @@ loongarch_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc,
>   			 struct trad_frame_cache *this_cache)
>   {
>     CORE_ADDR cur_pc = start_pc, prologue_end = 0;
> -  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  loongarch_gdbarch_tdep *tdep = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
>     auto regs = tdep->regs;
>     int32_t sp = regs.r + 3;
>     int32_t fp = regs.r + 22;
> @@ -202,7 +202,7 @@ loongarch_frame_cache (struct frame_info *this_frame, void **this_cache)
>     cache = trad_frame_cache_zalloc (this_frame);
>     *this_cache = cache;
>   
> -  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  loongarch_gdbarch_tdep *tdep = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
>     trad_frame_set_reg_realreg (cache, gdbarch_pc_regnum (gdbarch), tdep->regs.ra);
>   
>     pc = get_frame_address_in_block (this_frame);
> @@ -254,7 +254,7 @@ loongarch_return_value (struct gdbarch *gdbarch, struct value *function,
>   			struct type *type, struct regcache *regcache,
>   			gdb_byte *readbuf, const gdb_byte *writebuf)
>   {
> -  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  loongarch_gdbarch_tdep *tdep = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
>     auto regs = tdep->regs;
>     int len = TYPE_LENGTH (type);
>     int regnum = -1;
> @@ -282,7 +282,7 @@ loongarch_return_value (struct gdbarch *gdbarch, struct value *function,
>   static int
>   loongarch_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int num)
>   {
> -  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  loongarch_gdbarch_tdep *tdep = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
>     auto regs = tdep->regs;
>   
>     if (0 <= num && num < 32)
> @@ -408,7 +408,7 @@ loongarch_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>   	 we are looking for.  If it doesn't then we can't reuse this
>   	 gdbarch.  */
>         loongarch_gdbarch_tdep *candidate_tdep
> -	= (loongarch_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<loongarch_gdbarch_tdep> (arches->gdbarch);
>   
>         if (candidate_tdep->abi_features != abi_features)
>   	continue;
> diff --git a/gdb/m32c-tdep.c b/gdb/m32c-tdep.c
> index 4971be796cd..37456d16cb3 100644
> --- a/gdb/m32c-tdep.c
> +++ b/gdb/m32c-tdep.c
> @@ -142,7 +142,7 @@ struct m32c_gdbarch_tdep : gdbarch_tdep
>   static void
>   make_types (struct gdbarch *arch)
>   {
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>     unsigned long mach = gdbarch_bfd_arch_info (arch)->mach;
>     int data_addr_reg_bits, code_addr_reg_bits;
>     char type_name[50];
> @@ -215,7 +215,7 @@ make_types (struct gdbarch *arch)
>   static const char *
>   m32c_register_name (struct gdbarch *gdbarch, int num)
>   {
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
>     return tdep->regs[num].name;
>   }
>   
> @@ -223,7 +223,7 @@ m32c_register_name (struct gdbarch *gdbarch, int num)
>   static struct type *
>   m32c_register_type (struct gdbarch *arch, int reg_nr)
>   {
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>     return tdep->regs[reg_nr].type;
>   }
>   
> @@ -231,7 +231,7 @@ m32c_register_type (struct gdbarch *arch, int reg_nr)
>   static int
>   m32c_register_sim_regno (struct gdbarch *gdbarch, int reg_nr)
>   {
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
>     return tdep->regs[reg_nr].sim_num;
>   }
>   
> @@ -239,7 +239,7 @@ m32c_register_sim_regno (struct gdbarch *gdbarch, int reg_nr)
>   static int
>   m32c_debug_info_reg_to_regnum (struct gdbarch *gdbarch, int reg_nr)
>   {
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
>     if (0 <= reg_nr && reg_nr <= M32C_MAX_DWARF_REGNUM
>         && tdep->dwarf_regs[reg_nr])
>       return tdep->dwarf_regs[reg_nr]->num;
> @@ -254,7 +254,7 @@ static int
>   m32c_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
>   			  const struct reggroup *group)
>   {
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
>     struct m32c_reg *reg = &tdep->regs[regnum];
>   
>     /* The anonymous raw registers aren't in any groups.  */
> @@ -330,7 +330,7 @@ static int
>   m32c_read_flg (readable_regcache *cache)
>   {
>     gdbarch *arch = cache->arch ();
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>     ULONGEST flg;
>   
>     cache->raw_read (tdep->flg->num, &flg);
> @@ -530,7 +530,7 @@ static enum register_status
>   m32c_r3r2r1r0_read (struct m32c_reg *reg, readable_regcache *cache, gdb_byte *buf)
>   {
>     gdbarch *arch = reg->arch;
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>     int len = TYPE_LENGTH (tdep->r0->type);
>     enum register_status status;
>   
> @@ -567,7 +567,7 @@ m32c_r3r2r1r0_write (struct m32c_reg *reg, struct regcache *cache,
>   		     const gdb_byte *buf)
>   {
>     gdbarch *arch = reg->arch;
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>     int len = TYPE_LENGTH (tdep->r0->type);
>   
>     if (gdbarch_byte_order (reg->arch) == BFD_ENDIAN_BIG)
> @@ -595,7 +595,7 @@ m32c_pseudo_register_read (struct gdbarch *arch,
>   			   int cookednum,
>   			   gdb_byte *buf)
>   {
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>     struct m32c_reg *reg;
>   
>     gdb_assert (0 <= cookednum && cookednum < tdep->num_regs);
> @@ -613,7 +613,7 @@ m32c_pseudo_register_write (struct gdbarch *arch,
>   			    int cookednum,
>   			    const gdb_byte *buf)
>   {
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>     struct m32c_reg *reg;
>   
>     gdb_assert (0 <= cookednum && cookednum < tdep->num_regs);
> @@ -638,7 +638,7 @@ add_reg (struct gdbarch *arch,
>   	 struct m32c_reg *ry,
>   	 int n)
>   {
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>     struct m32c_reg *r = &tdep->regs[tdep->num_regs];
>   
>     gdb_assert (tdep->num_regs < M32C_MAX_NUM_REGS);
> @@ -678,7 +678,7 @@ set_dwarf_regnum (struct m32c_reg *reg, int num)
>   
>     /* Update the DWARF->reg mapping.  */
>     gdbarch *arch = reg->arch;
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>     tdep->dwarf_regs[num] = reg;
>   }
>   
> @@ -800,7 +800,7 @@ mark_save_restore (struct m32c_reg *reg)
>   static void
>   make_regs (struct gdbarch *arch)
>   {
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>     int mach = gdbarch_bfd_arch_info (arch)->mach;
>     int num_raw_regs;
>     int num_cooked_regs;
> @@ -1349,7 +1349,7 @@ m32c_pv_enter (struct m32c_pv_state *state, int size)
>       return 1;
>   
>     gdbarch *arch = state->arch;
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>     if (m32c_pv_push (state, state->fb, tdep->push_addr_bytes))
>       return 1;
>   
> @@ -1379,7 +1379,7 @@ static int
>   m32c_pv_pushm (struct m32c_pv_state *state, int src)
>   {
>     gdbarch *arch = state->arch;
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>   
>     /* The bits in SRC indicating which registers to save are:
>        r0 r1 r2 r3 a0 a1 sb fb */
> @@ -1400,7 +1400,7 @@ static int
>   m32c_is_1st_arg_reg (struct m32c_pv_state *state, pv_t value)
>   {
>     gdbarch *arch = state->arch;
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>   
>     return (value.kind == pvk_register
>   	  && (gdbarch_bfd_arch_info (state->arch)->mach == bfd_mach_m16c
> @@ -1415,7 +1415,7 @@ static int
>   m32c_is_arg_reg (struct m32c_pv_state *state, pv_t value)
>   {
>     gdbarch *arch = state->arch;
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>   
>     return (value.kind == pvk_register
>   	  && (gdbarch_bfd_arch_info (state->arch)->mach == bfd_mach_m16c
> @@ -1440,7 +1440,7 @@ m32c_is_arg_spill (struct m32c_pv_state *st,
>   		   pv_t value)
>   {
>     gdbarch *arch = st->arch;
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>   
>     return (m32c_is_arg_reg (st, value)
>   	  && loc.kind == srcdest_mem
> @@ -1464,7 +1464,7 @@ m32c_is_struct_return (struct m32c_pv_state *st,
>   		       pv_t value)
>   {
>     gdbarch *arch = st->arch;
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>   
>     return (m32c_is_1st_arg_reg (st, value)
>   	  && !st->stack->find_reg (st->arch, value.reg, 0)
> @@ -1482,7 +1482,7 @@ static int
>   m32c_pushm_is_reg_save (struct m32c_pv_state *st, int src)
>   {
>     gdbarch *arch = st->arch;
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>   
>     /* The bits in SRC indicating which registers to save are:
>        r0 r1 r2 r3 a0 a1 sb fb */
> @@ -1510,7 +1510,7 @@ check_for_saved (void *prologue_untyped, pv_t addr, CORE_ADDR size, pv_t value)
>   {
>     struct m32c_prologue *prologue = (struct m32c_prologue *) prologue_untyped;
>     struct gdbarch *arch = prologue->arch;
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>   
>     /* Is this the unchanged value of some register being saved on the
>        stack?  */
> @@ -1550,7 +1550,7 @@ m32c_analyze_prologue (struct gdbarch *arch,
>   		       CORE_ADDR start, CORE_ADDR limit,
>   		       struct m32c_prologue *prologue)
>   {
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>     unsigned long mach = gdbarch_bfd_arch_info (arch)->mach;
>     CORE_ADDR after_last_frame_related_insn;
>     struct m32c_pv_state st;
> @@ -1881,7 +1881,7 @@ m32c_frame_base (struct frame_info *this_frame,
>     struct m32c_prologue *p
>       = m32c_analyze_frame_prologue (this_frame, this_prologue_cache);
>     gdbarch *arch = get_frame_arch (this_frame);
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>   
>     /* In functions that use alloca, the distance between the stack
>        pointer and the frame base varies dynamically, so we can't use
> @@ -1932,7 +1932,7 @@ m32c_prev_register (struct frame_info *this_frame,
>   		    void **this_prologue_cache, int regnum)
>   {
>     gdbarch *arch = get_frame_arch (this_frame);
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>     struct m32c_prologue *p
>       = m32c_analyze_frame_prologue (this_frame, this_prologue_cache);
>     CORE_ADDR frame_base = m32c_frame_base (this_frame, this_prologue_cache);
> @@ -2015,7 +2015,7 @@ m32c_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>   		      function_call_return_method return_method,
>   		      CORE_ADDR struct_addr)
>   {
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     unsigned long mach = gdbarch_bfd_arch_info (gdbarch)->mach;
>     CORE_ADDR cfa;
> @@ -2178,7 +2178,7 @@ m32c_return_value (struct gdbarch *gdbarch,
>   		   gdb_byte *readbuf,
>   		   const gdb_byte *writebuf)
>   {
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     enum return_value_convention conv;
>     ULONGEST valtype_len = TYPE_LENGTH (valtype);
> @@ -2309,7 +2309,7 @@ static CORE_ADDR
>   m32c_skip_trampoline_code (struct frame_info *frame, CORE_ADDR stop_pc)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (frame);
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>   
>     /* It would be nicer to simply look up the addresses of known
> @@ -2555,7 +2555,7 @@ m32c_virtual_frame_pointer (struct gdbarch *gdbarch, CORE_ADDR pc,
>     struct m32c_prologue p;
>   
>     struct regcache *regcache = get_current_regcache ();
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
>     
>     if (!find_pc_partial_function (pc, &name, &func_addr, &func_end))
>       internal_error (__FILE__, __LINE__,
> diff --git a/gdb/m68hc11-tdep.c b/gdb/m68hc11-tdep.c
> index 98f1367423e..9eb18b937be 100644
> --- a/gdb/m68hc11-tdep.c
> +++ b/gdb/m68hc11-tdep.c
> @@ -146,14 +146,14 @@ struct m68gc11_gdbarch_tdep : gdbarch_tdep
>   static int
>   stack_correction (gdbarch *arch)
>   {
> -  m68gc11_gdbarch_tdep *tdep = (m68gc11_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m68gc11_gdbarch_tdep *tdep = gdbarch_tdep<m68gc11_gdbarch_tdep> (arch);
>     return tdep->stack_correction;
>   }
>   
>   static int
>   use_page_register (gdbarch *arch)
>   {
> -  m68gc11_gdbarch_tdep *tdep = (m68gc11_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m68gc11_gdbarch_tdep *tdep = gdbarch_tdep<m68gc11_gdbarch_tdep> (arch);
>     return tdep->stack_correction;
>   }
>   
> @@ -642,7 +642,7 @@ m68hc11_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
>         return pc;
>       }
>   
> -  m68gc11_gdbarch_tdep *tdep = (m68gc11_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68gc11_gdbarch_tdep *tdep = gdbarch_tdep<m68gc11_gdbarch_tdep> (gdbarch);
>     seq_table = tdep->prologue;
>     
>     /* The 68hc11 stack is as follows:
> @@ -1020,7 +1020,7 @@ m68hc11_print_register (struct gdbarch *gdbarch, struct ui_file *file,
>     else
>       {
>         m68gc11_gdbarch_tdep *tdep
> -	= (m68gc11_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +	= gdbarch_tdep<m68gc11_gdbarch_tdep> (gdbarch);
>   
>         if (regno == HARD_PC_REGNUM && tdep->use_page_register)
>   	{
> @@ -1125,7 +1125,7 @@ m68hc11_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file,
>         gdb_printf (file, " Y=");
>         m68hc11_print_register (gdbarch, file, frame, HARD_Y_REGNUM);
>     
> -      m68gc11_gdbarch_tdep *tdep = (m68gc11_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      m68gc11_gdbarch_tdep *tdep = gdbarch_tdep<m68gc11_gdbarch_tdep> (gdbarch);
>   
>         if (tdep->use_page_register)
>   	{
> @@ -1417,7 +1417,7 @@ m68hc11_gdbarch_init (struct gdbarch_info info,
>          arches = gdbarch_list_lookup_by_info (arches->next, &info))
>       {
>         m68gc11_gdbarch_tdep *tdep
> -	= (m68gc11_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<m68gc11_gdbarch_tdep> (arches->gdbarch);
>   
>         if (tdep->elf_flags != elf_flags)
>   	continue;
> diff --git a/gdb/m68k-bsd-tdep.c b/gdb/m68k-bsd-tdep.c
> index 9ef70f0dda4..2614c223f8e 100644
> --- a/gdb/m68k-bsd-tdep.c
> +++ b/gdb/m68k-bsd-tdep.c
> @@ -133,7 +133,7 @@ m68kbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   static void
>   m68kbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     tdep->jb_pc = 5;
>     tdep->jb_elt_size = 4;
> diff --git a/gdb/m68k-linux-tdep.c b/gdb/m68k-linux-tdep.c
> index 85ad4741b1f..28401d3ecc6 100644
> --- a/gdb/m68k-linux-tdep.c
> +++ b/gdb/m68k-linux-tdep.c
> @@ -384,7 +384,7 @@ m68k_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   static void
>   m68k_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     linux_init_abi (info, gdbarch, 0);
>   
> diff --git a/gdb/m68k-tdep.c b/gdb/m68k-tdep.c
> index 568bde66f93..9e59f5904c3 100644
> --- a/gdb/m68k-tdep.c
> +++ b/gdb/m68k-tdep.c
> @@ -70,7 +70,7 @@ typedef BP_MANIPULATION (m68k_break_insn) m68k_breakpoint;
>   static struct type *
>   m68k_ps_type (struct gdbarch *gdbarch)
>   {
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->m68k_ps_type)
>       {
> @@ -99,7 +99,7 @@ m68k_ps_type (struct gdbarch *gdbarch)
>   static struct type *
>   m68881_ext_type (struct gdbarch *gdbarch)
>   {
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->m68881_ext_type)
>       tdep->m68881_ext_type
> @@ -120,7 +120,7 @@ m68881_ext_type (struct gdbarch *gdbarch)
>   static struct type *
>   m68k_register_type (struct gdbarch *gdbarch, int regnum)
>   {
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->fpregs_present)
>       {
> @@ -171,7 +171,7 @@ static const char * const m68k_register_names[] = {
>   static const char *
>   m68k_register_name (struct gdbarch *gdbarch, int regnum)
>   {
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     if (regnum < 0 || regnum >= ARRAY_SIZE (m68k_register_names))
>       internal_error (__FILE__, __LINE__,
> @@ -191,7 +191,7 @@ static int
>   m68k_convert_register_p (struct gdbarch *gdbarch,
>   			 int regnum, struct type *type)
>   {
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->fpregs_present)
>       return 0;
> @@ -300,7 +300,7 @@ m68k_extract_return_value (struct type *type, struct regcache *regcache,
>     if (type->code () == TYPE_CODE_PTR && len == 4)
>       {
>         struct gdbarch *gdbarch = regcache->arch ();
> -      m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>         regcache->raw_read (tdep->pointer_result_regnum, valbuf);
>       }
>     else if (len <= 4)
> @@ -325,7 +325,7 @@ m68k_svr4_extract_return_value (struct type *type, struct regcache *regcache,
>   {
>     gdb_byte buf[M68K_MAX_REGISTER_SIZE];
>     struct gdbarch *gdbarch = regcache->arch ();
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->float_return && type->code () == TYPE_CODE_FLT)
>       {
> @@ -348,7 +348,7 @@ m68k_store_return_value (struct type *type, struct regcache *regcache,
>     if (type->code () == TYPE_CODE_PTR && len == 4)
>       {
>         struct gdbarch *gdbarch = regcache->arch ();
> -      m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>         regcache->raw_write (tdep->pointer_result_regnum, valbuf);
>         /* gdb historically also set D0 in the SVR4 case.  */
>         if (tdep->pointer_result_regnum != M68K_D0_REGNUM)
> @@ -371,7 +371,7 @@ m68k_svr4_store_return_value (struct type *type, struct regcache *regcache,
>   			      const gdb_byte *valbuf)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->float_return && type->code () == TYPE_CODE_FLT)
>       {
> @@ -391,7 +391,7 @@ m68k_svr4_store_return_value (struct type *type, struct regcache *regcache,
>   static int
>   m68k_reg_struct_return_p (struct gdbarch *gdbarch, struct type *type)
>   {
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>     enum type_code code = type->code ();
>     int len = TYPE_LENGTH (type);
>   
> @@ -469,7 +469,7 @@ m68k_svr4_return_value (struct gdbarch *gdbarch, struct value *function,
>   			gdb_byte *readbuf, const gdb_byte *writebuf)
>   {
>     enum type_code code = type->code ();
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     /* Aggregates with a single member are always returned like their
>        sole element.  */
> @@ -541,7 +541,7 @@ m68k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>   		      function_call_return_method return_method,
>   		      CORE_ADDR struct_addr)
>   {
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     gdb_byte buf[4];
>     int i;
> @@ -596,7 +596,7 @@ m68k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>   static int
>   m68k_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int num)
>   {
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     if (num < 8)
>       /* d0..7 */
> @@ -766,7 +766,7 @@ m68k_analyze_register_saves (struct gdbarch *gdbarch, CORE_ADDR pc,
>   			     struct m68k_frame_cache *cache)
>   {
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     if (cache->locals >= 0)
>       {
> @@ -1058,7 +1058,7 @@ m68k_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
>     gdb_byte *buf;
>     CORE_ADDR sp, jb_addr;
>     struct gdbarch *gdbarch = get_frame_arch (frame);
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>   
>     if (tdep->jb_pc < 0)
> @@ -1104,7 +1104,7 @@ m68k_return_in_first_hidden_param_p (struct gdbarch *gdbarch,
>   void
>   m68k_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     /* SVR4 uses a different calling convention.  */
>     set_gdbarch_return_value (gdbarch, m68k_svr4_return_value);
> @@ -1122,7 +1122,7 @@ m68k_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   static void
>   m68k_embedded_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     m68k_svr4_init_abi (info, gdbarch);
>     tdep->pointer_result_regnum = M68K_D0_REGNUM;
> @@ -1237,7 +1237,7 @@ m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
>       {
>         m68k_gdbarch_tdep *tdep
> -	= (m68k_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
> +	= gdbarch_tdep<m68k_gdbarch_tdep> (best_arch->gdbarch);
>   
>         if (flavour != tdep->flavour)
>   	continue;
> @@ -1339,7 +1339,7 @@ m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>   static void
>   m68k_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
>   {
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     if (tdep == NULL)
>       return;
> diff --git a/gdb/mep-tdep.c b/gdb/mep-tdep.c
> index 6b3a62391c0..d5ba78c6df9 100644
> --- a/gdb/mep-tdep.c
> +++ b/gdb/mep-tdep.c
> @@ -260,7 +260,7 @@ me_module_register_set (CONFIG_ATTR me_module,
>          specifically excluding the generic coprocessor register sets.  */
>   
>     mep_gdbarch_tdep *tdep
> -    = (mep_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
> +    = gdbarch_tdep<mep_gdbarch_tdep> (target_gdbarch ());
>     CGEN_CPU_DESC desc = tdep->cpu_desc;
>     const CGEN_HW_ENTRY *hw;
>   
> @@ -856,7 +856,7 @@ current_me_module (void)
>     else
>       {
>         mep_gdbarch_tdep *tdep
> -	= (mep_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
> +	= gdbarch_tdep<mep_gdbarch_tdep> (target_gdbarch ());
>         return tdep->me_module;
>       }
>   }
> @@ -2391,7 +2391,7 @@ mep_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          arches = gdbarch_list_lookup_by_info (arches->next, &info))
>       {
>         mep_gdbarch_tdep *tdep
> -	= (mep_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<mep_gdbarch_tdep> (arches->gdbarch);
>   
>         if (tdep->me_module == me_module)
>   	return arches->gdbarch;
> diff --git a/gdb/mips-linux-tdep.c b/gdb/mips-linux-tdep.c
> index d8f90ccf881..ca313a28279 100644
> --- a/gdb/mips-linux-tdep.c
> +++ b/gdb/mips-linux-tdep.c
> @@ -1317,7 +1317,7 @@ mips_linux_get_syscall_number (struct gdbarch *gdbarch,
>   			       thread_info *thread)
>   {
>     struct regcache *regcache = get_thread_regcache (thread);
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     int regsize = register_size (gdbarch, MIPS_V0_REGNUM);
>     /* The content of a register */
> @@ -1527,7 +1527,7 @@ static void
>   mips_linux_init_abi (struct gdbarch_info info,
>   		     struct gdbarch *gdbarch)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>     enum mips_abi abi = mips_abi (gdbarch);
>     struct tdesc_arch_data *tdesc_data = info.tdesc_data;
>   
> diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
> index fc1cb46de84..1ea16767e54 100644
> --- a/gdb/mips-tdep.c
> +++ b/gdb/mips-tdep.c
> @@ -227,7 +227,7 @@ static const char mips_disassembler_options_n64[] = "gpr-names=64";
>   const struct mips_regnum *
>   mips_regnum (struct gdbarch *gdbarch)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>     return tdep->regnum;
>   }
>   
> @@ -252,7 +252,7 @@ mips_float_register_p (struct gdbarch *gdbarch, int regnum)
>   static bool
>   mips_eabi (gdbarch *arch)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (arch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (arch);
>     return (tdep->mips_abi == MIPS_ABI_EABI32 \
>   	  || tdep->mips_abi == MIPS_ABI_EABI64);
>   }
> @@ -260,21 +260,21 @@ mips_eabi (gdbarch *arch)
>   static int
>   mips_last_fp_arg_regnum (gdbarch *arch)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (arch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (arch);
>     return tdep->mips_last_fp_arg_regnum;
>   }
>   
>   static int
>   mips_last_arg_regnum (gdbarch *arch)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (arch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (arch);
>     return tdep->mips_last_arg_regnum;
>   }
>   
>   static enum mips_fpu_type
>   mips_get_fpu_type (gdbarch *arch)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (arch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (arch);
>     return tdep->mips_fpu_type;
>   }
>   
> @@ -282,14 +282,14 @@ mips_get_fpu_type (gdbarch *arch)
>   enum mips_abi
>   mips_abi (struct gdbarch *gdbarch)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>     return tdep->mips_abi;
>   }
>   
>   int
>   mips_isa_regsize (struct gdbarch *gdbarch)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>   
>     /* If we know how big the registers are, use that size.  */
>     if (tdep->register_size_valid_p)
> @@ -335,7 +335,7 @@ mips_abi_regsize (struct gdbarch *gdbarch)
>   static int
>   is_mips16_isa (struct gdbarch *gdbarch)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>     return tdep->mips_isa == ISA_MIPS16;
>   }
>   
> @@ -344,7 +344,7 @@ is_mips16_isa (struct gdbarch *gdbarch)
>   static int
>   is_micromips_isa (struct gdbarch *gdbarch)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>     return tdep->mips_isa == ISA_MICROMIPS;
>   }
>   
> @@ -636,7 +636,7 @@ static const char * const mips_linux_reg_names[NUM_MIPS_PROCESSOR_REGS] = {
>   static const char *
>   mips_register_name (struct gdbarch *gdbarch, int regno)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>     /* GPR names for all ABIs other than n32/n64.  */
>     static const char *mips_gpr_names[] = {
>       "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
> @@ -777,7 +777,7 @@ mips_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
>     else if (register_size (gdbarch, rawnum) >
>   	   register_size (gdbarch, cookednum))
>       {
> -      mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>   
>         if (tdep->mips64_transfers_32bit_regs_p)
>   	return regcache->raw_read_part (rawnum, 0, 4, buf);
> @@ -810,7 +810,7 @@ mips_pseudo_register_write (struct gdbarch *gdbarch,
>     else if (register_size (gdbarch, rawnum) >
>   	   register_size (gdbarch, cookednum))
>       {
> -      mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>   
>         if (tdep->mips64_transfers_32bit_regs_p)
>   	regcache->raw_write_part (rawnum, 0, 4, buf);
> @@ -855,7 +855,7 @@ mips_ax_pseudo_register_push_stack (struct gdbarch *gdbarch,
>         if (register_size (gdbarch, rawnum) > register_size (gdbarch, reg))
>   	{
>   	  mips_gdbarch_tdep *tdep
> -	    = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +	    = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>   
>   	  if (!tdep->mips64_transfers_32bit_regs_p
>   	      || gdbarch_byte_order (gdbarch) != BFD_ENDIAN_BIG)
> @@ -1059,7 +1059,7 @@ mips_register_type (struct gdbarch *gdbarch, int regnum)
>     else
>       {
>         int rawnum = regnum - gdbarch_num_regs (gdbarch);
> -      mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>   
>         /* The cooked or ABI registers.  These are sized according to
>   	 the ABI (with a few complications).  */
> @@ -1191,7 +1191,7 @@ show_mask_address (struct ui_file *file, int from_tty,
>         else
>   	{
>   	  mips_gdbarch_tdep *tdep
> -	    = (mips_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
> +	    = gdbarch_tdep<mips_gdbarch_tdep> (target_gdbarch ());
>   
>   	  if (mips_mask_address_p (tdep))
>   	    additional_text = _(" (currently \"on\")");
> @@ -1727,7 +1727,7 @@ mips32_next_pc (struct regcache *regcache, CORE_ADDR pc)
>   	    case 12:            /* SYSCALL */
>   	      {
>   		mips_gdbarch_tdep *tdep
> -		  = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +		  = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>   
>   		if (tdep->syscall_next_pc != NULL)
>   		  pc = tdep->syscall_next_pc (get_current_frame ());
> @@ -1938,7 +1938,7 @@ micromips_next_pc (struct regcache *regcache, CORE_ADDR pc)
>   		case 0x22d: /* SYSCALL:  000000 1000101101 111100 */
>   		  {
>   		    mips_gdbarch_tdep *tdep
> -		      = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +		      = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>   
>   		    if (tdep->syscall_next_pc != NULL)
>   		      pc = tdep->syscall_next_pc (get_current_frame ());
> @@ -3901,7 +3901,7 @@ mips_stub_frame_base_sniffer (struct frame_info *this_frame)
>   static CORE_ADDR
>   mips_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>   
>     if (mips_mask_address_p (tdep) && (((ULONGEST) addr) >> 32 == 0xffffffffUL))
>       /* This hack is a work-around for existing boards using PMON, the
> @@ -4804,7 +4804,7 @@ mips_eabi_return_value (struct gdbarch *gdbarch, struct value *function,
>   			struct type *type, struct regcache *regcache,
>   			gdb_byte *readbuf, const gdb_byte *writebuf)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>     int fp_return_type = 0;
>     int offset, regnum, xfer;
>   
> @@ -5195,7 +5195,7 @@ mips_n32n64_return_value (struct gdbarch *gdbarch, struct value *function,
>   			  struct type *type, struct regcache *regcache,
>   			  gdb_byte *readbuf, const gdb_byte *writebuf)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>   
>     /* From MIPSpro N32 ABI Handbook, Document Number: 007-2816-004
>   
> @@ -5704,7 +5704,7 @@ mips_o32_return_value (struct gdbarch *gdbarch, struct value *function,
>   {
>     CORE_ADDR func_addr = function ? find_function_addr (function, NULL) : 0;
>     int mips16 = mips_pc_is_mips16 (gdbarch, func_addr);
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>     enum mips_fval_reg fval_reg;
>   
>     fval_reg = readbuf ? mips16 ? mips_fval_gpr : mips_fval_fpr : mips_fval_both;
> @@ -8101,7 +8101,7 @@ mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>     else if (arches != NULL)
>       {
>         mips_gdbarch_tdep *tdep
> -	= (mips_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<mips_gdbarch_tdep> (arches->gdbarch);
>         elf_flags = tdep->elf_flags;
>       }
>     else
> @@ -8142,7 +8142,7 @@ mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>     if (found_abi == MIPS_ABI_UNKNOWN && info.abfd == NULL && arches != NULL)
>       {
>         mips_gdbarch_tdep *tdep
> -	= (mips_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<mips_gdbarch_tdep> (arches->gdbarch);
>         found_abi = tdep->found_abi;
>       }
>   
> @@ -8459,7 +8459,7 @@ mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          arches = gdbarch_list_lookup_by_info (arches->next, &info))
>       {
>         mips_gdbarch_tdep *tdep
> -        = (mips_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +        = gdbarch_tdep<mips_gdbarch_tdep> (arches->gdbarch);
>   
>         /* MIPS needs to be pedantic about which ABI and the compressed
>   	 ISA variation the object is using.  */
> @@ -8917,7 +8917,7 @@ mips_fpu_type_str (enum mips_fpu_type fpu_type)
>   static void
>   mips_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>     if (tdep != NULL)
>       {
>         int ef_mips_arch;
> diff --git a/gdb/mn10300-tdep.c b/gdb/mn10300-tdep.c
> index 7a41070bb30..22511d894d4 100644
> --- a/gdb/mn10300-tdep.c
> +++ b/gdb/mn10300-tdep.c
> @@ -1412,7 +1412,7 @@ mn10300_gdbarch_init (struct gdbarch_info info,
>   static void
>   mn10300_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
>   {
> -  mn10300_gdbarch_tdep *tdep = (mn10300_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  mn10300_gdbarch_tdep *tdep = gdbarch_tdep<mn10300_gdbarch_tdep> (gdbarch);
>     gdb_printf (file, "mn10300_dump_tdep: am33_mode = %d\n",
>   	      tdep->am33_mode);
>   }
> diff --git a/gdb/mn10300-tdep.h b/gdb/mn10300-tdep.h
> index 10fef99c5d7..87b861ead90 100644
> --- a/gdb/mn10300-tdep.h
> +++ b/gdb/mn10300-tdep.h
> @@ -84,7 +84,7 @@ struct mn10300_gdbarch_tdep : gdbarch_tdep
>   static inline int
>   get_am33_mode (gdbarch *arch)
>   {
> -  mn10300_gdbarch_tdep *tdep = (mn10300_gdbarch_tdep *) gdbarch_tdep (arch);
> +  mn10300_gdbarch_tdep *tdep = gdbarch_tdep<mn10300_gdbarch_tdep> (arch);
>     return tdep->am33_mode;
>   }
>   
> diff --git a/gdb/msp430-tdep.c b/gdb/msp430-tdep.c
> index 28268a95139..4ae8b3d5626 100644
> --- a/gdb/msp430-tdep.c
> +++ b/gdb/msp430-tdep.c
> @@ -341,7 +341,7 @@ msp430_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc,
>     int rn;
>     pv_t reg[MSP430_NUM_TOTAL_REGS];
>     CORE_ADDR after_last_frame_setup_insn = start_pc;
> -  msp430_gdbarch_tdep *tdep = (msp430_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  msp430_gdbarch_tdep *tdep = gdbarch_tdep<msp430_gdbarch_tdep> (gdbarch);
>     int code_model = tdep->code_model;
>     int sz;
>   
> @@ -570,7 +570,7 @@ msp430_return_value (struct gdbarch *gdbarch,
>   {
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     LONGEST valtype_len = TYPE_LENGTH (valtype);
> -  msp430_gdbarch_tdep *tdep = (msp430_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  msp430_gdbarch_tdep *tdep = gdbarch_tdep<msp430_gdbarch_tdep> (gdbarch);
>     int code_model = tdep->code_model;
>   
>     if (TYPE_LENGTH (valtype) > 8
> @@ -651,7 +651,7 @@ msp430_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>     int write_pass;
>     int sp_off = 0;
>     CORE_ADDR cfa;
> -  msp430_gdbarch_tdep *tdep = (msp430_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  msp430_gdbarch_tdep *tdep = gdbarch_tdep<msp430_gdbarch_tdep> (gdbarch);
>     int code_model = tdep->code_model;
>   
>     struct type *func_type = value_type (function);
> @@ -814,7 +814,7 @@ msp430_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
>   
>     stub_name = bms.minsym->linkage_name ();
>   
> -  msp430_gdbarch_tdep *tdep = (msp430_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  msp430_gdbarch_tdep *tdep = gdbarch_tdep<msp430_gdbarch_tdep> (gdbarch);
>     if (tdep->code_model == MSP_SMALL_CODE_MODEL
>         && msp430_in_return_stub (gdbarch, pc, stub_name))
>       {
> @@ -877,7 +877,7 @@ msp430_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>   	  if (ca && gdbarch_bfd_arch_info (ca)->arch == bfd_arch_msp430)
>   	    {
>   	      msp430_gdbarch_tdep *ca_tdep
> -		= (msp430_gdbarch_tdep *) gdbarch_tdep (ca);
> +		= gdbarch_tdep<msp430_gdbarch_tdep> (ca);
>   
>   	      elf_flags = ca_tdep->elf_flags;
>   	      isa = ca_tdep->isa;
> @@ -904,7 +904,7 @@ msp430_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          arches = gdbarch_list_lookup_by_info (arches->next, &info))
>       {
>         msp430_gdbarch_tdep *candidate_tdep
> -	= (msp430_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<msp430_gdbarch_tdep> (arches->gdbarch);
>   
>         if (candidate_tdep->elf_flags != elf_flags
>   	  || candidate_tdep->isa != isa
> diff --git a/gdb/nds32-tdep.c b/gdb/nds32-tdep.c
> index e95ad7cc662..11bfd2d1f54 100644
> --- a/gdb/nds32-tdep.c
> +++ b/gdb/nds32-tdep.c
> @@ -289,7 +289,7 @@ typedef BP_MANIPULATION (nds32_break_insn) nds32_breakpoint;
>   static int
>   nds32_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int num)
>   {
> -  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
>     const int FSR = 38;
>     const int FDR = FSR + 32;
>   
> @@ -432,7 +432,7 @@ nds32_pseudo_register_read (struct gdbarch *gdbarch,
>   			    readable_regcache *regcache, int regnum,
>   			    gdb_byte *buf)
>   {
> -  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
>     gdb_byte reg_buf[8];
>     int offset, fdr_regnum;
>     enum register_status status;
> @@ -471,7 +471,7 @@ nds32_pseudo_register_write (struct gdbarch *gdbarch,
>   			     struct regcache *regcache, int regnum,
>   			     const gdb_byte *buf)
>   {
> -  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
>     gdb_byte reg_buf[8];
>     int offset, fdr_regnum;
>   
> @@ -608,7 +608,7 @@ static CORE_ADDR
>   nds32_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
>   			CORE_ADDR limit_pc, struct nds32_frame_cache *cache)
>   {
> -  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
>     int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
>     /* Current scanning status.  */
>     int in_prologue_bb = 0;
> @@ -1169,7 +1169,7 @@ static int
>   nds32_analyze_epilogue (struct gdbarch *gdbarch, CORE_ADDR pc,
>   			struct nds32_frame_cache *cache)
>   {
> -  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
>     int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
>     CORE_ADDR limit_pc;
>     uint32_t insn, insn_len;
> @@ -1220,7 +1220,7 @@ nds32_analyze_epilogue (struct gdbarch *gdbarch, CORE_ADDR pc,
>   static int
>   nds32_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR addr)
>   {
> -  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
>     int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
>     int insn_type = INSN_NORMAL;
>     int ret_found = 0;
> @@ -1424,7 +1424,7 @@ nds32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>     int i;
>     ULONGEST regval;
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
>     struct type *func_type = value_type (function);
>     int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
>     int abi_split = nds32_abi_split (tdep->elf_abi);
> @@ -1652,7 +1652,7 @@ nds32_extract_return_value (struct gdbarch *gdbarch, struct type *type,
>   			    struct regcache *regcache, gdb_byte *valbuf)
>   {
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
>     int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
>     int calling_use_fpr;
>     int len;
> @@ -1742,7 +1742,7 @@ nds32_store_return_value (struct gdbarch *gdbarch, struct type *type,
>   			  struct regcache *regcache, const gdb_byte *valbuf)
>   {
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
>     int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
>     int calling_use_fpr;
>     int len;
> @@ -1965,7 +1965,7 @@ nds32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
>       {
>         nds32_gdbarch_tdep *idep
> -	= (nds32_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
> +	= gdbarch_tdep<nds32_gdbarch_tdep> (best_arch->gdbarch);
>   
>         if (idep->elf_abi != elf_abi)
>   	continue;
> diff --git a/gdb/nios2-linux-tdep.c b/gdb/nios2-linux-tdep.c
> index a32f79aa28a..da69638b20b 100644
> --- a/gdb/nios2-linux-tdep.c
> +++ b/gdb/nios2-linux-tdep.c
> @@ -217,7 +217,7 @@ nios2_linux_is_kernel_helper (CORE_ADDR pc)
>   static void
>   nios2_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  nios2_gdbarch_tdep *tdep = (nios2_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  nios2_gdbarch_tdep *tdep = gdbarch_tdep<nios2_gdbarch_tdep> (gdbarch);
>   
>     linux_init_abi (info, gdbarch, 0);
>   
> diff --git a/gdb/nios2-tdep.c b/gdb/nios2-tdep.c
> index 159d31b2d0f..0bad229b44a 100644
> --- a/gdb/nios2-tdep.c
> +++ b/gdb/nios2-tdep.c
> @@ -2098,7 +2098,7 @@ static CORE_ADDR
>   nios2_get_next_pc (struct regcache *regcache, CORE_ADDR pc)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  nios2_gdbarch_tdep *tdep = (nios2_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  nios2_gdbarch_tdep *tdep = gdbarch_tdep<nios2_gdbarch_tdep> (gdbarch);
>     unsigned long mach = gdbarch_bfd_arch_info (gdbarch)->mach;
>     unsigned int insn;
>     const struct nios2_opcode *op = nios2_fetch_insn (gdbarch, pc, &insn);
> @@ -2221,7 +2221,7 @@ static int
>   nios2_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (frame);
> -  nios2_gdbarch_tdep *tdep = (nios2_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  nios2_gdbarch_tdep *tdep = gdbarch_tdep<nios2_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     CORE_ADDR jb_addr = get_frame_register_unsigned (frame, NIOS2_R4_REGNUM);
>     gdb_byte buf[4];
> diff --git a/gdb/or1k-tdep.c b/gdb/or1k-tdep.c
> index 2b906fa69d3..4699b755d42 100644
> --- a/gdb/or1k-tdep.c
> +++ b/gdb/or1k-tdep.c
> @@ -248,7 +248,7 @@ or1k_return_value (struct gdbarch *gdbarch, struct value *functype,
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     enum type_code rv_type = valtype->code ();
>     unsigned int rv_size = TYPE_LENGTH (valtype);
> -  or1k_gdbarch_tdep *tdep = (or1k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  or1k_gdbarch_tdep *tdep = gdbarch_tdep<or1k_gdbarch_tdep> (gdbarch);
>     int bpw = tdep->bytes_per_word;
>   
>     /* Deal with struct/union as addresses.  If an array won't fit in a
> @@ -353,7 +353,7 @@ or1k_delay_slot_p (struct gdbarch *gdbarch, CORE_ADDR pc)
>   {
>     const CGEN_INSN *insn;
>     CGEN_FIELDS tmp_fields;
> -  or1k_gdbarch_tdep *tdep = (or1k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  or1k_gdbarch_tdep *tdep = gdbarch_tdep<or1k_gdbarch_tdep> (gdbarch);
>   
>     insn = cgen_lookup_insn (tdep->gdb_cgen_cpu_desc,
>   			   NULL,
> @@ -635,7 +635,7 @@ or1k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>     int heap_offset = 0;
>     CORE_ADDR heap_sp = sp - 128;
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  or1k_gdbarch_tdep *tdep = (or1k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  or1k_gdbarch_tdep *tdep = gdbarch_tdep<or1k_gdbarch_tdep> (gdbarch);
>     int bpa = tdep->bytes_per_address;
>     int bpw = tdep->bytes_per_word;
>     struct type *func_type = value_type (function);
> @@ -1273,7 +1273,7 @@ or1k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>   static void
>   or1k_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
>   {
> -  or1k_gdbarch_tdep *tdep = (or1k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  or1k_gdbarch_tdep *tdep = gdbarch_tdep<or1k_gdbarch_tdep> (gdbarch);
>   
>     if (NULL == tdep)
>       return; /* Nothing to report */
> diff --git a/gdb/ppc-fbsd-nat.c b/gdb/ppc-fbsd-nat.c
> index ce045ac55ab..d0a5778e2d3 100644
> --- a/gdb/ppc-fbsd-nat.c
> +++ b/gdb/ppc-fbsd-nat.c
> @@ -100,7 +100,7 @@ fill_fpregset (const struct regcache *regcache,
>   static int
>   getfpregs_supplies (struct gdbarch *gdbarch, int regno)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
>   	 point registers.  Traditionally, GDB's register set has still
> @@ -185,7 +185,7 @@ static int
>   ppcfbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int i, regnum;
>   
>     /* The stack pointer shouldn't be zero.  */
> diff --git a/gdb/ppc-fbsd-tdep.c b/gdb/ppc-fbsd-tdep.c
> index 4afcc3019a4..f5b482921a7 100644
> --- a/gdb/ppc-fbsd-tdep.c
> +++ b/gdb/ppc-fbsd-tdep.c
> @@ -126,7 +126,7 @@ ppcfbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   				      void *cb_data,
>   				      const struct regcache *regcache)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->wordsize == 4)
>       cb (".reg", 148, 148, &ppc32_fbsd_gregset, NULL, cb_data);
> @@ -200,7 +200,7 @@ static struct trad_frame_cache *
>   ppcfbsd_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     struct trad_frame_cache *cache;
>     CORE_ADDR addr, base, func;
>     gdb_byte buf[PPC_INSN_SIZE];
> @@ -287,7 +287,7 @@ static CORE_ADDR
>   ppcfbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
>   				  CORE_ADDR lm_addr, CORE_ADDR offset)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     struct regcache *regcache;
>     int tp_offset, tp_regnum;
>   
> @@ -319,7 +319,7 @@ ppcfbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
>   static void
>   ppcfbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     /* Generic FreeBSD support. */
>     fbsd_init_abi (info, gdbarch);
> diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c
> index 588dd7df9c0..bdcc0746f58 100644
> --- a/gdb/ppc-linux-nat.c
> +++ b/gdb/ppc-linux-nat.c
> @@ -649,7 +649,7 @@ static int
>   ppc_register_u_addr (struct gdbarch *gdbarch, int regno)
>   {
>     int u_addr = -1;
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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 +802,7 @@ static void
>   fetch_spe_register (struct regcache *regcache, int tid, int regno)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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 +911,7 @@ static void
>   fetch_register (struct regcache *regcache, int tid, int regno)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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;
> @@ -1156,7 +1156,7 @@ static void
>   fetch_gp_regs (struct regcache *regcache, int tid)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int i;
>   
>     if (have_ptrace_getsetregs)
> @@ -1208,7 +1208,7 @@ static void
>   fetch_fp_regs (struct regcache *regcache, int tid)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int i;
>   
>     if (have_ptrace_getsetfpregs)
> @@ -1226,7 +1226,7 @@ static void
>   fetch_ppc_registers (struct regcache *regcache, int tid)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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 +1425,7 @@ static void
>   store_spe_register (const struct regcache *regcache, int tid, int regno)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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 +1477,7 @@ static void
>   store_register (const struct regcache *regcache, int tid, int regno)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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;
> @@ -1718,7 +1718,7 @@ static void
>   store_gp_regs (const struct regcache *regcache, int tid, int regno)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int i;
>   
>     if (have_ptrace_getsetregs)
> @@ -1780,7 +1780,7 @@ static void
>   store_fp_regs (const struct regcache *regcache, int tid, int regno)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int i;
>   
>     if (have_ptrace_getsetfpregs)
> @@ -1798,7 +1798,7 @@ static void
>   store_ppc_registers (const struct regcache *regcache, int tid)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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)
> diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c
> index 4c5f8b7a281..5a8ba239343 100644
> --- a/gdb/ppc-linux-tdep.c
> +++ b/gdb/ppc-linux-tdep.c
> @@ -332,7 +332,7 @@ ppc_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
>   {
>     unsigned int insnbuf[POWERPC32_PLT_CHECK_LEN];
>     struct gdbarch *gdbarch = get_frame_arch (frame);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     CORE_ADDR target = 0;
>     int scan_limit, i;
> @@ -898,7 +898,7 @@ ppc_linux_vsxregset (void)
>   const struct regset *
>   ppc_linux_cgprregset (struct gdbarch *gdbarch)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->wordsize == 4)
>       {
> @@ -938,7 +938,7 @@ ppc_linux_collect_core_cpgrregset (const struct regset *regset,
>   				   int regnum, void *buf, size_t len)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     const struct regset *cgprregset = ppc_linux_cgprregset (gdbarch);
>   
> @@ -985,7 +985,7 @@ ppc_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   					void *cb_data,
>   					const struct regcache *regcache)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int have_altivec = tdep->ppc_vr0_regnum != -1;
>     int have_vsx = tdep->ppc_vsr0_upper_regnum != -1;
>     int have_ppr = tdep->ppc_ppr_regnum != -1;
> @@ -1170,7 +1170,7 @@ ppc_linux_sigtramp_cache (struct frame_info *this_frame,
>     CORE_ADDR fpregs;
>     int i;
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>   
>     base = get_frame_register_unsigned (this_frame,
> @@ -1341,7 +1341,7 @@ ppc_linux_get_syscall_number (struct gdbarch *gdbarch,
>   			      thread_info *thread)
>   {
>     struct regcache *regcache = get_thread_regcache (thread);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>   
>     /* Make sure we're in a 32- or 64-bit machine */
> @@ -1417,7 +1417,7 @@ static int
>   ppc_linux_syscall_record (struct regcache *regcache)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     ULONGEST scnum;
>     enum gdb_syscall syscall_gdb;
>     int ret;
> @@ -1507,7 +1507,7 @@ ppc_linux_record_signal (struct gdbarch *gdbarch, struct regcache *regcache,
>     const int SIGNAL_FRAMESIZE = 128;
>     const int sizeof_rt_sigframe = 1440 * 2 + 8 * 2 + 4 * 6 + 8 + 8 + 128 + 512;
>     ULONGEST sp;
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int i;
>   
>     for (i = 3; i <= 12; i++)
> @@ -2036,7 +2036,7 @@ static void
>   ppc_linux_init_abi (struct gdbarch_info info,
>   		    struct gdbarch *gdbarch)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     struct tdesc_arch_data *tdesc_data = info.tdesc_data;
>     static const char *const stap_integer_prefixes[] = { "i", NULL };
>     static const char *const stap_register_indirection_prefixes[] = { "(",
> diff --git a/gdb/ppc-netbsd-nat.c b/gdb/ppc-netbsd-nat.c
> index fb2dce501a4..91f18fbb83f 100644
> --- a/gdb/ppc-netbsd-nat.c
> +++ b/gdb/ppc-netbsd-nat.c
> @@ -52,7 +52,7 @@ static ppc_nbsd_nat_target the_ppc_nbsd_nat_target;
>   static int
>   getregs_supplies (struct gdbarch *gdbarch, int regnum)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     return ((regnum >= tdep->ppc_gp0_regnum
>   	   && regnum < tdep->ppc_gp0_regnum + ppc_num_gprs)
> @@ -68,7 +68,7 @@ getregs_supplies (struct gdbarch *gdbarch, int regnum)
>   static int
>   getfpregs_supplies (struct gdbarch *gdbarch, int regnum)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
>        point registers.  Traditionally, GDB's register set has still
> @@ -159,7 +159,7 @@ ppcnbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
>     struct switchframe sf;
>     struct callframe cf;
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int i;
>   
>     /* The stack pointer shouldn't be zero.  */
> diff --git a/gdb/ppc-netbsd-tdep.c b/gdb/ppc-netbsd-tdep.c
> index cb3d8d5e5df..d8dc494979a 100644
> --- a/gdb/ppc-netbsd-tdep.c
> +++ b/gdb/ppc-netbsd-tdep.c
> @@ -102,7 +102,7 @@ ppcnbsd_sigtramp_cache_init (const struct tramp_frame *self,
>   			     CORE_ADDR func)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     CORE_ADDR addr, base;
>     int i;
>   
> diff --git a/gdb/ppc-obsd-nat.c b/gdb/ppc-obsd-nat.c
> index 93e1024b589..e480f19dc73 100644
> --- a/gdb/ppc-obsd-nat.c
> +++ b/gdb/ppc-obsd-nat.c
> @@ -54,7 +54,7 @@ static ppc_obsd_nat_target the_ppc_obsd_nat_target;
>   static int
>   getfpregs_supplies (struct gdbarch *gdbarch, int regnum)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
>        point registers.  Traditionally, GDB's register set has still
> @@ -154,7 +154,7 @@ static int
>   ppcobsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     struct switchframe sf;
>     struct callframe cf;
>     int i, regnum;
> diff --git a/gdb/ppc-obsd-tdep.c b/gdb/ppc-obsd-tdep.c
> index a2924e35bbc..90fb5e3a399 100644
> --- a/gdb/ppc-obsd-tdep.c
> +++ b/gdb/ppc-obsd-tdep.c
> @@ -161,7 +161,7 @@ static struct trad_frame_cache *
>   ppcobsd_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     struct trad_frame_cache *cache;
>     CORE_ADDR addr, base, func;
> diff --git a/gdb/ppc-sysv-tdep.c b/gdb/ppc-sysv-tdep.c
> index 6c2fd1bfc99..ed6c2d4449d 100644
> --- a/gdb/ppc-sysv-tdep.c
> +++ b/gdb/ppc-sysv-tdep.c
> @@ -65,7 +65,7 @@ ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>   			      function_call_return_method return_method,
>   			      CORE_ADDR struct_addr)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     int opencl_abi = ppc_sysv_use_opencl_abi (value_type (function));
>     ULONGEST saved_sp;
> @@ -597,7 +597,7 @@ get_decimal_float_return_value (struct gdbarch *gdbarch, struct type *valtype,
>   				struct regcache *regcache, gdb_byte *readbuf,
>   				const gdb_byte *writebuf)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     gdb_assert (valtype->code () == TYPE_CODE_DECFLOAT);
>   
> @@ -675,7 +675,7 @@ do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *func_type,
>   			  gdb_byte *readbuf, const gdb_byte *writebuf,
>   			  int broken_gcc)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     int opencl_abi = func_type? ppc_sysv_use_opencl_abi (func_type) : 0;
>   
> @@ -1250,7 +1250,7 @@ ppc64_sysv_abi_push_val (struct gdbarch *gdbarch,
>   			 const bfd_byte *val, int len, int align,
>   			 struct ppc64_sysv_argpos *argpos)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int offset = 0;
>   
>     /* Enforce alignment of stack location, if requested.  */
> @@ -1300,7 +1300,7 @@ static void
>   ppc64_sysv_abi_push_integer (struct gdbarch *gdbarch, ULONGEST val,
>   			     struct ppc64_sysv_argpos *argpos)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     gdb_byte buf[PPC_MAX_REGISTER_SIZE];
>   
> @@ -1318,7 +1318,7 @@ ppc64_sysv_abi_push_freg (struct gdbarch *gdbarch,
>   			  struct type *type, const bfd_byte *val,
>   			  struct ppc64_sysv_argpos *argpos)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     if (tdep->soft_float)
>       return;
>   
> @@ -1403,7 +1403,7 @@ static void
>   ppc64_sysv_abi_push_vreg (struct gdbarch *gdbarch, const bfd_byte *val,
>   			  struct ppc64_sysv_argpos *argpos)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (argpos->regcache && argpos->vreg <= 13)
>       argpos->regcache->cooked_write (tdep->ppc_vr0_regnum + argpos->vreg, val);
> @@ -1419,7 +1419,7 @@ ppc64_sysv_abi_push_param (struct gdbarch *gdbarch,
>   			   struct type *type, const bfd_byte *val,
>   			   struct ppc64_sysv_argpos *argpos)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (type->code () == TYPE_CODE_FLT
>         || type->code () == TYPE_CODE_DECFLOAT)
> @@ -1545,7 +1545,7 @@ ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch,
>   				CORE_ADDR struct_addr)
>   {
>     CORE_ADDR func_addr = find_function_addr (function, NULL);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     int opencl_abi = ppc_sysv_use_opencl_abi (value_type (function));
>     ULONGEST back_chain;
> @@ -1739,7 +1739,7 @@ ppc64_sysv_abi_return_value_base (struct gdbarch *gdbarch, struct type *valtype,
>   				  struct regcache *regcache, gdb_byte *readbuf,
>   				  const gdb_byte *writebuf, int index)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     /* Integers live in GPRs starting at r3.  */
>     if ((valtype->code () == TYPE_CODE_INT
> @@ -1922,7 +1922,7 @@ ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct value *function,
>   			     struct type *valtype, struct regcache *regcache,
>   			     gdb_byte *readbuf, const gdb_byte *writebuf)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     struct type *func_type = function ? value_type (function) : NULL;
>     int opencl_abi = func_type? ppc_sysv_use_opencl_abi (func_type) : 0;
>     struct type *eltype;
> diff --git a/gdb/ppc64-tdep.c b/gdb/ppc64-tdep.c
> index 32931f72691..0437ca7e3f3 100644
> --- a/gdb/ppc64-tdep.c
> +++ b/gdb/ppc64-tdep.c
> @@ -89,7 +89,7 @@ ppc64_plt_entry_point (struct frame_info *frame, CORE_ADDR plt_off)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (frame);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     CORE_ADDR tocp;
>   
>     if (execution_direction == EXEC_REVERSE)
> diff --git a/gdb/riscv-linux-tdep.c b/gdb/riscv-linux-tdep.c
> index 387b8bdbc2f..5bda2e5c824 100644
> --- a/gdb/riscv-linux-tdep.c
> +++ b/gdb/riscv-linux-tdep.c
> @@ -179,7 +179,7 @@ riscv_linux_syscall_next_pc (struct frame_info *frame)
>   static void
>   riscv_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
>   
>     linux_init_abi (info, gdbarch, 0);
>   
> diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
> index 69f2123dcdb..2d41be96b20 100644
> --- a/gdb/riscv-tdep.c
> +++ b/gdb/riscv-tdep.c
> @@ -733,7 +733,7 @@ show_riscv_debug_variable (struct ui_file *file, int from_tty,
>   int
>   riscv_isa_xlen (struct gdbarch *gdbarch)
>   {
> -  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
>     return tdep->isa_features.xlen;
>   }
>   
> @@ -742,7 +742,7 @@ riscv_isa_xlen (struct gdbarch *gdbarch)
>   int
>   riscv_abi_xlen (struct gdbarch *gdbarch)
>   {
> -  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
>     return tdep->abi_features.xlen;
>   }
>   
> @@ -751,7 +751,7 @@ riscv_abi_xlen (struct gdbarch *gdbarch)
>   int
>   riscv_isa_flen (struct gdbarch *gdbarch)
>   {
> -  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
>     return tdep->isa_features.flen;
>   }
>   
> @@ -760,7 +760,7 @@ riscv_isa_flen (struct gdbarch *gdbarch)
>   int
>   riscv_abi_flen (struct gdbarch *gdbarch)
>   {
> -  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
>     return tdep->abi_features.flen;
>   }
>   
> @@ -769,7 +769,7 @@ riscv_abi_flen (struct gdbarch *gdbarch)
>   bool
>   riscv_abi_embedded (struct gdbarch *gdbarch)
>   {
> -  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
>     return tdep->abi_features.embedded;
>   }
>   
> @@ -786,7 +786,7 @@ riscv_has_fp_regs (struct gdbarch *gdbarch)
>   static bool
>   riscv_has_fp_abi (struct gdbarch *gdbarch)
>   {
> -  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
>     return tdep->abi_features.flen > 0;
>   }
>   
> @@ -910,7 +910,7 @@ riscv_register_name (struct gdbarch *gdbarch, int regnum)
>        will show up in 'info register all'.  Unless, we identify the
>        duplicate copies of these registers (in riscv_tdesc_unknown_reg) and
>        then hide the registers here by giving them no name.  */
> -  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
>     if (tdep->duplicate_fflags_regnum == regnum)
>       return NULL;
>     if (tdep->duplicate_frm_regnum == regnum)
> @@ -938,7 +938,7 @@ riscv_register_name (struct gdbarch *gdbarch, int regnum)
>   static struct type *
>   riscv_fpreg_d_type (struct gdbarch *gdbarch)
>   {
> -  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->riscv_fpreg_d_type == nullptr)
>       {
> @@ -1260,7 +1260,7 @@ riscv_is_regnum_a_named_csr (int regnum)
>   static bool
>   riscv_is_unknown_csr (struct gdbarch *gdbarch, int regnum)
>   {
> -  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
>     return (regnum >= tdep->unknown_csrs_first_regnum
>   	  && regnum < (tdep->unknown_csrs_first_regnum
>   		       + tdep->unknown_csrs_count));
> @@ -3600,7 +3600,7 @@ riscv_tdesc_unknown_reg (struct gdbarch *gdbarch, tdesc_feature *feature,
>        record their register numbers here.  */
>     if (strcmp (tdesc_feature_name (feature), riscv_freg_feature.name ()) == 0)
>       {
> -      riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
>         int *regnum_ptr = nullptr;
>   
>         if (strcmp (reg_name, "fflags") == 0)
> @@ -3631,7 +3631,7 @@ riscv_tdesc_unknown_reg (struct gdbarch *gdbarch, tdesc_feature *feature,
>        about register groups in riscv_register_reggroup_p.  */
>     if (strcmp (tdesc_feature_name (feature), riscv_csr_feature.name ()) == 0)
>       {
> -      riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
>         if (tdep->unknown_csrs_first_regnum == -1)
>   	tdep->unknown_csrs_first_regnum = possible_regnum;
>         gdb_assert (tdep->unknown_csrs_first_regnum
> @@ -3733,7 +3733,7 @@ riscv_gdbarch_init (struct gdbarch_info info,
>   	 we are looking for.  If it doesn't then we can't reuse this
>   	 gdbarch.  */
>         riscv_gdbarch_tdep *other_tdep
> -	= (riscv_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<riscv_gdbarch_tdep> (arches->gdbarch);
>   
>         if (other_tdep->isa_features != features
>   	  || other_tdep->abi_features != abi_features)
> @@ -3858,7 +3858,7 @@ riscv_next_pc (struct regcache *regcache, CORE_ADDR pc)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
>     const riscv_gdbarch_tdep *tdep
> -    = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +    = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
>     struct riscv_insn insn;
>     CORE_ADDR next_pc;
>   
> diff --git a/gdb/rl78-tdep.c b/gdb/rl78-tdep.c
> index 6ea0473081d..2462e7a191d 100644
> --- a/gdb/rl78-tdep.c
> +++ b/gdb/rl78-tdep.c
> @@ -267,7 +267,7 @@ struct rl78_prologue
>   static struct type *
>   rl78_psw_type (struct gdbarch *gdbarch)
>   {
> -  rl78_gdbarch_tdep *tdep = (rl78_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  rl78_gdbarch_tdep *tdep = gdbarch_tdep<rl78_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->rl78_psw_type == NULL)
>       {
> @@ -291,7 +291,7 @@ rl78_psw_type (struct gdbarch *gdbarch)
>   static struct type *
>   rl78_register_type (struct gdbarch *gdbarch, int reg_nr)
>   {
> -  rl78_gdbarch_tdep *tdep = (rl78_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  rl78_gdbarch_tdep *tdep = gdbarch_tdep<rl78_gdbarch_tdep> (gdbarch);
>   
>     if (reg_nr == RL78_PC_REGNUM)
>       return tdep->rl78_code_pointer;
> @@ -1248,7 +1248,7 @@ rl78_return_value (struct gdbarch *gdbarch,
>   {
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     ULONGEST valtype_len = TYPE_LENGTH (valtype);
> -  rl78_gdbarch_tdep *tdep = (rl78_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  rl78_gdbarch_tdep *tdep = gdbarch_tdep<rl78_gdbarch_tdep> (gdbarch);
>     int is_g10 = tdep->elf_flags & E_FLAG_RL78_G10;
>   
>     if (valtype_len > 8)
> @@ -1394,7 +1394,7 @@ rl78_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          arches = gdbarch_list_lookup_by_info (arches->next, &info))
>       {
>         rl78_gdbarch_tdep *tdep
> -	= (rl78_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<rl78_gdbarch_tdep> (arches->gdbarch);
>   
>         if (tdep->elf_flags != elf_flags)
>   	continue;
> diff --git a/gdb/rs6000-aix-nat.c b/gdb/rs6000-aix-nat.c
> index 8563aea313a..8697d27b4ed 100644
> --- a/gdb/rs6000-aix-nat.c
> +++ b/gdb/rs6000-aix-nat.c
> @@ -115,7 +115,7 @@ static rs6000_nat_target the_rs6000_nat_target;
>   static int
>   regmap (struct gdbarch *gdbarch, int regno, int *isfloat)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     *isfloat = 0;
>     if (tdep->ppc_gp0_regnum <= regno
> @@ -317,7 +317,7 @@ rs6000_nat_target::fetch_registers (struct regcache *regcache, int regno)
>   
>     else
>       {
> -      ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>         /* Read 32 general purpose registers.  */
>         for (regno = tdep->ppc_gp0_regnum;
> @@ -359,7 +359,7 @@ rs6000_nat_target::store_registers (struct regcache *regcache, int regno)
>   
>     else
>       {
> -      ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>         /* Write general purpose registers first.  */
>         for (regno = tdep->ppc_gp0_regnum;
> diff --git a/gdb/rs6000-aix-tdep.c b/gdb/rs6000-aix-tdep.c
> index ead03bf8819..c15a10c19b4 100644
> --- a/gdb/rs6000-aix-tdep.c
> +++ b/gdb/rs6000-aix-tdep.c
> @@ -75,7 +75,7 @@ aix_sighandle_frame_cache (struct frame_info *this_frame,
>     LONGEST backchain;
>     CORE_ADDR base, base_orig, func;
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     struct trad_frame_cache *this_trad_cache;
>   
> @@ -261,7 +261,7 @@ rs6000_aix_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   					 void *cb_data,
>   					 const struct regcache *regcache)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     if (tdep->wordsize == 4)
>       cb (".reg", 592, 592, &rs6000_aix32_regset, NULL, cb_data);
>     else
> @@ -292,7 +292,7 @@ rs6000_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>   			function_call_return_method return_method,
>   			CORE_ADDR struct_addr)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     int ii;
>     int len = 0;
> @@ -522,7 +522,7 @@ rs6000_return_value (struct gdbarch *gdbarch, struct value *function,
>   		     struct type *valtype, struct regcache *regcache,
>   		     gdb_byte *readbuf, const gdb_byte *writebuf)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>   
>     /* The calling convention this function implements assumes the
> @@ -660,7 +660,7 @@ rs6000_convert_from_func_ptr_addr (struct gdbarch *gdbarch,
>   				   CORE_ADDR addr,
>   				   struct target_ops *targ)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     struct obj_section *s;
>   
> @@ -704,7 +704,7 @@ branch_dest (struct regcache *regcache, int opcode, int instr,
>   	     CORE_ADDR pc, CORE_ADDR safety)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     CORE_ADDR dest;
>     int immediate;
> @@ -972,7 +972,7 @@ static struct ld_info
>   rs6000_aix_extract_ld_info (struct gdbarch *gdbarch,
>   			    const gdb_byte *ldi_buf)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
>     const struct ld_info_desc desc
> @@ -1131,7 +1131,7 @@ rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch,
>   static void
>   rs6000_aix_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     /* RS6000/AIX does not support PT_STEP.  Has to be simulated.  */
>     set_gdbarch_software_single_step (gdbarch, rs6000_software_single_step);
> diff --git a/gdb/rs6000-lynx178-tdep.c b/gdb/rs6000-lynx178-tdep.c
> index 844d0a4ede2..dc13dd3fa73 100644
> --- a/gdb/rs6000-lynx178-tdep.c
> +++ b/gdb/rs6000-lynx178-tdep.c
> @@ -36,7 +36,7 @@ rs6000_lynx178_push_dummy_call (struct gdbarch *gdbarch,
>   				function_call_return_method return_method,
>   				CORE_ADDR struct_addr)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     int ii;
>     int len = 0;
> @@ -265,7 +265,7 @@ rs6000_lynx178_return_value (struct gdbarch *gdbarch, struct value *function,
>   			     struct type *valtype, struct regcache *regcache,
>   			     gdb_byte *readbuf, const gdb_byte *writebuf)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>   
>     /* The calling convention this function implements assumes the
> diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
> index 6815dfaa820..640459f1c28 100644
> --- a/gdb/rs6000-tdep.c
> +++ b/gdb/rs6000-tdep.c
> @@ -201,7 +201,7 @@ struct rs6000_framedata
>   int
>   vsx_register_p (struct gdbarch *gdbarch, int regno)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     if (tdep->ppc_vsr0_regnum < 0)
>       return 0;
>     else
> @@ -213,7 +213,7 @@ vsx_register_p (struct gdbarch *gdbarch, int regno)
>   int
>   altivec_register_p (struct gdbarch *gdbarch, int regno)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     if (tdep->ppc_vr0_regnum < 0 || tdep->ppc_vrsave_regnum < 0)
>       return 0;
>     else
> @@ -225,7 +225,7 @@ altivec_register_p (struct gdbarch *gdbarch, int regno)
>   int
>   spe_register_p (struct gdbarch *gdbarch, int regno)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     
>     /* Is it a reference to EV0 -- EV31, and do we have those?  */
>     if (IS_SPE_PSEUDOREG (tdep, regno))
> @@ -257,7 +257,7 @@ spe_register_p (struct gdbarch *gdbarch, int regno)
>   int
>   ppc_floating_point_unit_p (struct gdbarch *gdbarch)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     return (tdep->ppc_fp0_regnum >= 0
>   	  && tdep->ppc_fpscr_regnum >= 0);
> @@ -268,7 +268,7 @@ ppc_floating_point_unit_p (struct gdbarch *gdbarch)
>   int
>   ppc_altivec_support_p (struct gdbarch *gdbarch)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     return (tdep->ppc_vr0_regnum >= 0
>   	  && tdep->ppc_vrsave_regnum >= 0);
> @@ -297,7 +297,7 @@ set_sim_regno (int *table, int gdb_regno, int sim_regno)
>   static void
>   init_sim_regno_table (struct gdbarch *arch)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (arch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (arch);
>     int total_regs = gdbarch_num_regs (arch);
>     int *sim_regno = GDBARCH_OBSTACK_CALLOC (arch, total_regs, int);
>     int i;
> @@ -391,7 +391,7 @@ init_sim_regno_table (struct gdbarch *arch)
>   static int
>   rs6000_register_sim_regno (struct gdbarch *gdbarch, int reg)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int sim_regno;
>   
>     if (tdep->sim_regno == NULL)
> @@ -522,7 +522,7 @@ ppc_supply_gregset (const struct regset *regset, struct regcache *regcache,
>   		    int regnum, const void *gregs, size_t len)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     const struct ppc_reg_offsets *offsets
>       = (const struct ppc_reg_offsets *) regset->regmap;
>     size_t offset;
> @@ -578,7 +578,7 @@ ppc_supply_fpregset (const struct regset *regset, struct regcache *regcache,
>     if (!ppc_floating_point_unit_p (gdbarch))
>       return;
>   
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     offsets = (const struct ppc_reg_offsets *) regset->regmap;
>     if (regnum == -1)
>       {
> @@ -611,7 +611,7 @@ ppc_collect_gregset (const struct regset *regset,
>   		     int regnum, void *gregs, size_t len)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     const struct ppc_reg_offsets *offsets
>       = (const struct ppc_reg_offsets *) regset->regmap;
>     size_t offset;
> @@ -668,7 +668,7 @@ ppc_collect_fpregset (const struct regset *regset,
>     if (!ppc_floating_point_unit_p (gdbarch))
>       return;
>   
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     offsets = (const struct ppc_reg_offsets *) regset->regmap;
>     if (regnum == -1)
>       {
> @@ -746,7 +746,7 @@ static int
>   rs6000_in_function_epilogue_frame_p (struct frame_info *curfrm,
>   				     struct gdbarch *gdbarch, CORE_ADDR pc)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     bfd_byte insn_buf[PPC_INSN_SIZE];
>     CORE_ADDR scan_pc, func_start, func_end, epilogue_start, epilogue_end;
> @@ -1042,7 +1042,7 @@ ppc_displaced_step_fixup (struct gdbarch *gdbarch,
>         if (insn & 0x1)
>   	{
>   	  /* Link register needs to be set to the next instruction's PC.  */
> -	  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +	  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   	  regcache_cooked_write_unsigned (regs,
>   					  tdep->ppc_lr_regnum,
>   					  from + PPC_INSN_SIZE);
> @@ -1590,7 +1590,7 @@ skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc, CORE_ADDR lim_pc,
>     int num_skip_non_prologue_insns = 0;
>     int r0_contains_arg = 0;
>     const struct bfd_arch_info *arch_info = gdbarch_bfd_arch_info (gdbarch);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>   
>     memset (fdata, 0, sizeof (struct rs6000_framedata));
> @@ -2310,7 +2310,7 @@ static CORE_ADDR
>   rs6000_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (frame);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     unsigned int ii, op;
>     int rel;
> @@ -2368,7 +2368,7 @@ rs6000_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
>   static struct type *
>   rs6000_builtin_type_vec64 (struct gdbarch *gdbarch)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->ppc_builtin_type_vec64)
>       {
> @@ -2413,7 +2413,7 @@ rs6000_builtin_type_vec64 (struct gdbarch *gdbarch)
>   static struct type *
>   rs6000_builtin_type_vec128 (struct gdbarch *gdbarch)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->ppc_builtin_type_vec128)
>       {
> @@ -2467,7 +2467,7 @@ rs6000_builtin_type_vec128 (struct gdbarch *gdbarch)
>   static const char *
>   rs6000_register_name (struct gdbarch *gdbarch, int regno)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     /* The upper half "registers" have names in the XML description,
>        but we present only the low GPRs and the full 64-bit registers
> @@ -2605,7 +2605,7 @@ rs6000_register_name (struct gdbarch *gdbarch, int regno)
>   static struct type *
>   rs6000_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     /* These are the e500 pseudo-registers.  */
>     if (IS_SPE_PSEUDOREG (tdep, regnum))
> @@ -2644,7 +2644,7 @@ static int
>   rs6000_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
>   				   const struct reggroup *group)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (IS_V_ALIAS_PSEUDOREG (tdep, regnum))
>       return 0;
> @@ -2659,7 +2659,7 @@ static int
>   rs6000_convert_register_p (struct gdbarch *gdbarch, int regnum,
>   			   struct type *type)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     return (tdep->ppc_fp0_regnum >= 0
>   	  && regnum >= tdep->ppc_fp0_regnum
> @@ -2744,7 +2744,7 @@ e500_move_ev_register (move_ev_register_func move,
>   		       struct regcache *regcache, int ev_reg, void *buffer)
>   {
>     struct gdbarch *arch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (arch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (arch);
>     int reg_index;
>     gdb_byte *byte_buffer = (gdb_byte *) buffer;
>     enum register_status status;
> @@ -2785,7 +2785,7 @@ e500_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
>   			   int ev_reg, gdb_byte *buffer)
>   {
>     struct gdbarch *arch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int reg_index;
>     enum register_status status;
>   
> @@ -2826,7 +2826,7 @@ static enum register_status
>   dfp_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
>   			   int reg_nr, gdb_byte *buffer)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int reg_index, fp0;
>     enum register_status status;
>   
> @@ -2866,7 +2866,7 @@ static void
>   dfp_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
>   			    int reg_nr, const gdb_byte *buffer)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int reg_index, fp0;
>   
>     if (IS_DFP_PSEUDOREG (tdep, reg_nr))
> @@ -2903,7 +2903,7 @@ v_alias_pseudo_register_read (struct gdbarch *gdbarch,
>   			      readable_regcache *regcache, int reg_nr,
>   			      gdb_byte *buffer)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     gdb_assert (IS_V_ALIAS_PSEUDOREG (tdep, reg_nr));
>   
>     return regcache->raw_read (tdep->ppc_vr0_regnum
> @@ -2918,7 +2918,7 @@ v_alias_pseudo_register_write (struct gdbarch *gdbarch,
>   			       struct regcache *regcache,
>   			       int reg_nr, const gdb_byte *buffer)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     gdb_assert (IS_V_ALIAS_PSEUDOREG (tdep, reg_nr));
>   
>     regcache->raw_write (tdep->ppc_vr0_regnum
> @@ -2930,7 +2930,7 @@ static enum register_status
>   vsx_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
>   			   int reg_nr, gdb_byte *buffer)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int reg_index, vr0, fp0, vsr0_upper;
>     enum register_status status;
>   
> @@ -2978,7 +2978,7 @@ static void
>   vsx_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
>   			    int reg_nr, const gdb_byte *buffer)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int reg_index, vr0, fp0, vsr0_upper;
>   
>     if (IS_VSX_PSEUDOREG (tdep, reg_nr))
> @@ -3020,7 +3020,7 @@ static enum register_status
>   efp_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
>   			   int reg_nr, gdb_byte *buffer)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int reg_index, vr0;
>   
>     if (IS_EFP_PSEUDOREG (tdep, reg_nr))
> @@ -3049,7 +3049,7 @@ static void
>   efp_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
>   			    int reg_nr, const gdb_byte *buffer)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int reg_index, vr0;
>     int offset = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG ? 0 : 8;
>   
> @@ -3085,7 +3085,7 @@ rs6000_pseudo_register_read (struct gdbarch *gdbarch,
>   			     int reg_nr, gdb_byte *buffer)
>   {
>     struct gdbarch *regcache_arch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     gdb_assert (regcache_arch == gdbarch);
>   
> @@ -3116,7 +3116,7 @@ rs6000_pseudo_register_write (struct gdbarch *gdbarch,
>   			      int reg_nr, const gdb_byte *buffer)
>   {
>     struct gdbarch *regcache_arch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     gdb_assert (regcache_arch == gdbarch);
>   
> @@ -3147,7 +3147,7 @@ static void
>   dfp_ax_pseudo_register_collect (struct gdbarch *gdbarch,
>   				struct agent_expr *ax, int reg_nr)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int reg_index, fp0;
>   
>     if (IS_DFP_PSEUDOREG (tdep, reg_nr))
> @@ -3174,7 +3174,7 @@ static void
>   v_alias_pseudo_register_collect (struct gdbarch *gdbarch,
>   				 struct agent_expr *ax, int reg_nr)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     gdb_assert (IS_V_ALIAS_PSEUDOREG (tdep, reg_nr));
>   
>     ax_reg_mask (ax, tdep->ppc_vr0_regnum
> @@ -3188,7 +3188,7 @@ static void
>   vsx_ax_pseudo_register_collect (struct gdbarch *gdbarch,
>   				struct agent_expr *ax, int reg_nr)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int reg_index, vr0, fp0, vsr0_upper;
>   
>     if (IS_VSX_PSEUDOREG (tdep, reg_nr))
> @@ -3226,7 +3226,7 @@ static void
>   efp_ax_pseudo_register_collect (struct gdbarch *gdbarch,
>   				struct agent_expr *ax, int reg_nr)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int reg_index, vr0;
>   
>     if (IS_EFP_PSEUDOREG (tdep, reg_nr))
> @@ -3249,7 +3249,7 @@ static int
>   rs6000_ax_pseudo_register_collect (struct gdbarch *gdbarch,
>   				   struct agent_expr *ax, int reg_nr)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     if (IS_SPE_PSEUDOREG (tdep, reg_nr))
>       {
>         int reg_index = reg_nr - tdep->ppc_ev0_regnum;
> @@ -3289,7 +3289,7 @@ rs6000_gen_return_address (struct gdbarch *gdbarch,
>   			   struct agent_expr *ax, struct axs_value *value,
>   			   CORE_ADDR scope)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     value->type = register_type (gdbarch, tdep->ppc_lr_regnum);
>     value->kind = axs_lvalue_register;
>     value->u.reg = tdep->ppc_lr_regnum;
> @@ -3300,7 +3300,7 @@ rs6000_gen_return_address (struct gdbarch *gdbarch,
>   static int
>   rs6000_stab_reg_to_regnum (struct gdbarch *gdbarch, int num)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (0 <= num && num <= 31)
>       return tdep->ppc_gp0_regnum + num;
> @@ -3342,7 +3342,7 @@ rs6000_stab_reg_to_regnum (struct gdbarch *gdbarch, int num)
>   static int
>   rs6000_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int num)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (0 <= num && num <= 31)
>       return tdep->ppc_gp0_regnum + num;
> @@ -3561,7 +3561,7 @@ rs6000_frame_cache (struct frame_info *this_frame, void **this_cache)
>   {
>     struct rs6000_frame_cache *cache;
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     struct rs6000_framedata fdata;
>     int wordsize = tdep->wordsize;
> @@ -3797,7 +3797,7 @@ rs6000_epilogue_frame_cache (struct frame_info *this_frame, void **this_cache)
>   {
>     struct rs6000_frame_cache *cache;
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (*this_cache)
>       return (struct rs6000_frame_cache *) *this_cache;
> @@ -3918,7 +3918,7 @@ ppc_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
>   			    struct dwarf2_frame_state_reg *reg,
>   			    struct frame_info *this_frame)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     /* PPC32 and PPC64 ABI's are the same regarding volatile and
>        non-volatile registers.  We will use the same code for both.  */
> @@ -4229,7 +4229,7 @@ static int
>   ppc_process_record_op4 (struct gdbarch *gdbarch, struct regcache *regcache,
>   			CORE_ADDR addr, uint32_t insn)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int ext = PPC_FIELD (insn, 21, 11);
>     int vra = PPC_FIELD (insn, 11, 5);
>   
> @@ -4771,7 +4771,7 @@ static int
>   ppc_process_record_op6 (struct gdbarch *gdbarch, struct regcache *regcache,
>   			CORE_ADDR addr, uint32_t insn)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int subtype = PPC_FIELD (insn, 28, 4);
>     CORE_ADDR ea = 0;
>   
> @@ -4799,7 +4799,7 @@ static int
>   ppc_process_record_op19 (struct gdbarch *gdbarch, struct regcache *regcache,
>   			   CORE_ADDR addr, uint32_t insn)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int ext = PPC_EXTOP (insn);
>   
>     switch (ext & 0x01f)
> @@ -4855,7 +4855,7 @@ ppc_process_record_op31_177 (struct gdbarch *gdbarch,
>   {
>     int RA_opcode = PPC_RA(insn);
>     int as = PPC_FIELD (insn, 6, 3);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     switch (RA_opcode)
>       {
> @@ -4875,7 +4875,7 @@ static int
>   ppc_process_record_op31 (struct gdbarch *gdbarch, struct regcache *regcache,
>   			   CORE_ADDR addr, uint32_t insn)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int ext = PPC_EXTOP (insn);
>     int tmp, nr, nb = 0, i;
>     CORE_ADDR at_dcsz, ea = 0;
> @@ -5536,7 +5536,7 @@ static int
>   ppc_process_record_op59 (struct gdbarch *gdbarch, struct regcache *regcache,
>   			 CORE_ADDR addr, uint32_t insn)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int ext = PPC_EXTOP (insn);
>     int at = PPC_FIELD (insn, 6, 3);
>   
> @@ -5701,7 +5701,7 @@ ppc_process_record_op60_XX2 (struct gdbarch *gdbarch,
>   			     struct regcache *regcache,
>   			     CORE_ADDR addr, uint32_t insn)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int RA_opcode = PPC_RA(insn);
>   
>     switch (RA_opcode)
> @@ -5742,7 +5742,7 @@ static int
>   ppc_process_record_op60 (struct gdbarch *gdbarch, struct regcache *regcache,
>   			   CORE_ADDR addr, uint32_t insn)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int ext = PPC_EXTOP (insn);
>   
>     switch (ext >> 2)
> @@ -6097,7 +6097,7 @@ static int
>   ppc_process_record_op61 (struct gdbarch *gdbarch, struct regcache *regcache,
>   			   CORE_ADDR addr, uint32_t insn)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     ULONGEST ea = 0;
>     int size;
>   
> @@ -6156,7 +6156,7 @@ static int
>   ppc_process_record_op63 (struct gdbarch *gdbarch, struct regcache *regcache,
>   			   CORE_ADDR addr, uint32_t insn)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int ext = PPC_EXTOP (insn);
>     int tmp;
>   
> @@ -6453,7 +6453,7 @@ ppc_process_record_prefix_op42 (struct gdbarch *gdbarch,
>   				struct regcache *regcache,
>   				uint32_t insn_prefix, uint32_t insn_suffix)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int type = PPC_FIELD (insn_prefix, 6, 2);
>     int ST1 = PPC_FIELD (insn_prefix, 8, 1);
>   
> @@ -6489,7 +6489,7 @@ ppc_process_record_prefix_op59_XX3 (struct gdbarch *gdbarch,
>     int type = PPC_FIELD (insn_prefix, 6, 2);
>     int ST4 = PPC_FIELD (insn_prefix, 8, 4);
>     int at = PPC_FIELD (insn_suffix, 6, 3);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (type == 3)
>       {
> @@ -6603,7 +6603,7 @@ ppc_process_record_prefix_store (struct gdbarch *gdbarch,
>   				 CORE_ADDR addr, uint32_t insn_prefix,
>   				 uint32_t insn_suffix)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     ULONGEST iaddr = 0;
>     int size;
>     int R = PPC_BIT (insn_prefix, 11);
> @@ -6659,7 +6659,7 @@ ppc_process_record_prefix_op32 (struct gdbarch *gdbarch,
>     int type = PPC_FIELD (insn_prefix, 6, 2);
>     int ST1 = PPC_FIELD (insn_prefix, 8, 1);
>     int ST4 = PPC_FIELD (insn_prefix, 8, 4);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (type == 1)
>       {
> @@ -6713,7 +6713,7 @@ ppc_process_record_prefix_op33 (struct gdbarch *gdbarch,
>   {
>     int type = PPC_FIELD (insn_prefix, 6, 2);
>     int ST4 = PPC_FIELD (insn_prefix, 8, 4);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (type == 1)
>       {
> @@ -6751,7 +6751,7 @@ ppc_process_record_prefix_op34 (struct gdbarch *gdbarch,
>     int type = PPC_FIELD (insn_prefix, 6, 2);
>     int ST1 = PPC_FIELD (insn_prefix, 8, 1);
>     int ST4 = PPC_FIELD (insn_prefix, 8, 4);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (type == 1)
>       {
> @@ -6797,7 +6797,7 @@ ppc_process_record_prefix_store_vsx_ds_form (struct gdbarch *gdbarch,
>   					     uint32_t insn_prefix,
>   					     uint32_t insn_suffix)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     ULONGEST ea = 0;
>     int size;
>     int R = PPC_BIT (insn_prefix, 11);
> @@ -6850,7 +6850,7 @@ ppc_process_record_prefix_vsx_d_form (struct gdbarch *gdbarch,
>   				      uint32_t insn_prefix,
>   				      uint32_t insn_suffix)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     ULONGEST ea = 0;
>     int size;
>     int R = PPC_BIT (insn_prefix, 11);
> @@ -6907,7 +6907,7 @@ ppc_process_prefix_instruction (int insn_prefix, int insn_suffix,
>   {
>     int type = PPC_FIELD (insn_prefix, 6, 2);
>     int ST1 = PPC_FIELD (insn_prefix, 8, 1);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int op6;
>   
>     /* D-form has uses a 5-bit opcode in the instruction suffix */
> @@ -7086,7 +7086,7 @@ int
>   ppc_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
>   		      CORE_ADDR addr)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     uint32_t insn, insn_suffix;
>     int op6, tmp, i;
> @@ -8150,7 +8150,7 @@ rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>   	 meaningful, because 64-bit CPUs can run in 32-bit mode.  So, perform
>   	 separate word size check.  */
>         ppc_gdbarch_tdep *tdep
> -	= (ppc_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<ppc_gdbarch_tdep> (arches->gdbarch);
>         if (tdep && tdep->elf_abi != elf_abi)
>   	continue;
>         if (tdep && tdep->soft_float != soft_float)
> @@ -8452,7 +8452,7 @@ rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>   static void
>   rs6000_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (tdep == NULL)
>       return;
> diff --git a/gdb/rx-tdep.c b/gdb/rx-tdep.c
> index 2a24ebba2b6..c67d4057195 100644
> --- a/gdb/rx-tdep.c
> +++ b/gdb/rx-tdep.c
> @@ -964,7 +964,7 @@ rx_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          arches = gdbarch_list_lookup_by_info (arches->next, &info))
>       {
>         rx_gdbarch_tdep *tdep
> -	= (rx_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<rx_gdbarch_tdep> (arches->gdbarch);
>   
>         if (tdep->elf_flags != elf_flags)
>   	continue;
> diff --git a/gdb/s390-linux-tdep.c b/gdb/s390-linux-tdep.c
> index 9d4e2d09f2a..03611fe1d23 100644
> --- a/gdb/s390-linux-tdep.c
> +++ b/gdb/s390-linux-tdep.c
> @@ -79,7 +79,7 @@ static void
>   s390_write_pc (struct regcache *regcache, CORE_ADDR pc)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>   
>     regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
>   
> @@ -269,7 +269,7 @@ s390_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   				   void *cb_data,
>   				   const struct regcache *regcache)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     const int gregset_size = (tdep->abi == ABI_LINUX_S390 ?
>   			    s390_sizeof_gregset : s390x_sizeof_gregset);
>   
> @@ -390,7 +390,7 @@ s390_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
>   				  void **this_prologue_cache)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     int word_size = gdbarch_ptr_bit (gdbarch) / 8;
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     struct s390_sigtramp_unwind_cache *info;
> @@ -561,7 +561,7 @@ s390_linux_get_syscall_number (struct gdbarch *gdbarch,
>   			       thread_info *thread)
>   {
>     struct regcache *regs = get_thread_regcache (thread);
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     ULONGEST pc;
>     ULONGEST svc_number = -1;
> @@ -594,7 +594,7 @@ static int
>   s390_all_but_pc_registers_record (struct regcache *regcache)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     int i;
>   
>     for (i = 0; i < 16; i++)
> @@ -802,7 +802,7 @@ static int
>   s390_linux_syscall_record (struct regcache *regcache, LONGEST syscall_native)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     int ret;
>     enum gdb_syscall syscall_gdb;
>   
> @@ -853,7 +853,7 @@ static int
>   s390_linux_record_signal (struct gdbarch *gdbarch, struct regcache *regcache,
>   			  enum gdb_signal signal)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     /* There are two kinds of signal frames on s390. rt_sigframe is always
>        the larger one, so don't even bother with sigframe.  */
>     const int sizeof_rt_sigframe = (tdep->abi == ABI_LINUX_ZSERIES ?
> @@ -1117,7 +1117,7 @@ s390_init_linux_record_tdep (struct linux_record_tdep *record_tdep,
>   static void
>   s390_linux_init_abi_any (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>   
>     tdep->s390_syscall_record = s390_linux_syscall_record;
>   
> @@ -1152,7 +1152,7 @@ s390_linux_init_abi_any (struct gdbarch_info info, struct gdbarch *gdbarch)
>   static void
>   s390_linux_init_abi_31 (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>   
>     tdep->abi = ABI_LINUX_S390;
>   
> @@ -1168,7 +1168,7 @@ s390_linux_init_abi_31 (struct gdbarch_info info, struct gdbarch *gdbarch)
>   static void
>   s390_linux_init_abi_64 (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>   
>     tdep->abi = ABI_LINUX_ZSERIES;
>   
> diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c
> index 14b03a167d7..2aeb3a14637 100644
> --- a/gdb/s390-tdep.c
> +++ b/gdb/s390-tdep.c
> @@ -1045,7 +1045,7 @@ s390_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
>   static int
>   s390_register_call_saved (struct gdbarch *gdbarch, int regnum)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>   
>     switch (tdep->abi)
>       {
> @@ -1076,7 +1076,7 @@ s390_guess_tracepoint_registers (struct gdbarch *gdbarch,
>   				 struct regcache *regcache,
>   				 CORE_ADDR addr)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     int sz = register_size (gdbarch, S390_PSWA_REGNUM);
>     gdb_byte *reg = (gdb_byte *) alloca (sz);
>     ULONGEST pswm, pswa;
> @@ -1172,7 +1172,7 @@ enum { s390_dwarf_reg_r0l = ARRAY_SIZE (s390_dwarf_regmap) - 16 };
>   static int
>   s390_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     int gdb_reg = -1;
>   
>     /* In a 32-on-64 debug scenario, debug info refers to the full
> @@ -1231,7 +1231,7 @@ static struct value *
>   s390_value_from_register (struct gdbarch *gdbarch, struct type *type,
>   			  int regnum, struct frame_id frame_id)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     struct value *value = default_value_from_register (gdbarch, type,
>   						     regnum, frame_id);
>     check_typedef (type);
> @@ -1250,7 +1250,7 @@ s390_value_from_register (struct gdbarch *gdbarch, struct type *type,
>   static const char *
>   s390_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>   
>     if (regnum == tdep->pc_regnum)
>       return "pc";
> @@ -1284,7 +1284,7 @@ s390_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
>   static struct type *
>   s390_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>   
>     if (regnum == tdep->pc_regnum)
>       return builtin_type (gdbarch)->builtin_func_ptr;
> @@ -1308,7 +1308,7 @@ static enum register_status
>   s390_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
>   			   int regnum, gdb_byte *buf)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     int regsize = register_size (gdbarch, regnum);
>     ULONGEST val;
> @@ -1383,7 +1383,7 @@ static void
>   s390_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
>   			    int regnum, const gdb_byte *buf)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     int regsize = register_size (gdbarch, regnum);
>     ULONGEST val, psw;
> @@ -1442,7 +1442,7 @@ static int
>   s390_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
>   				 const struct reggroup *group)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>   
>     /* We usually save/restore the whole PSW, which includes PC and CC.
>        However, some older gdbservers may not support saving/restoring
> @@ -1470,7 +1470,7 @@ static int
>   s390_ax_pseudo_register_collect (struct gdbarch *gdbarch,
>   				 struct agent_expr *ax, int regnum)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     if (regnum == tdep->pc_regnum)
>       {
>         ax_reg_mask (ax, S390_PSWA_REGNUM);
> @@ -1504,7 +1504,7 @@ static int
>   s390_ax_pseudo_register_push_stack (struct gdbarch *gdbarch,
>   				    struct agent_expr *ax, int regnum)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     if (regnum == tdep->pc_regnum)
>       {
>         ax_reg (ax, S390_PSWA_REGNUM);
> @@ -1905,7 +1905,7 @@ s390_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>   		      function_call_return_method return_method,
>   		      CORE_ADDR struct_addr)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     int word_size = gdbarch_ptr_bit (gdbarch) / 8;
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     int i;
> @@ -2084,7 +2084,7 @@ s390_return_value (struct gdbarch *gdbarch, struct value *function,
>         break;
>       case TYPE_CODE_ARRAY:
>         {
> -	s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +	s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>   	rvc = (tdep->vector_abi == S390_VECTOR_ABI_128
>   	       && TYPE_LENGTH (type) <= 16 && type->is_vector ())
>   	  ? RETURN_VALUE_REGISTER_CONVENTION
> @@ -2168,7 +2168,7 @@ s390_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
>   static CORE_ADDR
>   s390_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     ULONGEST pc;
>     pc = frame_unwind_register_unsigned (next_frame, tdep->pc_regnum);
>     return gdbarch_addr_bits_remove (gdbarch, pc);
> @@ -2190,7 +2190,7 @@ static struct value *
>   s390_unwind_pseudo_register (struct frame_info *this_frame, int regnum)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     struct type *type = register_type (gdbarch, regnum);
>   
>     /* Unwind PC via PSW address.  */
> @@ -2775,7 +2775,7 @@ static CORE_ADDR
>   s390_record_address_mask (struct gdbarch *gdbarch, struct regcache *regcache,
>   			  CORE_ADDR val)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     ULONGEST pswm, pswa;
>     int am;
>     if (tdep->abi == ABI_LINUX_S390)
> @@ -2842,7 +2842,7 @@ s390_record_calc_disp_vsce (struct gdbarch *gdbarch, struct regcache *regcache,
>   			    uint8_t vx, uint8_t el, uint8_t es, uint16_t bd,
>   			    int8_t dh, CORE_ADDR *res)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     ULONGEST x;
>     gdb_byte buf[16];
> @@ -2885,7 +2885,7 @@ static int s390_popcnt (unsigned int x) {
>   static int
>   s390_record_gpr_g (struct gdbarch *gdbarch, struct regcache *regcache, int i)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + i))
>       return -1;
>     if (tdep->abi == ABI_LINUX_S390)
> @@ -2899,7 +2899,7 @@ s390_record_gpr_g (struct gdbarch *gdbarch, struct regcache *regcache, int i)
>   static int
>   s390_record_gpr_h (struct gdbarch *gdbarch, struct regcache *regcache, int i)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     if (tdep->abi == ABI_LINUX_S390)
>       {
>         if (record_full_arch_list_add_reg (regcache, S390_R0_UPPER_REGNUM + i))
> @@ -2939,7 +2939,7 @@ static int
>   s390_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
>   		     CORE_ADDR addr)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     uint16_t insn[3] = {0};
>     /* Instruction as bytes.  */
>     uint8_t ibyte[6];
> @@ -7178,7 +7178,7 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          arches = gdbarch_list_lookup_by_info (arches->next, &info))
>       {
>         s390_gdbarch_tdep *tmp
> -	= (s390_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<s390_gdbarch_tdep> (arches->gdbarch);
>   
>         if (!tmp)
>   	continue;
> diff --git a/gdb/sh-linux-tdep.c b/gdb/sh-linux-tdep.c
> index 2975a8f5d3d..f146f023add 100644
> --- a/gdb/sh-linux-tdep.c
> +++ b/gdb/sh-linux-tdep.c
> @@ -195,7 +195,7 @@ sh_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>     set_gdbarch_fetch_tls_load_module_address (gdbarch,
>   					     svr4_fetch_objfile_link_map);
>   
> -  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
>   
>     /* Remember regset characteristics.  The sizes should match
>        elf_gregset_t and elf_fpregset_t from Linux.  */
> diff --git a/gdb/sh-netbsd-tdep.c b/gdb/sh-netbsd-tdep.c
> index 4fbb53b49ff..49760337c4b 100644
> --- a/gdb/sh-netbsd-tdep.c
> +++ b/gdb/sh-netbsd-tdep.c
> @@ -63,7 +63,7 @@ static void
>   shnbsd_init_abi (struct gdbarch_info info,
>   		  struct gdbarch *gdbarch)
>   {
> -  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
>     nbsd_init_abi (info, gdbarch);
>   
>     tdep->core_gregmap = (struct sh_corefile_regmap *)regmap;
> diff --git a/gdb/sh-tdep.c b/gdb/sh-tdep.c
> index 2341a9beef6..062df860c81 100644
> --- a/gdb/sh-tdep.c
> +++ b/gdb/sh-tdep.c
> @@ -1554,7 +1554,7 @@ sh_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
>   static struct type *
>   sh_littlebyte_bigword_type (struct gdbarch *gdbarch)
>   {
> -  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->sh_littlebyte_bigword_type == NULL)
>       tdep->sh_littlebyte_bigword_type
> @@ -2146,7 +2146,7 @@ sh_corefile_supply_regset (const struct regset *regset,
>   			   int regnum, const void *regs, size_t len)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
>     const struct sh_corefile_regmap *regmap = (regset == &sh_corefile_gregset
>   					     ? tdep->core_gregmap
>   					     : tdep->core_fpregmap);
> @@ -2172,7 +2172,7 @@ sh_corefile_collect_regset (const struct regset *regset,
>   			    int regnum, void *regs, size_t len)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
>     const struct sh_corefile_regmap *regmap = (regset == &sh_corefile_gregset
>   					     ? tdep->core_gregmap
>   					     : tdep->core_fpregmap);
> @@ -2210,7 +2210,7 @@ sh_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   				 void *cb_data,
>   				 const struct regcache *regcache)
>   {
> -  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->core_gregmap != NULL)
>       cb (".reg", tdep->sizeof_gregset, tdep->sizeof_gregset,
> diff --git a/gdb/sparc-linux-tdep.c b/gdb/sparc-linux-tdep.c
> index 18196b2f075..66481ea7b8a 100644
> --- a/gdb/sparc-linux-tdep.c
> +++ b/gdb/sparc-linux-tdep.c
> @@ -254,7 +254,7 @@ static void
>   sparc_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
>   {
>     gdbarch *arch = regcache->arch ();
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
>     ULONGEST psr;
>   
>     regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
> @@ -421,7 +421,7 @@ static const struct regset sparc32_linux_fpregset =
>   static void
>   sparc32_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     linux_init_abi (info, gdbarch, 0);
>   
> diff --git a/gdb/sparc-netbsd-tdep.c b/gdb/sparc-netbsd-tdep.c
> index a97a772dba2..57c178511fa 100644
> --- a/gdb/sparc-netbsd-tdep.c
> +++ b/gdb/sparc-netbsd-tdep.c
> @@ -295,7 +295,7 @@ static const struct regset sparc32nbsd_fpregset =
>   void
>   sparc32nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     nbsd_init_abi (info, gdbarch);
>   
> diff --git a/gdb/sparc-sol2-tdep.c b/gdb/sparc-sol2-tdep.c
> index 28eb6f67601..a92e95ce71b 100644
> --- a/gdb/sparc-sol2-tdep.c
> +++ b/gdb/sparc-sol2-tdep.c
> @@ -196,7 +196,7 @@ static const struct frame_unwind sparc32_sol2_sigtramp_frame_unwind =
>   static void
>   sparc32_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     tdep->gregset = &sparc32_sol2_gregset;
>     tdep->sizeof_gregset = 152;
> diff --git a/gdb/sparc-tdep.c b/gdb/sparc-tdep.c
> index e540263a2fe..397f5489550 100644
> --- a/gdb/sparc-tdep.c
> +++ b/gdb/sparc-tdep.c
> @@ -425,7 +425,7 @@ sparc32_register_name (struct gdbarch *gdbarch, int regnum)
>   static struct type *
>   sparc_psr_type (struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->sparc_psr_type)
>       {
> @@ -447,7 +447,7 @@ sparc_psr_type (struct gdbarch *gdbarch)
>   static struct type *
>   sparc_fsr_type (struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->sparc_fsr_type)
>       {
> @@ -988,7 +988,7 @@ CORE_ADDR
>   sparc_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
>   			CORE_ADDR current_pc, struct sparc_frame_cache *cache)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>     unsigned long insn;
>     int offset = 0;
>     int dest = -1;
> @@ -1680,7 +1680,7 @@ sparc_analyze_control_transfer (struct regcache *regcache,
>   
>         /* Trap instruction (TRAP).  */
>         gdbarch *arch = regcache->arch ();
> -      sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
> +      sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
>         return tdep->step_trap (frame, insn);
>       }
>   
> @@ -1731,7 +1731,7 @@ static std::vector<CORE_ADDR>
>   sparc_software_single_step (struct regcache *regcache)
>   {
>     struct gdbarch *arch = regcache->arch ();
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
>     CORE_ADDR npc, nnpc;
>   
>     CORE_ADDR pc, orig_npc;
> @@ -1761,7 +1761,7 @@ static void
>   sparc_write_pc (struct regcache *regcache, CORE_ADDR pc)
>   {
>     gdbarch *arch = regcache->arch ();
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
>   
>     regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
>     regcache_cooked_write_unsigned (regcache, tdep->npc_regnum, pc + 4);
> @@ -1776,7 +1776,7 @@ sparc_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   				    void *cb_data,
>   				    const struct regcache *regcache)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     cb (".reg", tdep->sizeof_gregset, tdep->sizeof_gregset, tdep->gregset, NULL,
>         cb_data);
> diff --git a/gdb/sparc64-fbsd-tdep.c b/gdb/sparc64-fbsd-tdep.c
> index 8a288282772..76c682fd521 100644
> --- a/gdb/sparc64-fbsd-tdep.c
> +++ b/gdb/sparc64-fbsd-tdep.c
> @@ -222,7 +222,7 @@ static const struct regset sparc64fbsd_fpregset =
>   static void
>   sparc64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     /* Generic FreeBSD support. */
>     fbsd_init_abi (info, gdbarch);
> diff --git a/gdb/sparc64-linux-tdep.c b/gdb/sparc64-linux-tdep.c
> index 9ea72331e93..f5940cfcdee 100644
> --- a/gdb/sparc64-linux-tdep.c
> +++ b/gdb/sparc64-linux-tdep.c
> @@ -262,7 +262,7 @@ static void
>   sparc64_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
>   {
>     gdbarch *arch = regcache->arch ();
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
>     ULONGEST state;
>   
>     regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
> @@ -364,7 +364,7 @@ static const struct regset sparc64_linux_fpregset =
>   static void
>   sparc64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     linux_init_abi (info, gdbarch, 0);
>   
> diff --git a/gdb/sparc64-netbsd-tdep.c b/gdb/sparc64-netbsd-tdep.c
> index 29cd3b6f3ba..db368118f23 100644
> --- a/gdb/sparc64-netbsd-tdep.c
> +++ b/gdb/sparc64-netbsd-tdep.c
> @@ -248,7 +248,7 @@ static const struct regset sparc64nbsd_fpregset =
>   static void
>   sparc64nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     nbsd_init_abi (info, gdbarch);
>   
> diff --git a/gdb/sparc64-obsd-tdep.c b/gdb/sparc64-obsd-tdep.c
> index 05ebbd2e84a..d6470a51b65 100644
> --- a/gdb/sparc64-obsd-tdep.c
> +++ b/gdb/sparc64-obsd-tdep.c
> @@ -423,7 +423,7 @@ static const struct regset sparc64obsd_fpregset =
>   static void
>   sparc64obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     tdep->gregset = &sparc64obsd_gregset;
>     tdep->sizeof_gregset = 288;
> diff --git a/gdb/sparc64-sol2-tdep.c b/gdb/sparc64-sol2-tdep.c
> index 458f0320582..e656c359efa 100644
> --- a/gdb/sparc64-sol2-tdep.c
> +++ b/gdb/sparc64-sol2-tdep.c
> @@ -199,7 +199,7 @@ static const struct frame_unwind sparc64_sol2_sigtramp_frame_unwind =
>   static void
>   sparc64_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     tdep->gregset = &sparc64_sol2_gregset;
>     tdep->sizeof_gregset = 304;
> diff --git a/gdb/sparc64-tdep.c b/gdb/sparc64-tdep.c
> index 95496d33ad4..5ca5f2dca8c 100644
> --- a/gdb/sparc64-tdep.c
> +++ b/gdb/sparc64-tdep.c
> @@ -648,7 +648,7 @@ sparc64_structure_or_union_p (const struct type *type)
>   static struct type *
>   sparc64_pstate_type (struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->sparc64_pstate_type)
>       {
> @@ -675,7 +675,7 @@ sparc64_pstate_type (struct gdbarch *gdbarch)
>   static struct type *
>   sparc64_ccr_type (struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->sparc64_ccr_type == NULL)
>       {
> @@ -700,7 +700,7 @@ sparc64_ccr_type (struct gdbarch *gdbarch)
>   static struct type *
>   sparc64_fsr_type (struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->sparc64_fsr_type)
>       {
> @@ -733,7 +733,7 @@ sparc64_fsr_type (struct gdbarch *gdbarch)
>   static struct type *
>   sparc64_fprs_type (struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->sparc64_fprs_type)
>       {
> @@ -1806,7 +1806,7 @@ sparc64_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr)
>   void
>   sparc64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     tdep->pc_regnum = SPARC64_PC_REGNUM;
>     tdep->npc_regnum = SPARC64_NPC_REGNUM;
> diff --git a/gdb/tic6x-linux-tdep.c b/gdb/tic6x-linux-tdep.c
> index 5a93294361a..b2422d1ccc0 100644
> --- a/gdb/tic6x-linux-tdep.c
> +++ b/gdb/tic6x-linux-tdep.c
> @@ -45,7 +45,7 @@ static const gdb_byte tic6x_bkpt_bnop_le[] = { 0x22, 0xa1, 0x00, 0x00 };
>   static unsigned int
>   tic6x_register_sigcontext_offset (unsigned int regnum, struct gdbarch *gdbarch)
>   {
> -  tic6x_gdbarch_tdep *tdep = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  tic6x_gdbarch_tdep *tdep = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
>   
>     if (regnum == TIC6X_A4_REGNUM || regnum == TIC6X_A4_REGNUM + 2
>         || regnum == TIC6X_A4_REGNUM + 4)
> @@ -92,7 +92,7 @@ tic6x_linux_rt_sigreturn_init (const struct tramp_frame *self,
>   		    + TIC6X_SIGINFO_SIZE
>   		    + 4 + 4 /* uc_flags and *uc_link in struct ucontext.  */
>   		    + TIC6X_STACK_T_SIZE);
> -  tic6x_gdbarch_tdep *tdep = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  tic6x_gdbarch_tdep *tdep = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
>     unsigned int reg_offset;
>     unsigned int i;
>   
> @@ -165,7 +165,7 @@ extern struct target_so_ops dsbt_so_ops;
>   static void
>   tic6x_uclinux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  tic6x_gdbarch_tdep *tdep = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  tic6x_gdbarch_tdep *tdep = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
>   
>     linux_init_abi (info, gdbarch, 0);
>   
> diff --git a/gdb/tic6x-tdep.c b/gdb/tic6x-tdep.c
> index 3e49030ab14..b7efcf18576 100644
> --- a/gdb/tic6x-tdep.c
> +++ b/gdb/tic6x-tdep.c
> @@ -325,7 +325,7 @@ tic6x_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
>   static const gdb_byte *
>   tic6x_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
>   {
> -  tic6x_gdbarch_tdep *tdep = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  tic6x_gdbarch_tdep *tdep = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
>   
>     *size = kind;
>   
> @@ -599,7 +599,7 @@ tic6x_get_next_pc (struct regcache *regcache, CORE_ADDR pc)
>         if (inst == TIC6X_INST_SWE)
>   	{
>   	  tic6x_gdbarch_tdep *tdep
> -	    = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +	    = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
>   
>   	  if (tdep->syscall_next_pc != NULL)
>   	    return tdep->syscall_next_pc (get_current_frame ());
> @@ -1217,7 +1217,7 @@ tic6x_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          arches = gdbarch_list_lookup_by_info (arches->next, &info))
>       {
>         tic6x_gdbarch_tdep *tdep
> -	= (tic6x_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<tic6x_gdbarch_tdep> (arches->gdbarch);
>   
>         if (has_gp != tdep->has_gp)
>   	continue;
> diff --git a/gdb/v850-tdep.c b/gdb/v850-tdep.c
> index a67310a2440..4de5faa6a47 100644
> --- a/gdb/v850-tdep.c
> +++ b/gdb/v850-tdep.c
> @@ -511,7 +511,7 @@ v850_use_struct_convention (struct gdbarch *gdbarch, struct type *type)
>   {
>     int i;
>     struct type *fld_type, *tgt_type;
> -  v850_gdbarch_tdep *tdep = (v850_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  v850_gdbarch_tdep *tdep = gdbarch_tdep<v850_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->abi == V850_ABI_RH850)
>       {
> @@ -1023,7 +1023,7 @@ v850_push_dummy_call (struct gdbarch *gdbarch,
>     int argnum;
>     int arg_space = 0;
>     int stack_offset;
> -  v850_gdbarch_tdep *tdep = (v850_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  v850_gdbarch_tdep *tdep = gdbarch_tdep<v850_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->abi == V850_ABI_RH850)
>       stack_offset = 0;
> @@ -1374,7 +1374,7 @@ v850_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          arches = gdbarch_list_lookup_by_info (arches->next, &info))
>       {
>         v850_gdbarch_tdep *tdep
> -	= (v850_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<v850_gdbarch_tdep> (arches->gdbarch);
>   
>         if (tdep->e_flags != e_flags || tdep->e_machine != e_machine)
>   	continue;
> diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
> index 11f54302b11..63869b38ff9 100644
> --- a/gdb/windows-nat.c
> +++ b/gdb/windows-nat.c
> @@ -471,7 +471,7 @@ windows_fetch_one_register (struct regcache *regcache,
>   
>     char *context_offset = context_ptr + mappings[r];
>     struct gdbarch *gdbarch = regcache->arch ();
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     gdb_assert (!gdbarch_read_pc_p (gdbarch));
>     gdb_assert (gdbarch_pc_regnum (gdbarch) >= 0);
> diff --git a/gdb/xtensa-linux-nat.c b/gdb/xtensa-linux-nat.c
> index 5a08824a680..d005c9d8f78 100644
> --- a/gdb/xtensa-linux-nat.c
> +++ b/gdb/xtensa-linux-nat.c
> @@ -62,7 +62,7 @@ fill_gregset (const struct regcache *regcache,
>     int i;
>     xtensa_elf_gregset_t *regs = (xtensa_elf_gregset_t *) gregsetp;
>     struct gdbarch *gdbarch = regcache->arch ();
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     if (regnum == gdbarch_pc_regnum (gdbarch) || regnum == -1)
>       regcache->raw_collect (gdbarch_pc_regnum (gdbarch), &regs->pc);
> @@ -124,7 +124,7 @@ supply_gregset_reg (struct regcache *regcache,
>     xtensa_elf_gregset_t *regs = (xtensa_elf_gregset_t *) gregsetp;
>   
>     struct gdbarch *gdbarch = regcache->arch ();
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     if (regnum == gdbarch_pc_regnum (gdbarch) || regnum == -1)
>       regcache->raw_supply (gdbarch_pc_regnum (gdbarch), &regs->pc);
> diff --git a/gdb/xtensa-linux-tdep.c b/gdb/xtensa-linux-tdep.c
> index ef55319fd09..600b59b8894 100644
> --- a/gdb/xtensa-linux-tdep.c
> +++ b/gdb/xtensa-linux-tdep.c
> @@ -99,7 +99,7 @@ xtensa_linux_gdb_signal_to_target (struct gdbarch *gdbarch,
>   static void
>   xtensa_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->num_nopriv_regs < tdep->num_regs)
>       {
> diff --git a/gdb/xtensa-tdep.c b/gdb/xtensa-tdep.c
> index b6558838e44..f881870e244 100644
> --- a/gdb/xtensa-tdep.c
> +++ b/gdb/xtensa-tdep.c
> @@ -116,7 +116,7 @@ static unsigned int xtensa_debug_level = 0;
>   static int
>   windowing_enabled (struct gdbarch *gdbarch, unsigned int ps)
>   {
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     /* If we know CALL0 ABI is set explicitly,  say it is Call0.  */
>     if (tdep->call_abi == CallAbiCall0Only)
> @@ -130,7 +130,7 @@ windowing_enabled (struct gdbarch *gdbarch, unsigned int ps)
>   static int
>   arreg_number (struct gdbarch *gdbarch, int a_regnum, ULONGEST wb)
>   {
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>     int arreg;
>   
>     arreg = a_regnum - tdep->a0_base;
> @@ -145,7 +145,7 @@ arreg_number (struct gdbarch *gdbarch, int a_regnum, ULONGEST wb)
>   static int
>   areg_number (struct gdbarch *gdbarch, int ar_regnum, unsigned int wb)
>   {
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>     int areg;
>   
>     areg = ar_regnum - tdep->ar_base;
> @@ -226,7 +226,7 @@ static int
>   xtensa_find_register_by_name (struct gdbarch *gdbarch, const char *name)
>   {
>     int i;
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     for (i = 0; i < gdbarch_num_cooked_regs (gdbarch); i++)
>       if (strcasecmp (tdep->regmap[i].name, name) == 0)
> @@ -239,7 +239,7 @@ xtensa_find_register_by_name (struct gdbarch *gdbarch, const char *name)
>   static const char *
>   xtensa_register_name (struct gdbarch *gdbarch, int regnum)
>   {
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     /* Return the name stored in the register map.  */
>     if (regnum >= 0 && regnum < gdbarch_num_cooked_regs (gdbarch))
> @@ -254,7 +254,7 @@ xtensa_register_name (struct gdbarch *gdbarch, int regnum)
>   static struct type *
>   xtensa_register_type (struct gdbarch *gdbarch, int regnum)
>   {
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     /* Return signed integer for ARx and Ax registers.  */
>     if ((regnum >= tdep->ar_base
> @@ -339,7 +339,7 @@ static int
>   xtensa_reg_to_regnum (struct gdbarch *gdbarch, int regnum)
>   {
>     int i;
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     if (regnum >= 0 && regnum < 16)
>       return tdep->a0_base + regnum;
> @@ -542,7 +542,7 @@ xtensa_pseudo_register_read (struct gdbarch *gdbarch,
>   {
>     DEBUGTRACE ("xtensa_pseudo_register_read (... regnum = %d (%s) ...)\n",
>   	      regnum, xtensa_register_name (gdbarch, regnum));
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     /* Read aliases a0..a15, if this is a Windowed ABI.  */
>     if (tdep->isa_use_windowed_registers
> @@ -634,7 +634,7 @@ xtensa_pseudo_register_write (struct gdbarch *gdbarch,
>   {
>     DEBUGTRACE ("xtensa_pseudo_register_write (... regnum = %d (%s) ...)\n",
>   	      regnum, xtensa_register_name (gdbarch, regnum));
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     /* Renumber register, if aliases a0..a15 on Windowed ABI.  */
>     if (tdep->isa_use_windowed_registers
> @@ -767,7 +767,7 @@ xtensa_register_reggroup_p (struct gdbarch *gdbarch,
>   			    int regnum,
>   			    const struct reggroup *group)
>   {
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>     xtensa_register_t* reg = &tdep->regmap[regnum];
>     xtensa_register_type_t type = reg->type;
>     xtensa_register_group_t rg = reg->group;
> @@ -821,7 +821,7 @@ xtensa_supply_gregset (const struct regset *regset,
>   {
>     const xtensa_elf_gregset_t *regs = (const xtensa_elf_gregset_t *) gregs;
>     struct gdbarch *gdbarch = rc->arch ();
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>     int i;
>   
>     DEBUGTRACE ("xtensa_supply_gregset (..., regnum==%d, ...)\n", regnum);
> @@ -1050,7 +1050,7 @@ static struct frame_id
>   xtensa_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
>   {
>     CORE_ADDR pc, fp;
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     /* THIS-FRAME is a dummy frame.  Return a frame ID of that frame.  */
>   
> @@ -1105,7 +1105,7 @@ xtensa_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR current_pc)
>   {
>   #define RETURN_FP goto done
>   
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>     unsigned int fp_regnum = tdep->a0_base + 1;
>     CORE_ADDR start_addr;
>     xtensa_isa isa;
> @@ -1255,7 +1255,7 @@ xtensa_frame_cache (struct frame_info *this_frame, void **this_cache)
>     if (windowed)
>       {
>         LONGEST op1;
> -      xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>         /* Get WINDOWBASE, WINDOWSTART, and PS registers.  */
>         wb = get_frame_register_unsigned (this_frame,
> @@ -1417,7 +1417,7 @@ xtensa_frame_prev_register (struct frame_info *this_frame,
>     struct xtensa_frame_cache *cache;
>     ULONGEST saved_reg = 0;
>     int done = 1;
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     if (*this_cache == NULL)
>       *this_cache = xtensa_frame_cache (this_frame, this_cache);
> @@ -1546,7 +1546,7 @@ xtensa_extract_return_value (struct type *type,
>   
>     gdb_assert(len > 0);
>   
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>     if (tdep->call_abi != CallAbiCall0Only)
>       {
>         /* First, we have to find the caller window in the register file.  */
> @@ -1602,7 +1602,7 @@ xtensa_store_return_value (struct type *type,
>   
>     DEBUGTRACE ("xtensa_store_return_value (...)\n");
>   
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>     if (tdep->call_abi != CallAbiCall0Only)
>       {
>         regcache_raw_read_unsigned
> @@ -1686,7 +1686,7 @@ xtensa_push_dummy_call (struct gdbarch *gdbarch,
>   			CORE_ADDR struct_addr)
>   {
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>     int size, onstack_size;
>     gdb_byte *buf = (gdb_byte *) alloca (16);
>     CORE_ADDR ra, ps;
> @@ -1935,7 +1935,7 @@ xtensa_push_dummy_call (struct gdbarch *gdbarch,
>   static int
>   xtensa_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
>   {
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->isa_use_density_instructions)
>       return 2;
> @@ -2182,7 +2182,7 @@ call0_track_op (struct gdbarch *gdbarch, xtensa_c0reg_t dst[], xtensa_c0reg_t sr
>   {
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     unsigned litbase, litaddr, litval;
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     switch (opclass)
>       {
> @@ -2557,7 +2557,7 @@ call0_frame_cache (struct frame_info *this_frame,
>     CORE_ADDR body_pc=UINT_MAX;	/* PC, where prologue analysis stopped.  */
>     CORE_ADDR sp, fp, ra;
>     int fp_regnum = C0_SP, c0_hasfp = 0, c0_frmsz = 0, prev_sp = 0, to_stk;
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>    
>     sp = get_frame_register_unsigned
>       (this_frame, tdep->a0_base + 1);
> @@ -2710,7 +2710,7 @@ static int a11_was_saved;
>   static void
>   execute_l32e (struct gdbarch *gdbarch, int at, int as, int offset, CORE_ADDR wb)
>   {
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>     int atreg = arreg_number (gdbarch, tdep->a0_base + at, wb);
>     int asreg = arreg_number (gdbarch, tdep->a0_base + as, wb);
>     CORE_ADDR addr = xtensa_read_register (asreg) + offset;
> @@ -2740,7 +2740,7 @@ execute_l32e (struct gdbarch *gdbarch, int at, int as, int offset, CORE_ADDR wb)
>   static void
>   execute_s32e (struct gdbarch *gdbarch, int at, int as, int offset, CORE_ADDR wb)
>   {
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>     int atreg = arreg_number (gdbarch, tdep->a0_base + at, wb);
>     int asreg = arreg_number (gdbarch, tdep->a0_base + as, wb);
>     CORE_ADDR addr = xtensa_read_register (asreg) + offset;
> @@ -2774,7 +2774,7 @@ execute_code (struct gdbarch *gdbarch, CORE_ADDR current_pc, CORE_ADDR wb)
>     xtensa_opcode opc;
>     int insn_num = 0;
>     void (*func) (struct gdbarch *, int, int, int, CORE_ADDR);
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     uint32_t at, as, offset;
>   
> @@ -2905,7 +2905,7 @@ xtensa_window_interrupt_frame_cache (struct frame_info *this_frame,
>     CORE_ADDR ps, wb, ws, ra;
>     int epc1_regnum, i, regnum;
>     xtensa_exception_handler_t eh_type;
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     /* Read PS, WB, and WS from the hardware. Note that PS register
>        must be present, if Windowed ABI is supported.  */
> @@ -3019,7 +3019,7 @@ xtensa_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
>   
>         CORE_ADDR end_func;
>   
> -      xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>         if ((tdep->call_abi == CallAbiCall0Only)
>   	  && call0_ret (start_pc, prologue_sal.end))
>   	return start_pc;
> @@ -3041,7 +3041,7 @@ xtensa_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
>   static void
>   xtensa_verify_config (struct gdbarch *gdbarch)
>   {
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>     string_file log;
>   
>     /* Verify that we got a reasonable number of AREGS.  */
> diff --git a/gdb/z80-tdep.c b/gdb/z80-tdep.c
> index c2d906d1402..62d8ed96190 100644
> --- a/gdb/z80-tdep.c
> +++ b/gdb/z80-tdep.c
> @@ -308,7 +308,7 @@ z80_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR pc_beg, CORE_ADDR pc_end,
>   		   struct z80_unwind_cache *info)
>   {
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  z80_gdbarch_tdep *tdep = (z80_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  z80_gdbarch_tdep *tdep = gdbarch_tdep<z80_gdbarch_tdep> (gdbarch);
>     int addr_len = tdep->addr_length;
>     gdb_byte prologue[32]; /* max prologue is 24 bytes: __interrupt with local array */
>     int pos = 0;
> @@ -564,7 +564,7 @@ z80_frame_unwind_cache (struct frame_info *this_frame,
>     gdb_byte buf[sizeof(void*)];
>     struct z80_unwind_cache *info;
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  z80_gdbarch_tdep *tdep = (z80_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  z80_gdbarch_tdep *tdep = gdbarch_tdep<z80_gdbarch_tdep> (gdbarch);
>     int addr_len = tdep->addr_length;
>   
>     if (*this_prologue_cache)
> @@ -697,7 +697,7 @@ z80_frame_prev_register (struct frame_info *this_frame,
>   	  ULONGEST pc;
>   	  gdb_byte buf[3];
>   	  struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -	  z80_gdbarch_tdep *tdep = (z80_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +	  z80_gdbarch_tdep *tdep = gdbarch_tdep<z80_gdbarch_tdep> (gdbarch);
>   	  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>   
>   	  read_memory (info->saved_regs[Z80_PC_REGNUM].addr (),
> @@ -750,7 +750,7 @@ z80_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
>       }
>     else /* kind is non-RST address, use CALL instead, but it is dungerous */
>       {
> -      z80_gdbarch_tdep *tdep = (z80_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      z80_gdbarch_tdep *tdep = gdbarch_tdep<z80_gdbarch_tdep> (gdbarch);
>         gdb_byte *p = break_insn;
>         *p++ = 0xcd;
>         *p++ = (kind >> 0) & 0xff;

LGTM for the aarch64/arm bits.

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH 5/5] gdb: native target invalid architecture detection
  2022-05-31 16:51     ` Andrew Burgess
@ 2022-06-01  8:25       ` Luis Machado
  2022-06-01 21:06         ` John Baldwin
  2022-06-06 14:38         ` Andrew Burgess
  0 siblings, 2 replies; 83+ messages in thread
From: Luis Machado @ 2022-06-01  8:25 UTC (permalink / raw)
  To: Andrew Burgess, John Baldwin, gdb-patches

On 5/31/22 17:51, Andrew Burgess via Gdb-patches wrote:
> John Baldwin <jhb@FreeBSD.org> writes:
> 
>> On 5/31/22 7:30 AM, Andrew Burgess via Gdb-patches wrote:
>>> If GDB is asked to start a new inferior, or attach to an existing
>>> process, using a binary file for an architecture that does not match
>>> the current native target, then, currently, GDB will assert.  Here's
>>> an example session using current HEAD of master with GDB built for an
>>> x86-64 GNU/Linux native target, the binary being used is a RISC-V ELF:
>>>
>>>     $ ./gdb/gdb -q --data-directory ./gdb/data-directory/
>>>     (gdb) file /tmp/hello.rv32imc.x
>>>     Reading symbols from /tmp/hello.rv32imc.x...
>>>     (gdb) start
>>>     Temporary breakpoint 1 at 0x101b2: file hello.rv32.c, line 23.
>>>     Starting program: /tmp/hello.rv32imc.x
>>>     ../../src/gdb/gdbarch.h:166: internal-error: gdbarch_tdep: Assertion `dynamic_cast<TDepType *> (tdep) != nullptr' failed.
>>>     A problem internal to GDB has been detected,
>>>     further debugging may prove unreliable.
>>>
>>> The same error is encountered if, instead of starting a new inferior,
>>> the user tries to attach to an x86-64 process with a RISC-V binary set
>>> as the current executable.
>>>
>>> These errors are not specific to the x86-64/RISC-V pairing I'm using
>>> here, any attempt to use a binary for one architecture with a native
>>> target of a different architecture will result in a similar error.
>>>
>>> Clearly, attempting to use this cross-architecture combination is a
>>> user error, but I think GDB should do better than an assert; ideally a
>>> nice error should be printed.
>>>
>>> The problem we run into is that, when the user starts a new inferior,
>>> or attaches to an inferior, the inferior stops.  At this point GDB
>>> attempts to handle the stop, and this involves reading registers from
>>> the inferior.
>>>
>>> These register reads end up being done through the native target, so
>>> in the example above, we end up in the amd64_supply_fxsave function.
>>> However, these functions need a gdbarch.  The gdbarch is fetched from
>>> the register set, which was constructed using the gdbarch from the
>>> binary currently in use.  And so we end up in amd64_supply_fxsave
>>> using a RISC-V gdbarch.
>>>
>>> When we call:
>>>
>>>     i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>>>
>>> this will assert as the gdbarch_tdep data within the RISC-V gdbarch is
>>> of the type riscv_gdbarch_tdep not i386_gdbarch_tdep.
>>>
>>> The solution I propose in this commit is to add a new target_ops
>>> method supports_architecture_p.  This method will return true if a
>>> target can safely be used with a specific architecture, otherwise, the
>>> method returns false.
>>>
>>> I imagine that a result of true from this method doesn't guarantee
>>> that GDB can start an inferior of a given architecture, it just means
>>> that GDB will not crash if such an attempt is made.  A result of false
>>> is a hard stop; attempting to use this target with this architecture
>>> is not supported, and may cause GDB to crash.
>>>
>>> This distinction is important I think for things like remote targets,
>>> and possibly simulator targets.  We might imagine that GDB can ask a
>>> remote (or simulator) to start with a particular executable, and the
>>> target might still refuse for some reason.  But my thinking is that
>>> these refusals should be well handled (i.e. GDB should give a user
>>> friendly error), rather than crashing, as is the case with the native
>>> targets.
>>>
>>> For example, if I start gdbserver on an x86-64 machine like this:
>>>
>>>     gdbserver --multi :54321
>>>
>>> Then make use of this from a GDB session like this:
>>>
>>>     $ ./gdb/gdb -q --data-directory ./gdb/data-directory/
>>>     (gdb) file /tmp/hello.rv32imc.x
>>>     Reading symbols from /tmp/hello.rv32imc.x...
>>>     (gdb) target extended-remote :54321
>>>     Remote debugging using :54321
>>>     (gdb) run
>>>     Starting program: /tmp/hello.rv32imc.x
>>>     Running the default executable on the remote target failed; try "set remote exec-file"?
>>>     (gdb)
>>>
>>> Though the error is not very helpful in diagnosing the problem, we can
>>> see that GDB has not crashed, but has given the user an error.
>>>
>>> And so, the supports_architecture_p method is created to return true
>>> by default, then I override this in inf_child_target, where I compare
>>> the architecture in question with the default_bfd_arch.
>>>
>>> Finally, I've added calls to supports_architecture_p for the
>>> run (which covers run, start, starti) and attach commands.
>>>
>>> You will notice a lack of tests for this change.  I'm not sure of a
>>> good way that I can build a binary for a different architecture as
>>> part of a test, but if anyone has any ideas then I'll be happy to add
>>> a test here.
>>
>> Have you considered multi-arch cases such as running i386 binaries on an x86-64
>> host or 32-bit arm binaries on an AArch64 host?  Will we need to override this
>> method in certain targets (e.g. x86-linux-nat.c or x86-fbsd-nat.c) to support
>> such cases?
> 
> For the x86 examples you gave, I think these all have the bfd_arch_i386
> bfd architecture, so should work just fine.
> 
> But for the aarch64 case, I admit I don't know how this works.  A 32-bit
> ARM binary is going to have bfd_arch_arm, while the AArch64 target will
> be expecting a gdbarch with bfd_arch_aarch64.  But how GDB supports
> running the former on the latter, I don't know.
> 
> I notice there's aarch64-linux-nat.c and aarch32-linux-nat.c, I wonder
> if this has something to do with it...

aarch32 is the 32-bit state of aarch64, but the BFD architecture is different. So this won't work out-of-the-box.

> 
> Maybe someone with more ARM/AArch64 knowledge will chip in to fill in
> some of the blanks.

When attempting to run a 32-bit binary in 64-bit state, I get...

The target does not support architecture "armv7".

> 
> But to answer the general question, if there is a case that the existing
> code doesn't handle, then we can for sure override the new method in
> specific *-nat.c targets in order to handle weird cases.> 
> Thanks,
> Andrew
> 


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH 5/5] gdb: native target invalid architecture detection
  2022-06-01  8:25       ` Luis Machado
@ 2022-06-01 21:06         ` John Baldwin
  2022-06-01 21:21           ` Christophe Lyon
  2022-06-06 14:38         ` Andrew Burgess
  1 sibling, 1 reply; 83+ messages in thread
From: John Baldwin @ 2022-06-01 21:06 UTC (permalink / raw)
  To: Luis Machado, Andrew Burgess, gdb-patches

On 6/1/22 1:25 AM, Luis Machado wrote:
> On 5/31/22 17:51, Andrew Burgess via Gdb-patches wrote:
>> John Baldwin <jhb@FreeBSD.org> writes:
>>
>>> On 5/31/22 7:30 AM, Andrew Burgess via Gdb-patches wrote:
>>>> If GDB is asked to start a new inferior, or attach to an existing
>>>> process, using a binary file for an architecture that does not match
>>>> the current native target, then, currently, GDB will assert.  Here's
>>>> an example session using current HEAD of master with GDB built for an
>>>> x86-64 GNU/Linux native target, the binary being used is a RISC-V ELF:
>>>>
>>>>      $ ./gdb/gdb -q --data-directory ./gdb/data-directory/
>>>>      (gdb) file /tmp/hello.rv32imc.x
>>>>      Reading symbols from /tmp/hello.rv32imc.x...
>>>>      (gdb) start
>>>>      Temporary breakpoint 1 at 0x101b2: file hello.rv32.c, line 23.
>>>>      Starting program: /tmp/hello.rv32imc.x
>>>>      ../../src/gdb/gdbarch.h:166: internal-error: gdbarch_tdep: Assertion `dynamic_cast<TDepType *> (tdep) != nullptr' failed.
>>>>      A problem internal to GDB has been detected,
>>>>      further debugging may prove unreliable.
>>>>
>>>> The same error is encountered if, instead of starting a new inferior,
>>>> the user tries to attach to an x86-64 process with a RISC-V binary set
>>>> as the current executable.
>>>>
>>>> These errors are not specific to the x86-64/RISC-V pairing I'm using
>>>> here, any attempt to use a binary for one architecture with a native
>>>> target of a different architecture will result in a similar error.
>>>>
>>>> Clearly, attempting to use this cross-architecture combination is a
>>>> user error, but I think GDB should do better than an assert; ideally a
>>>> nice error should be printed.
>>>>
>>>> The problem we run into is that, when the user starts a new inferior,
>>>> or attaches to an inferior, the inferior stops.  At this point GDB
>>>> attempts to handle the stop, and this involves reading registers from
>>>> the inferior.
>>>>
>>>> These register reads end up being done through the native target, so
>>>> in the example above, we end up in the amd64_supply_fxsave function.
>>>> However, these functions need a gdbarch.  The gdbarch is fetched from
>>>> the register set, which was constructed using the gdbarch from the
>>>> binary currently in use.  And so we end up in amd64_supply_fxsave
>>>> using a RISC-V gdbarch.
>>>>
>>>> When we call:
>>>>
>>>>      i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>>>>
>>>> this will assert as the gdbarch_tdep data within the RISC-V gdbarch is
>>>> of the type riscv_gdbarch_tdep not i386_gdbarch_tdep.
>>>>
>>>> The solution I propose in this commit is to add a new target_ops
>>>> method supports_architecture_p.  This method will return true if a
>>>> target can safely be used with a specific architecture, otherwise, the
>>>> method returns false.
>>>>
>>>> I imagine that a result of true from this method doesn't guarantee
>>>> that GDB can start an inferior of a given architecture, it just means
>>>> that GDB will not crash if such an attempt is made.  A result of false
>>>> is a hard stop; attempting to use this target with this architecture
>>>> is not supported, and may cause GDB to crash.
>>>>
>>>> This distinction is important I think for things like remote targets,
>>>> and possibly simulator targets.  We might imagine that GDB can ask a
>>>> remote (or simulator) to start with a particular executable, and the
>>>> target might still refuse for some reason.  But my thinking is that
>>>> these refusals should be well handled (i.e. GDB should give a user
>>>> friendly error), rather than crashing, as is the case with the native
>>>> targets.
>>>>
>>>> For example, if I start gdbserver on an x86-64 machine like this:
>>>>
>>>>      gdbserver --multi :54321
>>>>
>>>> Then make use of this from a GDB session like this:
>>>>
>>>>      $ ./gdb/gdb -q --data-directory ./gdb/data-directory/
>>>>      (gdb) file /tmp/hello.rv32imc.x
>>>>      Reading symbols from /tmp/hello.rv32imc.x...
>>>>      (gdb) target extended-remote :54321
>>>>      Remote debugging using :54321
>>>>      (gdb) run
>>>>      Starting program: /tmp/hello.rv32imc.x
>>>>      Running the default executable on the remote target failed; try "set remote exec-file"?
>>>>      (gdb)
>>>>
>>>> Though the error is not very helpful in diagnosing the problem, we can
>>>> see that GDB has not crashed, but has given the user an error.
>>>>
>>>> And so, the supports_architecture_p method is created to return true
>>>> by default, then I override this in inf_child_target, where I compare
>>>> the architecture in question with the default_bfd_arch.
>>>>
>>>> Finally, I've added calls to supports_architecture_p for the
>>>> run (which covers run, start, starti) and attach commands.
>>>>
>>>> You will notice a lack of tests for this change.  I'm not sure of a
>>>> good way that I can build a binary for a different architecture as
>>>> part of a test, but if anyone has any ideas then I'll be happy to add
>>>> a test here.
>>>
>>> Have you considered multi-arch cases such as running i386 binaries on an x86-64
>>> host or 32-bit arm binaries on an AArch64 host?  Will we need to override this
>>> method in certain targets (e.g. x86-linux-nat.c or x86-fbsd-nat.c) to support
>>> such cases?
>>
>> For the x86 examples you gave, I think these all have the bfd_arch_i386
>> bfd architecture, so should work just fine.
>>
>> But for the aarch64 case, I admit I don't know how this works.  A 32-bit
>> ARM binary is going to have bfd_arch_arm, while the AArch64 target will
>> be expecting a gdbarch with bfd_arch_aarch64.  But how GDB supports
>> running the former on the latter, I don't know.
>>
>> I notice there's aarch64-linux-nat.c and aarch32-linux-nat.c, I wonder
>> if this has something to do with it...
> 
> aarch32 is the 32-bit state of aarch64, but the BFD architecture is different. So this won't work out-of-the-box.
> 
>>
>> Maybe someone with more ARM/AArch64 knowledge will chip in to fill in
>> some of the blanks.
> 
> When attempting to run a 32-bit binary in 64-bit state, I get...
> 
> The target does not support architecture "armv7".

Does Linux support running 32-bit binaries on a 64-bit aarch64 host?

-- 
John Baldwin

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH 5/5] gdb: native target invalid architecture detection
  2022-06-01 21:06         ` John Baldwin
@ 2022-06-01 21:21           ` Christophe Lyon
  2022-06-02 14:56             ` John Baldwin
  0 siblings, 1 reply; 83+ messages in thread
From: Christophe Lyon @ 2022-06-01 21:21 UTC (permalink / raw)
  To: John Baldwin, Luis Machado, Andrew Burgess, gdb-patches



On 6/1/22 23:06, John Baldwin wrote:
> On 6/1/22 1:25 AM, Luis Machado wrote:
>> On 5/31/22 17:51, Andrew Burgess via Gdb-patches wrote:
>>> John Baldwin <jhb@FreeBSD.org> writes:
>>>
>>>> On 5/31/22 7:30 AM, Andrew Burgess via Gdb-patches wrote:
>>>>> If GDB is asked to start a new inferior, or attach to an existing
>>>>> process, using a binary file for an architecture that does not match
>>>>> the current native target, then, currently, GDB will assert.  Here's
>>>>> an example session using current HEAD of master with GDB built for an
>>>>> x86-64 GNU/Linux native target, the binary being used is a RISC-V ELF:
>>>>>
>>>>>      $ ./gdb/gdb -q --data-directory ./gdb/data-directory/
>>>>>      (gdb) file /tmp/hello.rv32imc.x
>>>>>      Reading symbols from /tmp/hello.rv32imc.x...
>>>>>      (gdb) start
>>>>>      Temporary breakpoint 1 at 0x101b2: file hello.rv32.c, line 23.
>>>>>      Starting program: /tmp/hello.rv32imc.x
>>>>>      ../../src/gdb/gdbarch.h:166: internal-error: gdbarch_tdep: 
>>>>> Assertion `dynamic_cast<TDepType *> (tdep) != nullptr' failed.
>>>>>      A problem internal to GDB has been detected,
>>>>>      further debugging may prove unreliable.
>>>>>
>>>>> The same error is encountered if, instead of starting a new inferior,
>>>>> the user tries to attach to an x86-64 process with a RISC-V binary set
>>>>> as the current executable.
>>>>>
>>>>> These errors are not specific to the x86-64/RISC-V pairing I'm using
>>>>> here, any attempt to use a binary for one architecture with a native
>>>>> target of a different architecture will result in a similar error.
>>>>>
>>>>> Clearly, attempting to use this cross-architecture combination is a
>>>>> user error, but I think GDB should do better than an assert; ideally a
>>>>> nice error should be printed.
>>>>>
>>>>> The problem we run into is that, when the user starts a new inferior,
>>>>> or attaches to an inferior, the inferior stops.  At this point GDB
>>>>> attempts to handle the stop, and this involves reading registers from
>>>>> the inferior.
>>>>>
>>>>> These register reads end up being done through the native target, so
>>>>> in the example above, we end up in the amd64_supply_fxsave function.
>>>>> However, these functions need a gdbarch.  The gdbarch is fetched from
>>>>> the register set, which was constructed using the gdbarch from the
>>>>> binary currently in use.  And so we end up in amd64_supply_fxsave
>>>>> using a RISC-V gdbarch.
>>>>>
>>>>> When we call:
>>>>>
>>>>>      i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> 
>>>>> (gdbarch);
>>>>>
>>>>> this will assert as the gdbarch_tdep data within the RISC-V gdbarch is
>>>>> of the type riscv_gdbarch_tdep not i386_gdbarch_tdep.
>>>>>
>>>>> The solution I propose in this commit is to add a new target_ops
>>>>> method supports_architecture_p.  This method will return true if a
>>>>> target can safely be used with a specific architecture, otherwise, the
>>>>> method returns false.
>>>>>
>>>>> I imagine that a result of true from this method doesn't guarantee
>>>>> that GDB can start an inferior of a given architecture, it just means
>>>>> that GDB will not crash if such an attempt is made.  A result of false
>>>>> is a hard stop; attempting to use this target with this architecture
>>>>> is not supported, and may cause GDB to crash.
>>>>>
>>>>> This distinction is important I think for things like remote targets,
>>>>> and possibly simulator targets.  We might imagine that GDB can ask a
>>>>> remote (or simulator) to start with a particular executable, and the
>>>>> target might still refuse for some reason.  But my thinking is that
>>>>> these refusals should be well handled (i.e. GDB should give a user
>>>>> friendly error), rather than crashing, as is the case with the native
>>>>> targets.
>>>>>
>>>>> For example, if I start gdbserver on an x86-64 machine like this:
>>>>>
>>>>>      gdbserver --multi :54321
>>>>>
>>>>> Then make use of this from a GDB session like this:
>>>>>
>>>>>      $ ./gdb/gdb -q --data-directory ./gdb/data-directory/
>>>>>      (gdb) file /tmp/hello.rv32imc.x
>>>>>      Reading symbols from /tmp/hello.rv32imc.x...
>>>>>      (gdb) target extended-remote :54321
>>>>>      Remote debugging using :54321
>>>>>      (gdb) run
>>>>>      Starting program: /tmp/hello.rv32imc.x
>>>>>      Running the default executable on the remote target failed; 
>>>>> try "set remote exec-file"?
>>>>>      (gdb)
>>>>>
>>>>> Though the error is not very helpful in diagnosing the problem, we can
>>>>> see that GDB has not crashed, but has given the user an error.
>>>>>
>>>>> And so, the supports_architecture_p method is created to return true
>>>>> by default, then I override this in inf_child_target, where I compare
>>>>> the architecture in question with the default_bfd_arch.
>>>>>
>>>>> Finally, I've added calls to supports_architecture_p for the
>>>>> run (which covers run, start, starti) and attach commands.
>>>>>
>>>>> You will notice a lack of tests for this change.  I'm not sure of a
>>>>> good way that I can build a binary for a different architecture as
>>>>> part of a test, but if anyone has any ideas then I'll be happy to add
>>>>> a test here.
>>>>
>>>> Have you considered multi-arch cases such as running i386 binaries 
>>>> on an x86-64
>>>> host or 32-bit arm binaries on an AArch64 host?  Will we need to 
>>>> override this
>>>> method in certain targets (e.g. x86-linux-nat.c or x86-fbsd-nat.c) 
>>>> to support
>>>> such cases?
>>>
>>> For the x86 examples you gave, I think these all have the bfd_arch_i386
>>> bfd architecture, so should work just fine.
>>>
>>> But for the aarch64 case, I admit I don't know how this works.  A 32-bit
>>> ARM binary is going to have bfd_arch_arm, while the AArch64 target will
>>> be expecting a gdbarch with bfd_arch_aarch64.  But how GDB supports
>>> running the former on the latter, I don't know.
>>>
>>> I notice there's aarch64-linux-nat.c and aarch32-linux-nat.c, I wonder
>>> if this has something to do with it...
>>
>> aarch32 is the 32-bit state of aarch64, but the BFD architecture is 
>> different. So this won't work out-of-the-box.
>>
>>>
>>> Maybe someone with more ARM/AArch64 knowledge will chip in to fill in
>>> some of the blanks.
>>
>> When attempting to run a 32-bit binary in 64-bit state, I get...
>>
>> The target does not support architecture "armv7".
> 
> Does Linux support running 32-bit binaries on a 64-bit aarch64 host?
> 
Yes. For instance one can start a docker container in aarch32 (32-bit) 
mode on a aarch64 host (provided the CPU supports both modes, which is 
not always the case)

Christophe

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH 5/5] gdb: native target invalid architecture detection
  2022-06-01 21:21           ` Christophe Lyon
@ 2022-06-02 14:56             ` John Baldwin
  0 siblings, 0 replies; 83+ messages in thread
From: John Baldwin @ 2022-06-02 14:56 UTC (permalink / raw)
  To: Christophe Lyon, Luis Machado, Andrew Burgess, gdb-patches

On 6/1/22 2:21 PM, Christophe Lyon wrote:
> 
> 
> On 6/1/22 23:06, John Baldwin wrote:
>> On 6/1/22 1:25 AM, Luis Machado wrote:
>>> On 5/31/22 17:51, Andrew Burgess via Gdb-patches wrote:
>>>> John Baldwin <jhb@FreeBSD.org> writes:
>>>>
>>>>> On 5/31/22 7:30 AM, Andrew Burgess via Gdb-patches wrote:
>>>>>> If GDB is asked to start a new inferior, or attach to an existing
>>>>>> process, using a binary file for an architecture that does not match
>>>>>> the current native target, then, currently, GDB will assert.  Here's
>>>>>> an example session using current HEAD of master with GDB built for an
>>>>>> x86-64 GNU/Linux native target, the binary being used is a RISC-V ELF:
>>>>>>
>>>>>>       $ ./gdb/gdb -q --data-directory ./gdb/data-directory/
>>>>>>       (gdb) file /tmp/hello.rv32imc.x
>>>>>>       Reading symbols from /tmp/hello.rv32imc.x...
>>>>>>       (gdb) start
>>>>>>       Temporary breakpoint 1 at 0x101b2: file hello.rv32.c, line 23.
>>>>>>       Starting program: /tmp/hello.rv32imc.x
>>>>>>       ../../src/gdb/gdbarch.h:166: internal-error: gdbarch_tdep:
>>>>>> Assertion `dynamic_cast<TDepType *> (tdep) != nullptr' failed.
>>>>>>       A problem internal to GDB has been detected,
>>>>>>       further debugging may prove unreliable.
>>>>>>
>>>>>> The same error is encountered if, instead of starting a new inferior,
>>>>>> the user tries to attach to an x86-64 process with a RISC-V binary set
>>>>>> as the current executable.
>>>>>>
>>>>>> These errors are not specific to the x86-64/RISC-V pairing I'm using
>>>>>> here, any attempt to use a binary for one architecture with a native
>>>>>> target of a different architecture will result in a similar error.
>>>>>>
>>>>>> Clearly, attempting to use this cross-architecture combination is a
>>>>>> user error, but I think GDB should do better than an assert; ideally a
>>>>>> nice error should be printed.
>>>>>>
>>>>>> The problem we run into is that, when the user starts a new inferior,
>>>>>> or attaches to an inferior, the inferior stops.  At this point GDB
>>>>>> attempts to handle the stop, and this involves reading registers from
>>>>>> the inferior.
>>>>>>
>>>>>> These register reads end up being done through the native target, so
>>>>>> in the example above, we end up in the amd64_supply_fxsave function.
>>>>>> However, these functions need a gdbarch.  The gdbarch is fetched from
>>>>>> the register set, which was constructed using the gdbarch from the
>>>>>> binary currently in use.  And so we end up in amd64_supply_fxsave
>>>>>> using a RISC-V gdbarch.
>>>>>>
>>>>>> When we call:
>>>>>>
>>>>>>       i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep>
>>>>>> (gdbarch);
>>>>>>
>>>>>> this will assert as the gdbarch_tdep data within the RISC-V gdbarch is
>>>>>> of the type riscv_gdbarch_tdep not i386_gdbarch_tdep.
>>>>>>
>>>>>> The solution I propose in this commit is to add a new target_ops
>>>>>> method supports_architecture_p.  This method will return true if a
>>>>>> target can safely be used with a specific architecture, otherwise, the
>>>>>> method returns false.
>>>>>>
>>>>>> I imagine that a result of true from this method doesn't guarantee
>>>>>> that GDB can start an inferior of a given architecture, it just means
>>>>>> that GDB will not crash if such an attempt is made.  A result of false
>>>>>> is a hard stop; attempting to use this target with this architecture
>>>>>> is not supported, and may cause GDB to crash.
>>>>>>
>>>>>> This distinction is important I think for things like remote targets,
>>>>>> and possibly simulator targets.  We might imagine that GDB can ask a
>>>>>> remote (or simulator) to start with a particular executable, and the
>>>>>> target might still refuse for some reason.  But my thinking is that
>>>>>> these refusals should be well handled (i.e. GDB should give a user
>>>>>> friendly error), rather than crashing, as is the case with the native
>>>>>> targets.
>>>>>>
>>>>>> For example, if I start gdbserver on an x86-64 machine like this:
>>>>>>
>>>>>>       gdbserver --multi :54321
>>>>>>
>>>>>> Then make use of this from a GDB session like this:
>>>>>>
>>>>>>       $ ./gdb/gdb -q --data-directory ./gdb/data-directory/
>>>>>>       (gdb) file /tmp/hello.rv32imc.x
>>>>>>       Reading symbols from /tmp/hello.rv32imc.x...
>>>>>>       (gdb) target extended-remote :54321
>>>>>>       Remote debugging using :54321
>>>>>>       (gdb) run
>>>>>>       Starting program: /tmp/hello.rv32imc.x
>>>>>>       Running the default executable on the remote target failed;
>>>>>> try "set remote exec-file"?
>>>>>>       (gdb)
>>>>>>
>>>>>> Though the error is not very helpful in diagnosing the problem, we can
>>>>>> see that GDB has not crashed, but has given the user an error.
>>>>>>
>>>>>> And so, the supports_architecture_p method is created to return true
>>>>>> by default, then I override this in inf_child_target, where I compare
>>>>>> the architecture in question with the default_bfd_arch.
>>>>>>
>>>>>> Finally, I've added calls to supports_architecture_p for the
>>>>>> run (which covers run, start, starti) and attach commands.
>>>>>>
>>>>>> You will notice a lack of tests for this change.  I'm not sure of a
>>>>>> good way that I can build a binary for a different architecture as
>>>>>> part of a test, but if anyone has any ideas then I'll be happy to add
>>>>>> a test here.
>>>>>
>>>>> Have you considered multi-arch cases such as running i386 binaries
>>>>> on an x86-64
>>>>> host or 32-bit arm binaries on an AArch64 host?  Will we need to
>>>>> override this
>>>>> method in certain targets (e.g. x86-linux-nat.c or x86-fbsd-nat.c)
>>>>> to support
>>>>> such cases?
>>>>
>>>> For the x86 examples you gave, I think these all have the bfd_arch_i386
>>>> bfd architecture, so should work just fine.
>>>>
>>>> But for the aarch64 case, I admit I don't know how this works.  A 32-bit
>>>> ARM binary is going to have bfd_arch_arm, while the AArch64 target will
>>>> be expecting a gdbarch with bfd_arch_aarch64.  But how GDB supports
>>>> running the former on the latter, I don't know.
>>>>
>>>> I notice there's aarch64-linux-nat.c and aarch32-linux-nat.c, I wonder
>>>> if this has something to do with it...
>>>
>>> aarch32 is the 32-bit state of aarch64, but the BFD architecture is
>>> different. So this won't work out-of-the-box.
>>>
>>>>
>>>> Maybe someone with more ARM/AArch64 knowledge will chip in to fill in
>>>> some of the blanks.
>>>
>>> When attempting to run a 32-bit binary in 64-bit state, I get...
>>>
>>> The target does not support architecture "armv7".
>>
>> Does Linux support running 32-bit binaries on a 64-bit aarch64 host?
>>
> Yes. For instance one can start a docker container in aarch32 (32-bit)
> mode on a aarch64 host (provided the CPU supports both modes, which is
> not always the case)

Ok.  FreeBSD supports this too, but I think it's fine to deal with this
by overriding the relevant method in the aarch64-*-nat.c classes.

-- 
John Baldwin

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH 5/5] gdb: native target invalid architecture detection
  2022-06-01  8:25       ` Luis Machado
  2022-06-01 21:06         ` John Baldwin
@ 2022-06-06 14:38         ` Andrew Burgess
  2022-06-06 17:48           ` Andrew Burgess
  1 sibling, 1 reply; 83+ messages in thread
From: Andrew Burgess @ 2022-06-06 14:38 UTC (permalink / raw)
  To: Luis Machado, John Baldwin, gdb-patches

Luis Machado via Gdb-patches <gdb-patches@sourceware.org> writes:

> On 5/31/22 17:51, Andrew Burgess via Gdb-patches wrote:
>> John Baldwin <jhb@FreeBSD.org> writes:
>> 
>>> On 5/31/22 7:30 AM, Andrew Burgess via Gdb-patches wrote:
>>>> If GDB is asked to start a new inferior, or attach to an existing
>>>> process, using a binary file for an architecture that does not match
>>>> the current native target, then, currently, GDB will assert.  Here's
>>>> an example session using current HEAD of master with GDB built for an
>>>> x86-64 GNU/Linux native target, the binary being used is a RISC-V ELF:
>>>>
>>>>     $ ./gdb/gdb -q --data-directory ./gdb/data-directory/
>>>>     (gdb) file /tmp/hello.rv32imc.x
>>>>     Reading symbols from /tmp/hello.rv32imc.x...
>>>>     (gdb) start
>>>>     Temporary breakpoint 1 at 0x101b2: file hello.rv32.c, line 23.
>>>>     Starting program: /tmp/hello.rv32imc.x
>>>>     ../../src/gdb/gdbarch.h:166: internal-error: gdbarch_tdep: Assertion `dynamic_cast<TDepType *> (tdep) != nullptr' failed.
>>>>     A problem internal to GDB has been detected,
>>>>     further debugging may prove unreliable.
>>>>
>>>> The same error is encountered if, instead of starting a new inferior,
>>>> the user tries to attach to an x86-64 process with a RISC-V binary set
>>>> as the current executable.
>>>>
>>>> These errors are not specific to the x86-64/RISC-V pairing I'm using
>>>> here, any attempt to use a binary for one architecture with a native
>>>> target of a different architecture will result in a similar error.
>>>>
>>>> Clearly, attempting to use this cross-architecture combination is a
>>>> user error, but I think GDB should do better than an assert; ideally a
>>>> nice error should be printed.
>>>>
>>>> The problem we run into is that, when the user starts a new inferior,
>>>> or attaches to an inferior, the inferior stops.  At this point GDB
>>>> attempts to handle the stop, and this involves reading registers from
>>>> the inferior.
>>>>
>>>> These register reads end up being done through the native target, so
>>>> in the example above, we end up in the amd64_supply_fxsave function.
>>>> However, these functions need a gdbarch.  The gdbarch is fetched from
>>>> the register set, which was constructed using the gdbarch from the
>>>> binary currently in use.  And so we end up in amd64_supply_fxsave
>>>> using a RISC-V gdbarch.
>>>>
>>>> When we call:
>>>>
>>>>     i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>>>>
>>>> this will assert as the gdbarch_tdep data within the RISC-V gdbarch is
>>>> of the type riscv_gdbarch_tdep not i386_gdbarch_tdep.
>>>>
>>>> The solution I propose in this commit is to add a new target_ops
>>>> method supports_architecture_p.  This method will return true if a
>>>> target can safely be used with a specific architecture, otherwise, the
>>>> method returns false.
>>>>
>>>> I imagine that a result of true from this method doesn't guarantee
>>>> that GDB can start an inferior of a given architecture, it just means
>>>> that GDB will not crash if such an attempt is made.  A result of false
>>>> is a hard stop; attempting to use this target with this architecture
>>>> is not supported, and may cause GDB to crash.
>>>>
>>>> This distinction is important I think for things like remote targets,
>>>> and possibly simulator targets.  We might imagine that GDB can ask a
>>>> remote (or simulator) to start with a particular executable, and the
>>>> target might still refuse for some reason.  But my thinking is that
>>>> these refusals should be well handled (i.e. GDB should give a user
>>>> friendly error), rather than crashing, as is the case with the native
>>>> targets.
>>>>
>>>> For example, if I start gdbserver on an x86-64 machine like this:
>>>>
>>>>     gdbserver --multi :54321
>>>>
>>>> Then make use of this from a GDB session like this:
>>>>
>>>>     $ ./gdb/gdb -q --data-directory ./gdb/data-directory/
>>>>     (gdb) file /tmp/hello.rv32imc.x
>>>>     Reading symbols from /tmp/hello.rv32imc.x...
>>>>     (gdb) target extended-remote :54321
>>>>     Remote debugging using :54321
>>>>     (gdb) run
>>>>     Starting program: /tmp/hello.rv32imc.x
>>>>     Running the default executable on the remote target failed; try "set remote exec-file"?
>>>>     (gdb)
>>>>
>>>> Though the error is not very helpful in diagnosing the problem, we can
>>>> see that GDB has not crashed, but has given the user an error.
>>>>
>>>> And so, the supports_architecture_p method is created to return true
>>>> by default, then I override this in inf_child_target, where I compare
>>>> the architecture in question with the default_bfd_arch.
>>>>
>>>> Finally, I've added calls to supports_architecture_p for the
>>>> run (which covers run, start, starti) and attach commands.
>>>>
>>>> You will notice a lack of tests for this change.  I'm not sure of a
>>>> good way that I can build a binary for a different architecture as
>>>> part of a test, but if anyone has any ideas then I'll be happy to add
>>>> a test here.
>>>
>>> Have you considered multi-arch cases such as running i386 binaries on an x86-64
>>> host or 32-bit arm binaries on an AArch64 host?  Will we need to override this
>>> method in certain targets (e.g. x86-linux-nat.c or x86-fbsd-nat.c) to support
>>> such cases?
>> 
>> For the x86 examples you gave, I think these all have the bfd_arch_i386
>> bfd architecture, so should work just fine.
>> 
>> But for the aarch64 case, I admit I don't know how this works.  A 32-bit
>> ARM binary is going to have bfd_arch_arm, while the AArch64 target will
>> be expecting a gdbarch with bfd_arch_aarch64.  But how GDB supports
>> running the former on the latter, I don't know.
>> 
>> I notice there's aarch64-linux-nat.c and aarch32-linux-nat.c, I wonder
>> if this has something to do with it...
>
> aarch32 is the 32-bit state of aarch64, but the BFD architecture is
> different. So this won't work out-of-the-box.

If I understand correctly a aarch64 binary will have bfd_arch_aarch64,
and a aarch32 (armv7?) binary will be bfd_arch_arm.

What I don't understand, is how this all hangs together when running on
an aarch64 machine, using a native target.

Unless I'm missing something (please let me know if I am) then there's
just a single native linux target, the_aarch64_linux_nat_target, which
is registered from _initialize_aarch64_linux_nat in
aarch64-linux-nat.c.

In aarch64_linux_nat_target::fetch_registers, we assume the gdbarch_tdep
is of type aarch64_gdbarch_tdep, so this will only work for
bfd_arch_aarch64 binaries.

Then there's the_arm_linux_nat_target, from arm-linux-nat.c, which has
arm_linux_nat_target::fetch_registers, which assumed gdbarch_tdep will
be of type arm_gdbarch_tdep, so will only work for bfd_arch_arm targets.

So, I guess, if we can debug bfd_arch_arm and bfd_arch_aarch64 binaries
on a native aarch64 target, we must somehow be switching the current
native target object between these two, right?  But I can't figure out
where that's happening...

>
>> 
>> Maybe someone with more ARM/AArch64 knowledge will chip in to fill in
>> some of the blanks.
>
> When attempting to run a 32-bit binary in 64-bit state, I get...

Does this mean you're on an aarch64 machine, start GDB with an aarch32
(armv7?) binary, and then "run" to start the process?

>
> The target does not support architecture "armv7".

I'd be really interested to know if you only take the first 4 patches
from this series, can you still run armv7 binaries using an aarch64 GDB?
I'm wonderinging if the assert added in patch #4 will trigger.

Thanks,
Andrew

>
>> 
>> But to answer the general question, if there is a case that the existing
>> code doesn't handle, then we can for sure override the new method in
>> specific *-nat.c targets in order to handle weird cases.> 
>> Thanks,
>> Andrew
>> 


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH 5/5] gdb: native target invalid architecture detection
  2022-06-06 14:38         ` Andrew Burgess
@ 2022-06-06 17:48           ` Andrew Burgess
  2022-06-07 11:03             ` Luis Machado
  0 siblings, 1 reply; 83+ messages in thread
From: Andrew Burgess @ 2022-06-06 17:48 UTC (permalink / raw)
  To: Luis Machado, John Baldwin, gdb-patches

Andrew Burgess <aburgess@redhat.com> writes:

> Luis Machado via Gdb-patches <gdb-patches@sourceware.org> writes:
>
>> On 5/31/22 17:51, Andrew Burgess via Gdb-patches wrote:
>>> John Baldwin <jhb@FreeBSD.org> writes:
>>> 
>>>> On 5/31/22 7:30 AM, Andrew Burgess via Gdb-patches wrote:
>>>>> If GDB is asked to start a new inferior, or attach to an existing
>>>>> process, using a binary file for an architecture that does not match
>>>>> the current native target, then, currently, GDB will assert.  Here's
>>>>> an example session using current HEAD of master with GDB built for an
>>>>> x86-64 GNU/Linux native target, the binary being used is a RISC-V ELF:
>>>>>
>>>>>     $ ./gdb/gdb -q --data-directory ./gdb/data-directory/
>>>>>     (gdb) file /tmp/hello.rv32imc.x
>>>>>     Reading symbols from /tmp/hello.rv32imc.x...
>>>>>     (gdb) start
>>>>>     Temporary breakpoint 1 at 0x101b2: file hello.rv32.c, line 23.
>>>>>     Starting program: /tmp/hello.rv32imc.x
>>>>>     ../../src/gdb/gdbarch.h:166: internal-error: gdbarch_tdep: Assertion `dynamic_cast<TDepType *> (tdep) != nullptr' failed.
>>>>>     A problem internal to GDB has been detected,
>>>>>     further debugging may prove unreliable.
>>>>>
>>>>> The same error is encountered if, instead of starting a new inferior,
>>>>> the user tries to attach to an x86-64 process with a RISC-V binary set
>>>>> as the current executable.
>>>>>
>>>>> These errors are not specific to the x86-64/RISC-V pairing I'm using
>>>>> here, any attempt to use a binary for one architecture with a native
>>>>> target of a different architecture will result in a similar error.
>>>>>
>>>>> Clearly, attempting to use this cross-architecture combination is a
>>>>> user error, but I think GDB should do better than an assert; ideally a
>>>>> nice error should be printed.
>>>>>
>>>>> The problem we run into is that, when the user starts a new inferior,
>>>>> or attaches to an inferior, the inferior stops.  At this point GDB
>>>>> attempts to handle the stop, and this involves reading registers from
>>>>> the inferior.
>>>>>
>>>>> These register reads end up being done through the native target, so
>>>>> in the example above, we end up in the amd64_supply_fxsave function.
>>>>> However, these functions need a gdbarch.  The gdbarch is fetched from
>>>>> the register set, which was constructed using the gdbarch from the
>>>>> binary currently in use.  And so we end up in amd64_supply_fxsave
>>>>> using a RISC-V gdbarch.
>>>>>
>>>>> When we call:
>>>>>
>>>>>     i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>>>>>
>>>>> this will assert as the gdbarch_tdep data within the RISC-V gdbarch is
>>>>> of the type riscv_gdbarch_tdep not i386_gdbarch_tdep.
>>>>>
>>>>> The solution I propose in this commit is to add a new target_ops
>>>>> method supports_architecture_p.  This method will return true if a
>>>>> target can safely be used with a specific architecture, otherwise, the
>>>>> method returns false.
>>>>>
>>>>> I imagine that a result of true from this method doesn't guarantee
>>>>> that GDB can start an inferior of a given architecture, it just means
>>>>> that GDB will not crash if such an attempt is made.  A result of false
>>>>> is a hard stop; attempting to use this target with this architecture
>>>>> is not supported, and may cause GDB to crash.
>>>>>
>>>>> This distinction is important I think for things like remote targets,
>>>>> and possibly simulator targets.  We might imagine that GDB can ask a
>>>>> remote (or simulator) to start with a particular executable, and the
>>>>> target might still refuse for some reason.  But my thinking is that
>>>>> these refusals should be well handled (i.e. GDB should give a user
>>>>> friendly error), rather than crashing, as is the case with the native
>>>>> targets.
>>>>>
>>>>> For example, if I start gdbserver on an x86-64 machine like this:
>>>>>
>>>>>     gdbserver --multi :54321
>>>>>
>>>>> Then make use of this from a GDB session like this:
>>>>>
>>>>>     $ ./gdb/gdb -q --data-directory ./gdb/data-directory/
>>>>>     (gdb) file /tmp/hello.rv32imc.x
>>>>>     Reading symbols from /tmp/hello.rv32imc.x...
>>>>>     (gdb) target extended-remote :54321
>>>>>     Remote debugging using :54321
>>>>>     (gdb) run
>>>>>     Starting program: /tmp/hello.rv32imc.x
>>>>>     Running the default executable on the remote target failed; try "set remote exec-file"?
>>>>>     (gdb)
>>>>>
>>>>> Though the error is not very helpful in diagnosing the problem, we can
>>>>> see that GDB has not crashed, but has given the user an error.
>>>>>
>>>>> And so, the supports_architecture_p method is created to return true
>>>>> by default, then I override this in inf_child_target, where I compare
>>>>> the architecture in question with the default_bfd_arch.
>>>>>
>>>>> Finally, I've added calls to supports_architecture_p for the
>>>>> run (which covers run, start, starti) and attach commands.
>>>>>
>>>>> You will notice a lack of tests for this change.  I'm not sure of a
>>>>> good way that I can build a binary for a different architecture as
>>>>> part of a test, but if anyone has any ideas then I'll be happy to add
>>>>> a test here.
>>>>
>>>> Have you considered multi-arch cases such as running i386 binaries on an x86-64
>>>> host or 32-bit arm binaries on an AArch64 host?  Will we need to override this
>>>> method in certain targets (e.g. x86-linux-nat.c or x86-fbsd-nat.c) to support
>>>> such cases?
>>> 
>>> For the x86 examples you gave, I think these all have the bfd_arch_i386
>>> bfd architecture, so should work just fine.
>>> 
>>> But for the aarch64 case, I admit I don't know how this works.  A 32-bit
>>> ARM binary is going to have bfd_arch_arm, while the AArch64 target will
>>> be expecting a gdbarch with bfd_arch_aarch64.  But how GDB supports
>>> running the former on the latter, I don't know.
>>> 
>>> I notice there's aarch64-linux-nat.c and aarch32-linux-nat.c, I wonder
>>> if this has something to do with it...
>>
>> aarch32 is the 32-bit state of aarch64, but the BFD architecture is
>> different. So this won't work out-of-the-box.
>
> If I understand correctly a aarch64 binary will have bfd_arch_aarch64,
> and a aarch32 (armv7?) binary will be bfd_arch_arm.
>
> What I don't understand, is how this all hangs together when running on
> an aarch64 machine, using a native target.
>
> Unless I'm missing something (please let me know if I am) then there's
> just a single native linux target, the_aarch64_linux_nat_target, which
> is registered from _initialize_aarch64_linux_nat in
> aarch64-linux-nat.c.
>
> In aarch64_linux_nat_target::fetch_registers, we assume the gdbarch_tdep
> is of type aarch64_gdbarch_tdep, so this will only work for
> bfd_arch_aarch64 binaries.
>
> Then there's the_arm_linux_nat_target, from arm-linux-nat.c, which has
> arm_linux_nat_target::fetch_registers, which assumed gdbarch_tdep will
> be of type arm_gdbarch_tdep, so will only work for bfd_arch_arm targets.
>
> So, I guess, if we can debug bfd_arch_arm and bfd_arch_aarch64 binaries
> on a native aarch64 target, we must somehow be switching the current
> native target object between these two, right?  But I can't figure out
> where that's happening...
>
>>
>>> 
>>> Maybe someone with more ARM/AArch64 knowledge will chip in to fill in
>>> some of the blanks.
>>
>> When attempting to run a 32-bit binary in 64-bit state, I get...
>
> Does this mean you're on an aarch64 machine, start GDB with an aarch32
> (armv7?) binary, and then "run" to start the process?
>
>>
>> The target does not support architecture "armv7".
>
> I'd be really interested to know if you only take the first 4 patches
> from this series, can you still run armv7 binaries using an aarch64 GDB?
> I'm wonderinging if the assert added in patch #4 will trigger.

I managed to get a setup where I'm running on an aarch64 machine, and
using GDB to debug an ARMv7 binary.

I'm a little confused as to what's going on, so I'm hoping I can
describe what I'm seeing, and you can tell me if GDB is supposed to do
better than this or not.

First, I'm using a modified version of patch #4 of my series (i.e. I've
applied patches #1, #2, #3, and #4, but modified #4), in gdbarch.h I've
replaced the _function_ gdbarch_tdep with this:

  template<typename TDepType>
  static inline TDepType *
  gdbarch_tdep (struct gdbarch *gdbarch)
  {
    TDepType *tdep = dynamic_cast<TDepType *> (gdbarch_tdep_1 (gdbarch));
    if (tdep == nullptr)
      {
        fprintf (stderr, "XXX: Incorrect cast performed!\n");
        return static_cast<TDepType *> (gdbarch_tdep_1 (gdbarch));
      }
    return tdep;
  }

Here's my GDB session then, debugging a 32-bit ARMv7 binary;

  $ file /tmp/ubuntu-16.04-armhf/bin/true
  /tmp/ubuntu-16.04-armhf/bin/true: ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=c80229c22d4b6b30b71ab1b1b5a1de6b86b6aadf, stripped
  $ ./gdb/gdb -q --data-directory ./gdb/data-directory/ /tmp/ubuntu-16.04-armhf/bin/true
  Reading symbols from /tmp/ubuntu-16.04-armhf/bin/true...
  (No debugging symbols found in /tmp/ubuntu-16.04-armhf/bin/true)
  (gdb) show architecture 
  The target architecture is set to "auto" (currently "armv7").
  (gdb) starti
  Starting program: /tmp/ubuntu-16.04-armhf/bin/true 
  XXX: Incorrect cast performed!
  XXX: Incorrect cast performed!
  warning: Unable to determine the number of hardware watchpoints available.
  warning: Unable to determine the number of hardware breakpoints available.
  XXX: Incorrect cast performed!
  
  Program stopped.
  0x0000000000000006 in ?? ()
  (gdb) show architecture 
  The target architecture is set to "auto" (currently "aarch64").
  (gdb) pipe maintenance print xml-tdesc | head -n 20
  <?xml version="1.0"?>
  <!DOCTYPE target SYSTEM "gdb-target.dtd">
  <target>
    <architecture>arm</architecture>
    <feature name="org.gnu.gdb.arm.core">
      <reg name="r0" bitsize="32" type="uint32" regnum="0"/>
      <reg name="r1" bitsize="32" type="uint32" regnum="1"/>
      <reg name="r2" bitsize="32" type="uint32" regnum="2"/>
      <reg name="r3" bitsize="32" type="uint32" regnum="3"/>
      <reg name="r4" bitsize="32" type="uint32" regnum="4"/>
      <reg name="r5" bitsize="32" type="uint32" regnum="5"/>
      <reg name="r6" bitsize="32" type="uint32" regnum="6"/>
      <reg name="r7" bitsize="32" type="uint32" regnum="7"/>
      <reg name="r8" bitsize="32" type="uint32" regnum="8"/>
      <reg name="r9" bitsize="32" type="uint32" regnum="9"/>
      <reg name="r10" bitsize="32" type="uint32" regnum="10"/>
      <reg name="r11" bitsize="32" type="uint32" regnum="11"/>
      <reg name="r12" bitsize="32" type="uint32" regnum="12"/>
      <reg name="sp" bitsize="32" type="data_ptr" regnum="13"/>
      <reg name="lr" bitsize="32" type="int" regnum="14"/>
  (gdb) info registers 
  x0             0x0                 0
  x1             0x0                 0
  x2             0x0                 0
  x3             0x0                 0
  x4             0x0                 0
  x5             0x0                 0
  x6             0xfffef6a000000000  -291782898221056
  x7             0xf77d0b4100000000  -613321600451739648
  x8             0x30                48
  x9             0x8d03c8            9241544
  x10            0x23cad1e8          600494568
  x11            0x7fd7d9dce8        549082225896
  x12            0x7fd7d9dd00        549082225920
  x13            0x7fa10128d0        548162054352
  x14            0x23c3d8a0          600037536
  x15            0x0                 0
  x16            0xd32a70            13838960
  x17            0xd32aa0            13839008
  x18            0x0                 0
  x19            0x0                 0
  x20            0x0                 0
  x21            0x0                 0
  x22            0x0                 0
  x23            0x0                 0
  x24            0x7fd7d9dd50        549082226000
  x25            0x412694            4269716
  x26            0x7cdf14            8183572
  x27            0x23b60ca0          599133344
  x28            0x4105e0            4261344
  x29            0x0                 0
  x30            0x7fd7d9dd50        549082226000
  sp             0x23c3d8a0          0x23c3d8a0
  pc             0x6                 0x6
  cpsr           0x6                 [ EL=1 BTYPE=0 ]
  Unable to fetch vFP/SIMD registers.: Invalid argument.
  (gdb) 

There's a couple of weird things I notice here.  First, obviously we're
casting the tdep field incorrectly 3 times.  This happens because,
initially, the GDB inferior has a gdbarch selected based on the ELF, so
it will be an ARM gdbarch with an arm_gdbarch_tdep.  However, I believe
that the native target will be aarch64_linux_nat_target.

So, when we first stop, after the target is created, we will call
aarch64_linux_nat_target::fetch_registers as part of the stop process,
this will perform one of the invalid casts.  I haven't (yet) tracked
down the others.

The next weird thing is that, after starting, the architecture has
changed to aarch64.  I have no idea why this is the case (I haven't
looked yet).

My expectation was that after the first stop GDB would ask the native
target for a target description, we'd get an ARMv7 target description,
and we'd then use that description to update the gdbarch.  It appears I
was partially correct, as you can see that the xml-tdesc is for ARM,
however, the current architect still switches to aarch64, and I have no
idea why that is.

Finally, in the 'info registes' we appear to be displaying aarch64
register names, rather than the ARMv7 names from the xml-tdesc, which
seems weird (again, I haven't looked yet), and then, at the end of the
'info registers' output we appear to try and fetch some registers that
the target doens't support.

If I try the same experiment using an aarch64 test binary then the
architecture starts as aarch64 and remains so after the 'starti' (as
you'd expect, and the 'info registers' output still displays the aarch64
names (as you'd expect), but the warning about 'Unable to fetch vfP/SIMD
registers' is no longer present - so that issue is something specific
relating to running the ARMv7 binary.

I think there's a lot here for me to look into, but I'm hoping you might
be able to let me know if me experiences above are the "expected"
behaviour, or if I'm not configured/built GDB correctly, or maybe I'm
just not using GDB correctly in this ARMv7/ARMv8 situation.

Thanks,
Andrew


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH 5/5] gdb: native target invalid architecture detection
  2022-06-06 17:48           ` Andrew Burgess
@ 2022-06-07 11:03             ` Luis Machado
  2022-06-07 18:42               ` Pedro Alves
  0 siblings, 1 reply; 83+ messages in thread
From: Luis Machado @ 2022-06-07 11:03 UTC (permalink / raw)
  To: Andrew Burgess, John Baldwin, gdb-patches

On 6/6/22 18:48, Andrew Burgess wrote:
> Andrew Burgess <aburgess@redhat.com> writes:
> 
>> Luis Machado via Gdb-patches <gdb-patches@sourceware.org> writes:
>>
>>> On 5/31/22 17:51, Andrew Burgess via Gdb-patches wrote:
>>>> John Baldwin <jhb@FreeBSD.org> writes:
>>>>
>>>>> On 5/31/22 7:30 AM, Andrew Burgess via Gdb-patches wrote:
>>>>>> If GDB is asked to start a new inferior, or attach to an existing
>>>>>> process, using a binary file for an architecture that does not match
>>>>>> the current native target, then, currently, GDB will assert.  Here's
>>>>>> an example session using current HEAD of master with GDB built for an
>>>>>> x86-64 GNU/Linux native target, the binary being used is a RISC-V ELF:
>>>>>>
>>>>>>      $ ./gdb/gdb -q --data-directory ./gdb/data-directory/
>>>>>>      (gdb) file /tmp/hello.rv32imc.x
>>>>>>      Reading symbols from /tmp/hello.rv32imc.x...
>>>>>>      (gdb) start
>>>>>>      Temporary breakpoint 1 at 0x101b2: file hello.rv32.c, line 23.
>>>>>>      Starting program: /tmp/hello.rv32imc.x
>>>>>>      ../../src/gdb/gdbarch.h:166: internal-error: gdbarch_tdep: Assertion `dynamic_cast<TDepType *> (tdep) != nullptr' failed.
>>>>>>      A problem internal to GDB has been detected,
>>>>>>      further debugging may prove unreliable.
>>>>>>
>>>>>> The same error is encountered if, instead of starting a new inferior,
>>>>>> the user tries to attach to an x86-64 process with a RISC-V binary set
>>>>>> as the current executable.
>>>>>>
>>>>>> These errors are not specific to the x86-64/RISC-V pairing I'm using
>>>>>> here, any attempt to use a binary for one architecture with a native
>>>>>> target of a different architecture will result in a similar error.
>>>>>>
>>>>>> Clearly, attempting to use this cross-architecture combination is a
>>>>>> user error, but I think GDB should do better than an assert; ideally a
>>>>>> nice error should be printed.
>>>>>>
>>>>>> The problem we run into is that, when the user starts a new inferior,
>>>>>> or attaches to an inferior, the inferior stops.  At this point GDB
>>>>>> attempts to handle the stop, and this involves reading registers from
>>>>>> the inferior.
>>>>>>
>>>>>> These register reads end up being done through the native target, so
>>>>>> in the example above, we end up in the amd64_supply_fxsave function.
>>>>>> However, these functions need a gdbarch.  The gdbarch is fetched from
>>>>>> the register set, which was constructed using the gdbarch from the
>>>>>> binary currently in use.  And so we end up in amd64_supply_fxsave
>>>>>> using a RISC-V gdbarch.
>>>>>>
>>>>>> When we call:
>>>>>>
>>>>>>      i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>>>>>>
>>>>>> this will assert as the gdbarch_tdep data within the RISC-V gdbarch is
>>>>>> of the type riscv_gdbarch_tdep not i386_gdbarch_tdep.
>>>>>>
>>>>>> The solution I propose in this commit is to add a new target_ops
>>>>>> method supports_architecture_p.  This method will return true if a
>>>>>> target can safely be used with a specific architecture, otherwise, the
>>>>>> method returns false.
>>>>>>
>>>>>> I imagine that a result of true from this method doesn't guarantee
>>>>>> that GDB can start an inferior of a given architecture, it just means
>>>>>> that GDB will not crash if such an attempt is made.  A result of false
>>>>>> is a hard stop; attempting to use this target with this architecture
>>>>>> is not supported, and may cause GDB to crash.
>>>>>>
>>>>>> This distinction is important I think for things like remote targets,
>>>>>> and possibly simulator targets.  We might imagine that GDB can ask a
>>>>>> remote (or simulator) to start with a particular executable, and the
>>>>>> target might still refuse for some reason.  But my thinking is that
>>>>>> these refusals should be well handled (i.e. GDB should give a user
>>>>>> friendly error), rather than crashing, as is the case with the native
>>>>>> targets.
>>>>>>
>>>>>> For example, if I start gdbserver on an x86-64 machine like this:
>>>>>>
>>>>>>      gdbserver --multi :54321
>>>>>>
>>>>>> Then make use of this from a GDB session like this:
>>>>>>
>>>>>>      $ ./gdb/gdb -q --data-directory ./gdb/data-directory/
>>>>>>      (gdb) file /tmp/hello.rv32imc.x
>>>>>>      Reading symbols from /tmp/hello.rv32imc.x...
>>>>>>      (gdb) target extended-remote :54321
>>>>>>      Remote debugging using :54321
>>>>>>      (gdb) run
>>>>>>      Starting program: /tmp/hello.rv32imc.x
>>>>>>      Running the default executable on the remote target failed; try "set remote exec-file"?
>>>>>>      (gdb)
>>>>>>
>>>>>> Though the error is not very helpful in diagnosing the problem, we can
>>>>>> see that GDB has not crashed, but has given the user an error.
>>>>>>
>>>>>> And so, the supports_architecture_p method is created to return true
>>>>>> by default, then I override this in inf_child_target, where I compare
>>>>>> the architecture in question with the default_bfd_arch.
>>>>>>
>>>>>> Finally, I've added calls to supports_architecture_p for the
>>>>>> run (which covers run, start, starti) and attach commands.
>>>>>>
>>>>>> You will notice a lack of tests for this change.  I'm not sure of a
>>>>>> good way that I can build a binary for a different architecture as
>>>>>> part of a test, but if anyone has any ideas then I'll be happy to add
>>>>>> a test here.
>>>>>
>>>>> Have you considered multi-arch cases such as running i386 binaries on an x86-64
>>>>> host or 32-bit arm binaries on an AArch64 host?  Will we need to override this
>>>>> method in certain targets (e.g. x86-linux-nat.c or x86-fbsd-nat.c) to support
>>>>> such cases?
>>>>
>>>> For the x86 examples you gave, I think these all have the bfd_arch_i386
>>>> bfd architecture, so should work just fine.
>>>>
>>>> But for the aarch64 case, I admit I don't know how this works.  A 32-bit
>>>> ARM binary is going to have bfd_arch_arm, while the AArch64 target will
>>>> be expecting a gdbarch with bfd_arch_aarch64.  But how GDB supports
>>>> running the former on the latter, I don't know.
>>>>
>>>> I notice there's aarch64-linux-nat.c and aarch32-linux-nat.c, I wonder
>>>> if this has something to do with it...
>>>
>>> aarch32 is the 32-bit state of aarch64, but the BFD architecture is
>>> different. So this won't work out-of-the-box.
>>
>> If I understand correctly a aarch64 binary will have bfd_arch_aarch64,
>> and a aarch32 (armv7?) binary will be bfd_arch_arm.
>>
>> What I don't understand, is how this all hangs together when running on
>> an aarch64 machine, using a native target.
>>
>> Unless I'm missing something (please let me know if I am) then there's
>> just a single native linux target, the_aarch64_linux_nat_target, which
>> is registered from _initialize_aarch64_linux_nat in
>> aarch64-linux-nat.c.
>>
>> In aarch64_linux_nat_target::fetch_registers, we assume the gdbarch_tdep
>> is of type aarch64_gdbarch_tdep, so this will only work for
>> bfd_arch_aarch64 binaries.
>>
>> Then there's the_arm_linux_nat_target, from arm-linux-nat.c, which has
>> arm_linux_nat_target::fetch_registers, which assumed gdbarch_tdep will
>> be of type arm_gdbarch_tdep, so will only work for bfd_arch_arm targets.
>>
>> So, I guess, if we can debug bfd_arch_arm and bfd_arch_aarch64 binaries
>> on a native aarch64 target, we must somehow be switching the current
>> native target object between these two, right?  But I can't figure out
>> where that's happening...
>>
>>>
>>>>
>>>> Maybe someone with more ARM/AArch64 knowledge will chip in to fill in
>>>> some of the blanks.
>>>
>>> When attempting to run a 32-bit binary in 64-bit state, I get...
>>
>> Does this mean you're on an aarch64 machine, start GDB with an aarch32
>> (armv7?) binary, and then "run" to start the process?
>>
>>>
>>> The target does not support architecture "armv7".
>>
>> I'd be really interested to know if you only take the first 4 patches
>> from this series, can you still run armv7 binaries using an aarch64 GDB?
>> I'm wonderinging if the assert added in patch #4 will trigger.
> 
> I managed to get a setup where I'm running on an aarch64 machine, and
> using GDB to debug an ARMv7 binary.
> 
> I'm a little confused as to what's going on, so I'm hoping I can
> describe what I'm seeing, and you can tell me if GDB is supposed to do
> better than this or not.
> 
> First, I'm using a modified version of patch #4 of my series (i.e. I've
> applied patches #1, #2, #3, and #4, but modified #4), in gdbarch.h I've
> replaced the _function_ gdbarch_tdep with this:
> 
>    template<typename TDepType>
>    static inline TDepType *
>    gdbarch_tdep (struct gdbarch *gdbarch)
>    {
>      TDepType *tdep = dynamic_cast<TDepType *> (gdbarch_tdep_1 (gdbarch));
>      if (tdep == nullptr)
>        {
>          fprintf (stderr, "XXX: Incorrect cast performed!\n");
>          return static_cast<TDepType *> (gdbarch_tdep_1 (gdbarch));
>        }
>      return tdep;
>    }
> 
> Here's my GDB session then, debugging a 32-bit ARMv7 binary;
> 
>    $ file /tmp/ubuntu-16.04-armhf/bin/true
>    /tmp/ubuntu-16.04-armhf/bin/true: ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=c80229c22d4b6b30b71ab1b1b5a1de6b86b6aadf, stripped
>    $ ./gdb/gdb -q --data-directory ./gdb/data-directory/ /tmp/ubuntu-16.04-armhf/bin/true
>    Reading symbols from /tmp/ubuntu-16.04-armhf/bin/true...
>    (No debugging symbols found in /tmp/ubuntu-16.04-armhf/bin/true)
>    (gdb) show architecture
>    The target architecture is set to "auto" (currently "armv7").
>    (gdb) starti
>    Starting program: /tmp/ubuntu-16.04-armhf/bin/true
>    XXX: Incorrect cast performed!
>    XXX: Incorrect cast performed!
>    warning: Unable to determine the number of hardware watchpoints available.
>    warning: Unable to determine the number of hardware breakpoints available.
>    XXX: Incorrect cast performed!
>    
>    Program stopped.
>    0x0000000000000006 in ?? ()
>    (gdb) show architecture
>    The target architecture is set to "auto" (currently "aarch64").
>    (gdb) pipe maintenance print xml-tdesc | head -n 20
>    <?xml version="1.0"?>
>    <!DOCTYPE target SYSTEM "gdb-target.dtd">
>    <target>
>      <architecture>arm</architecture>
>      <feature name="org.gnu.gdb.arm.core">
>        <reg name="r0" bitsize="32" type="uint32" regnum="0"/>
>        <reg name="r1" bitsize="32" type="uint32" regnum="1"/>
>        <reg name="r2" bitsize="32" type="uint32" regnum="2"/>
>        <reg name="r3" bitsize="32" type="uint32" regnum="3"/>
>        <reg name="r4" bitsize="32" type="uint32" regnum="4"/>
>        <reg name="r5" bitsize="32" type="uint32" regnum="5"/>
>        <reg name="r6" bitsize="32" type="uint32" regnum="6"/>
>        <reg name="r7" bitsize="32" type="uint32" regnum="7"/>
>        <reg name="r8" bitsize="32" type="uint32" regnum="8"/>
>        <reg name="r9" bitsize="32" type="uint32" regnum="9"/>
>        <reg name="r10" bitsize="32" type="uint32" regnum="10"/>
>        <reg name="r11" bitsize="32" type="uint32" regnum="11"/>
>        <reg name="r12" bitsize="32" type="uint32" regnum="12"/>
>        <reg name="sp" bitsize="32" type="data_ptr" regnum="13"/>
>        <reg name="lr" bitsize="32" type="int" regnum="14"/>
>    (gdb) info registers
>    x0             0x0                 0
>    x1             0x0                 0
>    x2             0x0                 0
>    x3             0x0                 0
>    x4             0x0                 0
>    x5             0x0                 0
>    x6             0xfffef6a000000000  -291782898221056
>    x7             0xf77d0b4100000000  -613321600451739648
>    x8             0x30                48
>    x9             0x8d03c8            9241544
>    x10            0x23cad1e8          600494568
>    x11            0x7fd7d9dce8        549082225896
>    x12            0x7fd7d9dd00        549082225920
>    x13            0x7fa10128d0        548162054352
>    x14            0x23c3d8a0          600037536
>    x15            0x0                 0
>    x16            0xd32a70            13838960
>    x17            0xd32aa0            13839008
>    x18            0x0                 0
>    x19            0x0                 0
>    x20            0x0                 0
>    x21            0x0                 0
>    x22            0x0                 0
>    x23            0x0                 0
>    x24            0x7fd7d9dd50        549082226000
>    x25            0x412694            4269716
>    x26            0x7cdf14            8183572
>    x27            0x23b60ca0          599133344
>    x28            0x4105e0            4261344
>    x29            0x0                 0
>    x30            0x7fd7d9dd50        549082226000
>    sp             0x23c3d8a0          0x23c3d8a0
>    pc             0x6                 0x6
>    cpsr           0x6                 [ EL=1 BTYPE=0 ]
>    Unable to fetch vFP/SIMD registers.: Invalid argument.
>    (gdb)
> 
> There's a couple of weird things I notice here.  First, obviously we're
> casting the tdep field incorrectly 3 times.  This happens because,
> initially, the GDB inferior has a gdbarch selected based on the ELF, so
> it will be an ARM gdbarch with an arm_gdbarch_tdep.  However, I believe
> that the native target will be aarch64_linux_nat_target.

That's correct so far. Yes, the BFD will be arm and the native target will be aarch64-linux.

> 
> So, when we first stop, after the target is created, we will call
> aarch64_linux_nat_target::fetch_registers as part of the stop process,
> this will perform one of the invalid casts.  I haven't (yet) tracked
> down the others.

See below.

> 
> The next weird thing is that, after starting, the architecture has
> changed to aarch64.  I have no idea why this is the case (I haven't
> looked yet).

I think this used to work, but eventually it got broken (rotted away) and now it
doesn't work properly it seems.

My guess is that the introduction of SVE support also changed how we look up
the target description. In this particular case, I think we're calling the
aarch64_linux_nat_target::thread_architecture function, and that particular
function completely ignores the existence of aarch32, so GDB ends up
thinking we have an aarch64 target again.

> 
> My expectation was that after the first stop GDB would ask the native
> target for a target description, we'd get an ARMv7 target description,
> and we'd then use that description to update the gdbarch.  It appears I
> was partially correct, as you can see that the xml-tdesc is for ARM,
> however, the current architect still switches to aarch64, and I have no
> idea why that is.

I think the XML is generated from the BFD information, right? So that's
why it is correct.

> 
> Finally, in the 'info registes' we appear to be displaying aarch64
> register names, rather than the ARMv7 names from the xml-tdesc, which
> seems weird (again, I haven't looked yet), and then, at the end of the
> 'info registers' output we appear to try and fetch some registers that
> the target doens't support.

They're aarch64 registers because the aarch64_linux_nat_target::thread_architecture
function told GDB we have an aarch64 target description. That's incorrect.

The other errors are just consequence of incorrect identification of the
architecture.

> 
> If I try the same experiment using an aarch64 test binary then the
> architecture starts as aarch64 and remains so after the 'starti' (as
> you'd expect, and the 'info registers' output still displays the aarch64
> names (as you'd expect), but the warning about 'Unable to fetch vfP/SIMD
> registers' is no longer present - so that issue is something specific
> relating to running the ARMv7 binary.
> 
> I think there's a lot here for me to look into, but I'm hoping you might
> be able to let me know if me experiences above are the "expected"
> behaviour, or if I'm not configured/built GDB correctly, or maybe I'm
> just not using GDB correctly in this ARMv7/ARMv8 situation.

Yeah, sorry for the poor experience. I can confirm your procedure is
correct, and that you built GDB correctly. Unfortunately this part of
the AArch64 port seems to have rotted away given it is a less common
execution scenario.

The most exercised cases are to use a 64-bit GDB (aarch64) to debug 64-bit
binaries and a 32-bit GDB (arm/armhf) to debug 32-bit binaries. The aarch32
code path is what you're exercising here, using a 64-bit GDB to debug a 32-bit
binary.

I'm not sure if there are other ports out there that can handle multiple different
bfd's natively, but I don't want to block your series.

We can address this through a target hook that tells the upper layers we support
X and Y bfd's I suppose.

Hopefully this clarifies things a bit. Let me know if there's any other information
you need.

> 
> Thanks,
> Andrew
> 


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH 5/5] gdb: native target invalid architecture detection
  2022-06-07 11:03             ` Luis Machado
@ 2022-06-07 18:42               ` Pedro Alves
  2022-06-07 20:15                 ` Pedro Alves
  2022-06-08  7:54                 ` Luis Machado
  0 siblings, 2 replies; 83+ messages in thread
From: Pedro Alves @ 2022-06-07 18:42 UTC (permalink / raw)
  To: Luis Machado, Andrew Burgess, John Baldwin, gdb-patches

On 2022-06-07 12:03, Luis Machado via Gdb-patches wrote:

> Yeah, sorry for the poor experience. I can confirm your procedure is
> correct, and that you built GDB correctly. Unfortunately this part of
> the AArch64 port seems to have rotted away given it is a less common
> execution scenario.

This is actually covered by the testsuite, since:

~~~~~
commit 71be1fdc3655a170f4b14d795e5c9e81fcea06ef
Author:     Yao Qi <yao.qi@linaro.org>
AuthorDate: Tue Jul 7 16:58:19 2015 +0100
Commit:     Yao Qi <yao.qi@linaro.org>
CommitDate: Tue Jul 7 16:58:19 2015 +0100

    Adjust gdb.multi tests for aarch64
    
    Multi-arch related tests under gdb.multi are to compile programs with
    the same compiler but different compiler options (-m64 vs -m32).  However,
    different compilers are needed to compile both aarch64 program and
    arm (aarch32) program.  This patch is to adjust these test cases to
    compile programs in different modes with different compiler.
    
    When we use gcc for arm-linux target, its file name can be different,
    arm-linux-gnueabihf-gcc, arm-linux-gnueabi-gcc, or arm-none-linux-gnueabi-gcc,
    so I add a variable ARM_CC_FOR_TARGET, so that user can set the name
    of gcc for arm-linux target on aarch64, like:
    
     $ make check RUNTESTFLAGS='ARM_CC_FOR_TARGET=arm-linux-gnueabihf-gcc multi-arch.exp'
    
    gdb/testsuite:
    
    2015-07-07  Yao Qi  <yao.qi@linaro.org>
    
            * gdb.multi/multi-arch-exec.exp: Set march1 and march2 to "" if target
            is aarch64.  If target is aarch64, set compiler=${ARM_CC_FOR_TARGET}
            if it exists.
            * gdb.multi/multi-arch.exp: Likewise.

~~~~~

I guess the issue is that nobody ever remembers to set ARM_CC_FOR_TARGET, or even
knows about it.

IWBN if the aarch64 bots people have access to tested with ARM_CC_FOR_TARGET, if they
aren't already.

Maybe it would be possible to come up with a way to default ARM_CC_FOR_TARGET to
something that works for most people when testing aarch64, somehow.

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH 5/5] gdb: native target invalid architecture detection
  2022-06-07 18:42               ` Pedro Alves
@ 2022-06-07 20:15                 ` Pedro Alves
  2022-06-08  8:18                   ` Luis Machado
  2022-06-08  7:54                 ` Luis Machado
  1 sibling, 1 reply; 83+ messages in thread
From: Pedro Alves @ 2022-06-07 20:15 UTC (permalink / raw)
  To: Luis Machado, Andrew Burgess, John Baldwin, gdb-patches

On 2022-06-07 19:42, Pedro Alves wrote:

>     When we use gcc for arm-linux target, its file name can be different,
>     arm-linux-gnueabihf-gcc, arm-linux-gnueabi-gcc, or arm-none-linux-gnueabi-gcc,
>     so I add a variable ARM_CC_FOR_TARGET, so that user can set the name
>     of gcc for arm-linux target on aarch64, like:

...

> Maybe it would be possible to come up with a way to default ARM_CC_FOR_TARGET to
> something that works for most people when testing aarch64, somehow.

Maybe something like this?  Completely untested, other than hacking it such that
the aarch64 linux path is taken on my x86-64 box, to ensure the tcl at least parses
as expected.

I left arm-linux-gnueabihf-gcc last on the theory that binaries produced by
arm-linux-gnueabi-gcc and arm-none-linux-gnueabi-gcc would run everywhere, but
arm-linux-gnueabihf-gcc might now.  I am not really sure about that, I may be
making that up.

gdb.multi/multi-arch-exec.exp also uses ARM_CC_FOR_TARGET.  If something like
this works, then we could do the same to that testcase.  Even better if we
manage to factor this out to a shared procedure used by both testcases.

From 56cdd32a54b236d35c433809fcb015f20487dc4b Mon Sep 17 00:00:00 2001
From: Pedro Alves <pedro@palves.net>
Date: Tue, 7 Jun 2022 20:11:32 +0100
Subject: [PATCH] aarch64: gdb.multi/multi-arch.exp: Add fallback if
 ARM_CC_FOR_TARGET not set

On Aarch64, you can set ARM_CC_FOR_TARGET to the 32-bit compiler to
use when testing gdb.multi/multi-arch.exp.  If you set it, then the
testcase doesn't run.

I guess that approximately nobody remembers to set ARM_CC_FOR_TARGET.

This commit adds a fallback.  If ARM_CC_FOR_TARGET is not set, and
testing for Linux, try arm-linux-gnueabi-gcc,
arm-none-linux-gnueabi-gcc, arm-linux-gnueabihf-gcc.

Change-Id: Iefe5865d5fc84b4032eaff7f4c5c61582bf75c39
---
 gdb/testsuite/gdb.multi/multi-arch.exp | 39 ++++++++++++++++++++++----
 1 file changed, 34 insertions(+), 5 deletions(-)

diff --git a/gdb/testsuite/gdb.multi/multi-arch.exp b/gdb/testsuite/gdb.multi/multi-arch.exp
index e5c2d9cc161..a9d442d89ad 100644
--- a/gdb/testsuite/gdb.multi/multi-arch.exp
+++ b/gdb/testsuite/gdb.multi/multi-arch.exp
@@ -61,18 +61,47 @@ set options [list debug]
 
 if [istarget "aarch64*-*-*"] {
     if {[info exists ARM_CC_FOR_TARGET]} {
-	lappend options "compiler=${ARM_CC_FOR_TARGET}"
+	set compilers [list ${ARM_CC_FOR_TARGET}]
+    } elseif [istarget "*-linux*-*"] {
+	# Try a few common compiler names.
+	set compilers {
+	    arm-linux-gnueabi-gcc
+	    arm-none-linux-gnueabi-gcc
+	    arm-linux-gnueabihf-gcc
+	}
     } else {
+	set compilers {}
+    }
+
+    set ok 0
+    foreach compiler $compilers {
+	set arm_options $options
+	lappend arm_options "compiler=$compiler"
+
+	if {![is_remote host] && [which $compiler] == 0} {
+	    # Avoid "default_target_compile: Can't find
+	    # $compiler." warning issued from gdb_compile.
+	    continue
+	}
+
+	if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" ${exec2} \
+		  executable $arm_options] == "" } {
+	    set ok 1
+	    break
+	}
+    }
+
+    if {!$ok} {
 	unsupported "ARM compiler is not known"
 	return -1
     }
 } else {
     lappend options "additional_flags=${march2}"
-}
 
-if { [build_executable "failed to prepare" ${exec2} "${srcfile2}" \
-	 $options]} {
-    return -1
+    if { [build_executable "failed to prepare" ${exec2} "${srcfile2}" \
+	      $options]} {
+	return -1
+    }
 }
 
 # Start inferior 1

base-commit: 0c8cd1de90b97f12b27b40c2922a03a68932eea1
-- 
2.36.0


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH 5/5] gdb: native target invalid architecture detection
  2022-06-07 18:42               ` Pedro Alves
  2022-06-07 20:15                 ` Pedro Alves
@ 2022-06-08  7:54                 ` Luis Machado
  2022-06-08 10:12                   ` Pedro Alves
  1 sibling, 1 reply; 83+ messages in thread
From: Luis Machado @ 2022-06-08  7:54 UTC (permalink / raw)
  To: Pedro Alves, Andrew Burgess, John Baldwin, gdb-patches

On 6/7/22 19:42, Pedro Alves wrote:
> On 2022-06-07 12:03, Luis Machado via Gdb-patches wrote:
> 
>> Yeah, sorry for the poor experience. I can confirm your procedure is
>> correct, and that you built GDB correctly. Unfortunately this part of
>> the AArch64 port seems to have rotted away given it is a less common
>> execution scenario.
> 
> This is actually covered by the testsuite, since:
> 
> ~~~~~
> commit 71be1fdc3655a170f4b14d795e5c9e81fcea06ef
> Author:     Yao Qi <yao.qi@linaro.org>
> AuthorDate: Tue Jul 7 16:58:19 2015 +0100
> Commit:     Yao Qi <yao.qi@linaro.org>
> CommitDate: Tue Jul 7 16:58:19 2015 +0100
> 
>      Adjust gdb.multi tests for aarch64
>      
>      Multi-arch related tests under gdb.multi are to compile programs with
>      the same compiler but different compiler options (-m64 vs -m32).  However,
>      different compilers are needed to compile both aarch64 program and
>      arm (aarch32) program.  This patch is to adjust these test cases to
>      compile programs in different modes with different compiler.
>      
>      When we use gcc for arm-linux target, its file name can be different,
>      arm-linux-gnueabihf-gcc, arm-linux-gnueabi-gcc, or arm-none-linux-gnueabi-gcc,
>      so I add a variable ARM_CC_FOR_TARGET, so that user can set the name
>      of gcc for arm-linux target on aarch64, like:
>      
>       $ make check RUNTESTFLAGS='ARM_CC_FOR_TARGET=arm-linux-gnueabihf-gcc multi-arch.exp'
>      
>      gdb/testsuite:
>      
>      2015-07-07  Yao Qi  <yao.qi@linaro.org>
>      
>              * gdb.multi/multi-arch-exec.exp: Set march1 and march2 to "" if target
>              is aarch64.  If target is aarch64, set compiler=${ARM_CC_FOR_TARGET}
>              if it exists.
>              * gdb.multi/multi-arch.exp: Likewise.
> 
> ~~~~~
> 
> I guess the issue is that nobody ever remembers to set ARM_CC_FOR_TARGET, or even
> knows about it.

Yeah. As a general comment, I always have to stop and think about the list of things that need
to be installed in order for GDB's testsuite to run all/most of the tests.

If you're missing something, most of the time things show up as UNTESTED/UNSUPPORTED. It
would be nice to have a stable list of things we need to have complete (as much as possible)
testsuite coverage.

Having to set these options by hand is quite obscure as well.

> 
> IWBN if the aarch64 bots people have access to tested with ARM_CC_FOR_TARGET, if they
> aren't already.

I think it is a less common scenario. Yes, this is supported, but my feeling is that people
seldom use this. Which explains why nobody complained, and some are surprised this even works.

> 
> Maybe it would be possible to come up with a way to default ARM_CC_FOR_TARGET to
> something that works for most people when testing aarch64, somehow.
The problem is that a compiler is not enough to make things run fine. If you have an aarch64
Ubuntu, for example, you'd need to add armhf as an architecture option and install both the
compiler and the libraries (libc6:armhf mostly).

Another problem is that not every processor/kernel supports running a 32-bit process in a
64-bit environment. This makes things more complicated.

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH 5/5] gdb: native target invalid architecture detection
  2022-06-07 20:15                 ` Pedro Alves
@ 2022-06-08  8:18                   ` Luis Machado
  2022-06-08 10:17                     ` Pedro Alves
  0 siblings, 1 reply; 83+ messages in thread
From: Luis Machado @ 2022-06-08  8:18 UTC (permalink / raw)
  To: Pedro Alves, Andrew Burgess, John Baldwin, gdb-patches

On 6/7/22 21:15, Pedro Alves wrote:
> On 2022-06-07 19:42, Pedro Alves wrote:
> 
>>      When we use gcc for arm-linux target, its file name can be different,
>>      arm-linux-gnueabihf-gcc, arm-linux-gnueabi-gcc, or arm-none-linux-gnueabi-gcc,
>>      so I add a variable ARM_CC_FOR_TARGET, so that user can set the name
>>      of gcc for arm-linux target on aarch64, like:
> 
> ...
> 
>> Maybe it would be possible to come up with a way to default ARM_CC_FOR_TARGET to
>> something that works for most people when testing aarch64, somehow.
> 
> Maybe something like this?  Completely untested, other than hacking it such that
> the aarch64 linux path is taken on my x86-64 box, to ensure the tcl at least parses
> as expected.
> 

Thanks for the patch. I think it is fine to have some of these tests run conditionally
based on the presence of an environment variable. What we're really missing is proper
documentation of ARM_CC_FOR_TARGET, explaining what it does, when it should be enabled
and under what conditions.

I wonder if putting that on the GDB manual, under a testing section, would work. The Wiki
has an entry for testing, but I find it a bit chaotic. What do you say?

> I left arm-linux-gnueabihf-gcc last on the theory that binaries produced by
> arm-linux-gnueabi-gcc and arm-none-linux-gnueabi-gcc would run everywhere, but
> arm-linux-gnueabihf-gcc might now.  I am not really sure about that, I may be
> making that up.
> 
> gdb.multi/multi-arch-exec.exp also uses ARM_CC_FOR_TARGET.  If something like
> this works, then we could do the same to that testcase.  Even better if we
> manage to factor this out to a shared procedure used by both testcases.
> 
>  From 56cdd32a54b236d35c433809fcb015f20487dc4b Mon Sep 17 00:00:00 2001
> From: Pedro Alves <pedro@palves.net>
> Date: Tue, 7 Jun 2022 20:11:32 +0100
> Subject: [PATCH] aarch64: gdb.multi/multi-arch.exp: Add fallback if
>   ARM_CC_FOR_TARGET not set
> 
> On Aarch64, you can set ARM_CC_FOR_TARGET to the 32-bit compiler to
> use when testing gdb.multi/multi-arch.exp.  If you set it, then the
> testcase doesn't run.
> 
> I guess that approximately nobody remembers to set ARM_CC_FOR_TARGET.
> 
> This commit adds a fallback.  If ARM_CC_FOR_TARGET is not set, and
> testing for Linux, try arm-linux-gnueabi-gcc,
> arm-none-linux-gnueabi-gcc, arm-linux-gnueabihf-gcc.
> 
> Change-Id: Iefe5865d5fc84b4032eaff7f4c5c61582bf75c39
> ---
>   gdb/testsuite/gdb.multi/multi-arch.exp | 39 ++++++++++++++++++++++----
>   1 file changed, 34 insertions(+), 5 deletions(-)
> 
> diff --git a/gdb/testsuite/gdb.multi/multi-arch.exp b/gdb/testsuite/gdb.multi/multi-arch.exp
> index e5c2d9cc161..a9d442d89ad 100644
> --- a/gdb/testsuite/gdb.multi/multi-arch.exp
> +++ b/gdb/testsuite/gdb.multi/multi-arch.exp
> @@ -61,18 +61,47 @@ set options [list debug]
>   
>   if [istarget "aarch64*-*-*"] {
>       if {[info exists ARM_CC_FOR_TARGET]} {
> -	lappend options "compiler=${ARM_CC_FOR_TARGET}"
> +	set compilers [list ${ARM_CC_FOR_TARGET}]
> +    } elseif [istarget "*-linux*-*"] {
> +	# Try a few common compiler names.
> +	set compilers {
> +	    arm-linux-gnueabi-gcc
> +	    arm-none-linux-gnueabi-gcc
> +	    arm-linux-gnueabihf-gcc
> +	}
>       } else {
> +	set compilers {}
> +    }
> +
> +    set ok 0
> +    foreach compiler $compilers {
> +	set arm_options $options
> +	lappend arm_options "compiler=$compiler"
> +
> +	if {![is_remote host] && [which $compiler] == 0} {
> +	    # Avoid "default_target_compile: Can't find
> +	    # $compiler." warning issued from gdb_compile.
> +	    continue
> +	}
> +
> +	if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" ${exec2} \
> +		  executable $arm_options] == "" } {
> +	    set ok 1
> +	    break
> +	}
> +    }
> +
> +    if {!$ok} {
>   	unsupported "ARM compiler is not known"
>   	return -1
>       }
>   } else {
>       lappend options "additional_flags=${march2}"
> -}
>   
> -if { [build_executable "failed to prepare" ${exec2} "${srcfile2}" \
> -	 $options]} {
> -    return -1
> +    if { [build_executable "failed to prepare" ${exec2} "${srcfile2}" \
> +	      $options]} {
> +	return -1
> +    }
>   }
>   
>   # Start inferior 1
> 
> base-commit: 0c8cd1de90b97f12b27b40c2922a03a68932eea1


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH 5/5] gdb: native target invalid architecture detection
  2022-06-08  7:54                 ` Luis Machado
@ 2022-06-08 10:12                   ` Pedro Alves
  2022-06-08 11:20                     ` [PATCH v2] aarch64: Add fallback if ARM_CC_FOR_TARGET not set (was: Re: [PATCH 5/5] gdb: native target invalid architecture detection) Pedro Alves
  0 siblings, 1 reply; 83+ messages in thread
From: Pedro Alves @ 2022-06-08 10:12 UTC (permalink / raw)
  To: Luis Machado, Andrew Burgess, John Baldwin, gdb-patches

On 2022-06-08 08:54, Luis Machado wrote:
> On 6/7/22 19:42, Pedro Alves wrote:
>> On 2022-06-07 12:03, Luis Machado via Gdb-patches wrote:
>>
>>> Yeah, sorry for the poor experience. I can confirm your procedure is
>>> correct, and that you built GDB correctly. Unfortunately this part of
>>> the AArch64 port seems to have rotted away given it is a less common
>>> execution scenario.
>>
>> This is actually covered by the testsuite, since:
>>
>> ~~~~~
>> commit 71be1fdc3655a170f4b14d795e5c9e81fcea06ef
>> Author:     Yao Qi <yao.qi@linaro.org>
>> AuthorDate: Tue Jul 7 16:58:19 2015 +0100
>> Commit:     Yao Qi <yao.qi@linaro.org>
>> CommitDate: Tue Jul 7 16:58:19 2015 +0100
>>
>>      Adjust gdb.multi tests for aarch64
>>           Multi-arch related tests under gdb.multi are to compile programs with
>>      the same compiler but different compiler options (-m64 vs -m32).  However,
>>      different compilers are needed to compile both aarch64 program and
>>      arm (aarch32) program.  This patch is to adjust these test cases to
>>      compile programs in different modes with different compiler.
>>           When we use gcc for arm-linux target, its file name can be different,
>>      arm-linux-gnueabihf-gcc, arm-linux-gnueabi-gcc, or arm-none-linux-gnueabi-gcc,
>>      so I add a variable ARM_CC_FOR_TARGET, so that user can set the name
>>      of gcc for arm-linux target on aarch64, like:
>>            $ make check RUNTESTFLAGS='ARM_CC_FOR_TARGET=arm-linux-gnueabihf-gcc multi-arch.exp'
>>           gdb/testsuite:
>>           2015-07-07  Yao Qi  <yao.qi@linaro.org>
>>                   * gdb.multi/multi-arch-exec.exp: Set march1 and march2 to "" if target
>>              is aarch64.  If target is aarch64, set compiler=${ARM_CC_FOR_TARGET}
>>              if it exists.
>>              * gdb.multi/multi-arch.exp: Likewise.
>>
>> ~~~~~
>>
>> I guess the issue is that nobody ever remembers to set ARM_CC_FOR_TARGET, or even
>> knows about it.
> 
> Yeah. As a general comment, I always have to stop and think about the list of things that need
> to be installed in order for GDB's testsuite to run all/most of the tests.

Yes.  I think a nice solution for that would be to have a script under gdb/contrib/ that installs
all the build & test dependencies on per distro basis.  We have some of that in the old buildbot
wiki:

  https://sourceware.org/gdb/wiki/BuildBot#Buildslave_configuration

and also mjw's new buildbot infrastructure also is gaining some docker scripts that know the same.
But I think putting it in gdb/contrib/ would be better so that everyone has easy access to it.

> 
> If you're missing something, most of the time things show up as UNTESTED/UNSUPPORTED. It
> would be nice to have a stable list of things we need to have complete (as much as possible)
> testsuite coverage.
> 
> Having to set these options by hand is quite obscure as well.

Yes, hence my proposed patch in the follow up email.  I think that we should strive to make
just "make check" (with no options) Just Work.

> 
>>
>> IWBN if the aarch64 bots people have access to tested with ARM_CC_FOR_TARGET, if they
>> aren't already.
> 
> I think it is a less common scenario. Yes, this is supported, but my feeling is that people
> seldom use this. Which explains why nobody complained, and some are surprised this even works.
> 

A 64-bit program can always exec a 32-bit program.  Likewise the other way around.  That should be
debuggable with a single gdb.

As you say, it's supported.  So, better test it routinely.  Not testing it doesn't gain us anything,
other than leading to bitrot, as has happened.

>>
>> Maybe it would be possible to come up with a way to default ARM_CC_FOR_TARGET to
>> something that works for most people when testing aarch64, somehow.
> The problem is that a compiler is not enough to make things run fine. If you have an aarch64
> Ubuntu, for example, you'd need to add armhf as an architecture option and install both the
> compiler and the libraries (libc6:armhf mostly).

That is not an issue specific to aarch64.  On x86-64, you need to install extra runtime
packages to test -m32 too, just the compiler isn't enough, and those packages aren't installed
by default.

> 
> Another problem is that not every processor/kernel supports running a 32-bit process in a
> 64-bit environment. This makes things more complicated.
> 

Why "more complicated"?  If you're worried about FAILs in the testsuite, then we can e.g. make it run
the 32-bit program once outside gdb to check that running 32-bits works.  If that fails, then
we don't run the test.  Seems simple, not complicated.

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH 5/5] gdb: native target invalid architecture detection
  2022-06-08  8:18                   ` Luis Machado
@ 2022-06-08 10:17                     ` Pedro Alves
  0 siblings, 0 replies; 83+ messages in thread
From: Pedro Alves @ 2022-06-08 10:17 UTC (permalink / raw)
  To: Luis Machado, Andrew Burgess, John Baldwin, gdb-patches

On 2022-06-08 09:18, Luis Machado wrote:
> On 6/7/22 21:15, Pedro Alves wrote:
>> On 2022-06-07 19:42, Pedro Alves wrote:
>>
>>>      When we use gcc for arm-linux target, its file name can be different,
>>>      arm-linux-gnueabihf-gcc, arm-linux-gnueabi-gcc, or arm-none-linux-gnueabi-gcc,
>>>      so I add a variable ARM_CC_FOR_TARGET, so that user can set the name
>>>      of gcc for arm-linux target on aarch64, like:
>>
>> ...
>>
>>> Maybe it would be possible to come up with a way to default ARM_CC_FOR_TARGET to
>>> something that works for most people when testing aarch64, somehow.
>>
>> Maybe something like this?  Completely untested, other than hacking it such that
>> the aarch64 linux path is taken on my x86-64 box, to ensure the tcl at least parses
>> as expected.
>>
> 
> Thanks for the patch. I think it is fine to have some of these tests run conditionally
> based on the presence of an environment variable. What we're really missing is proper
> documentation of ARM_CC_FOR_TARGET, explaining what it does, when it should be enabled
> and under what conditions.

I agree we're missing documentation of that option, but I don't think fixing that should
prevent making "make check" with no options Just Work, with the ARM_CC_FOR_TARGET option
being there as an escape hatch for the less common scenario.  I think I should be able to
e.g., log in some aarch64 machine on the compile farm to test something, and not have
to remember to pass arch specific options to make check.

> 
> I wonder if putting that on the GDB manual, under a testing section, would work. The Wiki
> has an entry for testing, but I find it a bit chaotic. What do you say?

Testsuite options are documented in gdb/testsuite/README.

^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCH v2] aarch64: Add fallback if ARM_CC_FOR_TARGET not set (was: Re: [PATCH 5/5] gdb: native target invalid architecture detection)
  2022-06-08 10:12                   ` Pedro Alves
@ 2022-06-08 11:20                     ` Pedro Alves
  2022-06-08 12:50                       ` Luis Machado
                                         ` (2 more replies)
  0 siblings, 3 replies; 83+ messages in thread
From: Pedro Alves @ 2022-06-08 11:20 UTC (permalink / raw)
  To: Luis Machado, Andrew Burgess, John Baldwin, gdb-patches

On 2022-06-08 11:12, Pedro Alves wrote:
> On 2022-06-08 08:54, Luis Machado wrote:

> A 64-bit program can always exec a 32-bit program.  Likewise the other way around.  That should be
> debuggable with a single gdb.
> 
> As you say, it's supported.  So, better test it routinely.  Not testing it doesn't gain us anything,
> other than leading to bitrot, as has happened.
> 
>>>
>>> Maybe it would be possible to come up with a way to default ARM_CC_FOR_TARGET to
>>> something that works for most people when testing aarch64, somehow.
>> The problem is that a compiler is not enough to make things run fine. If you have an aarch64
>> Ubuntu, for example, you'd need to add armhf as an architecture option and install both the
>> compiler and the libraries (libc6:armhf mostly).
> 
> That is not an issue specific to aarch64.  On x86-64, you need to install extra runtime
> packages to test -m32 too, just the compiler isn't enough, and those packages aren't installed
> by default.
> 
>>
>> Another problem is that not every processor/kernel supports running a 32-bit process in a
>> 64-bit environment. This makes things more complicated.
>>
> 
> Why "more complicated"?  If you're worried about FAILs in the testsuite, then we can e.g. make it run
> the 32-bit program once outside gdb to check that running 32-bits works.  If that fails, then
> we don't run the test.  Seems simple, not complicated.

Here's a new version of the patch, doing that.  This version also moves the ARM_CC_FOR_TARGET fallback
discovery to lib/gdb.exp so it can be used by gdb.multi/multi-arch-exec.exp as well.  I've now tested
this on gcc80 on the GCC compile farm (an aarch64 ubuntu 18.04 machine), and confirmed that it works.  As in,
we pick the right compiler (turns out it is arm-linux-gnueabihf-gcc, the third fallback compiler, so the try-to-run
code is exercised).  Of course, the testcases actually FAIL, due to 32-bit support bitrot in gdb itself.

From 689671e40f88f1bf29af2433c7b6c7662c8f38c6 Mon Sep 17 00:00:00 2001
From: Pedro Alves <pedro@palves.net>
Date: Tue, 7 Jun 2022 20:11:32 +0100
Subject: [PATCH] aarch64: Add fallback if ARM_CC_FOR_TARGET not set

On Aarch64, you can set ARM_CC_FOR_TARGET to point to the 32-bit
compiler to use when testing gdb.multi/multi-arch.exp and
gdb.multi/multi-arch-exec.exp.  If you don't set it, then those
testcases don't run.

I guess that approximately nobody remembers to set ARM_CC_FOR_TARGET.

This commit adds a fallback.  If ARM_CC_FOR_TARGET is not set, and
testing for Linux, try arm-linux-gnueabi-gcc,
arm-none-linux-gnueabi-gcc, arm-linux-gnueabihf-gcc as 32-bit
compilers, making sure that the produced executable runs on the target
machine before claiming that the compiler produces useful executables.

Change-Id: Iefe5865d5fc84b4032eaff7f4c5c61582bf75c39
---
 gdb/testsuite/gdb.multi/multi-arch-exec.exp |  4 +-
 gdb/testsuite/gdb.multi/multi-arch.exp      |  4 +-
 gdb/testsuite/lib/gdb.exp                   | 57 +++++++++++++++++++++
 3 files changed, 61 insertions(+), 4 deletions(-)

diff --git a/gdb/testsuite/gdb.multi/multi-arch-exec.exp b/gdb/testsuite/gdb.multi/multi-arch-exec.exp
index a1496fb5571..a8e81e29ee9 100644
--- a/gdb/testsuite/gdb.multi/multi-arch-exec.exp
+++ b/gdb/testsuite/gdb.multi/multi-arch-exec.exp
@@ -62,8 +62,8 @@ proc append_arch2_options {options_var} {
     upvar 1 $options_var options
 
     if { [istarget "aarch64*-*-*"] } {
-	if {[info exists ARM_CC_FOR_TARGET]} {
-	    lappend options "compiler=${ARM_CC_FOR_TARGET}"
+	if {[arm_cc_for_target] != ""} {
+	    lappend options "compiler=[arm_cc_for_target]"
 	    return 1
 	} else {
 	    unsupported "ARM compiler is not known"
diff --git a/gdb/testsuite/gdb.multi/multi-arch.exp b/gdb/testsuite/gdb.multi/multi-arch.exp
index e5c2d9cc161..b564e6caf25 100644
--- a/gdb/testsuite/gdb.multi/multi-arch.exp
+++ b/gdb/testsuite/gdb.multi/multi-arch.exp
@@ -60,8 +60,8 @@ if { [build_executable "failed to prepare" ${exec1} "${srcfile1}" \
 set options [list debug]
 
 if [istarget "aarch64*-*-*"] {
-    if {[info exists ARM_CC_FOR_TARGET]} {
-	lappend options "compiler=${ARM_CC_FOR_TARGET}"
+    if {[arm_cc_for_target] != ""} {
+	lappend options "compiler=[arm_cc_for_target]"
     } else {
 	unsupported "ARM compiler is not known"
 	return -1
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 402450152ac..ac01a31655f 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -8666,5 +8666,62 @@ proc get_set_option_choices {set_cmd} {
     return $values
 }
 
+# Return the compiler that can generate 32-bit ARM executables.  Used
+# when testing biarch support on aarch64.  If ARM_CC_FOR_TARGET is
+# set, use that.  If not, try a few common compiler names, making sure
+# that the executable they produce can run.
+
+gdb_caching_proc arm_cc_for_target {
+    if {[info exists ARM_CC_FOR_TARGET]} {
+	# If the user specified the compiler explicitly, then don't
+	# check whether the resulting binary runs outside GDB.  Assume
+	# that it does, and if it turns out it doesn't, then the user
+	# should get loud FAILs, instead of UNSUPPORTED.
+	return $ARM_CC_FOR_TARGET
+    }
+
+    # Fallback to a few common compiler names.  Also confirm the
+    # produced binary actually runs on the system before declaring
+    # we've found the right compiler.
+
+    if [istarget "*-linux*-*"] {
+	set compilers {
+	    arm-linux-gnueabi-gcc
+	    arm-none-linux-gnueabi-gcc
+	    arm-linux-gnueabihf-gcc
+	}
+    } else {
+	set compilers {}
+    }
+
+    foreach compiler $compilers {
+	if {![is_remote host] && [which $compiler] == 0} {
+	    # Avoid "default_target_compile: Can't find
+	    # $compiler." warning issued from gdb_compile.
+	    continue
+	}
+
+	set src { int main() { return 0; } }
+	if {[gdb_simple_compile aarch64-32bit \
+		 $src \
+		 executable [list compiler=$compiler]]} {
+
+	    set result [remote_exec target $obj]
+	    set status [lindex $result 0]
+	    set output [lindex $result 1]
+
+	    file delete $obj
+
+	    if { $output != "" || $status != 0} {
+		continue
+	    }
+
+	    return $compiler
+	}
+    }
+
+    return ""
+}
+
 # Always load compatibility stuff.
 load_lib future.exp

base-commit: bcdbf606bc054bd1fa9a1c8978f2d3a57e42adf4
-- 
2.36.0


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v2] aarch64: Add fallback if ARM_CC_FOR_TARGET not set (was: Re: [PATCH 5/5] gdb: native target invalid architecture detection)
  2022-06-08 11:20                     ` [PATCH v2] aarch64: Add fallback if ARM_CC_FOR_TARGET not set (was: Re: [PATCH 5/5] gdb: native target invalid architecture detection) Pedro Alves
@ 2022-06-08 12:50                       ` Luis Machado
  2022-06-08 13:23                         ` Pedro Alves
  2022-06-08 13:38                       ` Andrew Burgess
  2022-06-08 19:01                       ` John Baldwin
  2 siblings, 1 reply; 83+ messages in thread
From: Luis Machado @ 2022-06-08 12:50 UTC (permalink / raw)
  To: Pedro Alves, Andrew Burgess, John Baldwin, gdb-patches

On 6/8/22 12:20, Pedro Alves wrote:
> On 2022-06-08 11:12, Pedro Alves wrote:
>> On 2022-06-08 08:54, Luis Machado wrote:
> 
>> A 64-bit program can always exec a 32-bit program.  Likewise the other way around.  That should be
>> debuggable with a single gdb.
>>
>> As you say, it's supported.  So, better test it routinely.  Not testing it doesn't gain us anything,
>> other than leading to bitrot, as has happened.
>>
>>>>
>>>> Maybe it would be possible to come up with a way to default ARM_CC_FOR_TARGET to
>>>> something that works for most people when testing aarch64, somehow.
>>> The problem is that a compiler is not enough to make things run fine. If you have an aarch64
>>> Ubuntu, for example, you'd need to add armhf as an architecture option and install both the
>>> compiler and the libraries (libc6:armhf mostly).
>>
>> That is not an issue specific to aarch64.  On x86-64, you need to install extra runtime
>> packages to test -m32 too, just the compiler isn't enough, and those packages aren't installed
>> by default.
>>
>>>
>>> Another problem is that not every processor/kernel supports running a 32-bit process in a
>>> 64-bit environment. This makes things more complicated.
>>>
>>
>> Why "more complicated"?  If you're worried about FAILs in the testsuite, then we can e.g. make it run
>> the 32-bit program once outside gdb to check that running 32-bits works.  If that fails, then
>> we don't run the test.  Seems simple, not complicated.
> 
> Here's a new version of the patch, doing that.  This version also moves the ARM_CC_FOR_TARGET fallback
> discovery to lib/gdb.exp so it can be used by gdb.multi/multi-arch-exec.exp as well.  I've now tested
> this on gcc80 on the GCC compile farm (an aarch64 ubuntu 18.04 machine), and confirmed that it works.  As in,
> we pick the right compiler (turns out it is arm-linux-gnueabihf-gcc, the third fallback compiler, so the try-to-run
> code is exercised).  Of course, the testcases actually FAIL, due to 32-bit support bitrot in gdb itself.
> 
>  From 689671e40f88f1bf29af2433c7b6c7662c8f38c6 Mon Sep 17 00:00:00 2001
> From: Pedro Alves <pedro@palves.net>
> Date: Tue, 7 Jun 2022 20:11:32 +0100
> Subject: [PATCH] aarch64: Add fallback if ARM_CC_FOR_TARGET not set
> 
> On Aarch64, you can set ARM_CC_FOR_TARGET to point to the 32-bit
> compiler to use when testing gdb.multi/multi-arch.exp and
> gdb.multi/multi-arch-exec.exp.  If you don't set it, then those
> testcases don't run.
> 
> I guess that approximately nobody remembers to set ARM_CC_FOR_TARGET.
> 
> This commit adds a fallback.  If ARM_CC_FOR_TARGET is not set, and
> testing for Linux, try arm-linux-gnueabi-gcc,
> arm-none-linux-gnueabi-gcc, arm-linux-gnueabihf-gcc as 32-bit
> compilers, making sure that the produced executable runs on the target
> machine before claiming that the compiler produces useful executables.
> 
> Change-Id: Iefe5865d5fc84b4032eaff7f4c5c61582bf75c39
> ---
>   gdb/testsuite/gdb.multi/multi-arch-exec.exp |  4 +-
>   gdb/testsuite/gdb.multi/multi-arch.exp      |  4 +-
>   gdb/testsuite/lib/gdb.exp                   | 57 +++++++++++++++++++++
>   3 files changed, 61 insertions(+), 4 deletions(-)
> 
> diff --git a/gdb/testsuite/gdb.multi/multi-arch-exec.exp b/gdb/testsuite/gdb.multi/multi-arch-exec.exp
> index a1496fb5571..a8e81e29ee9 100644
> --- a/gdb/testsuite/gdb.multi/multi-arch-exec.exp
> +++ b/gdb/testsuite/gdb.multi/multi-arch-exec.exp
> @@ -62,8 +62,8 @@ proc append_arch2_options {options_var} {
>       upvar 1 $options_var options
>   
>       if { [istarget "aarch64*-*-*"] } {
> -	if {[info exists ARM_CC_FOR_TARGET]} {
> -	    lappend options "compiler=${ARM_CC_FOR_TARGET}"
> +	if {[arm_cc_for_target] != ""} {
> +	    lappend options "compiler=[arm_cc_for_target]"
>   	    return 1
>   	} else {
>   	    unsupported "ARM compiler is not known"
> diff --git a/gdb/testsuite/gdb.multi/multi-arch.exp b/gdb/testsuite/gdb.multi/multi-arch.exp
> index e5c2d9cc161..b564e6caf25 100644
> --- a/gdb/testsuite/gdb.multi/multi-arch.exp
> +++ b/gdb/testsuite/gdb.multi/multi-arch.exp
> @@ -60,8 +60,8 @@ if { [build_executable "failed to prepare" ${exec1} "${srcfile1}" \
>   set options [list debug]
>   
>   if [istarget "aarch64*-*-*"] {
> -    if {[info exists ARM_CC_FOR_TARGET]} {
> -	lappend options "compiler=${ARM_CC_FOR_TARGET}"
> +    if {[arm_cc_for_target] != ""} {
> +	lappend options "compiler=[arm_cc_for_target]"
>       } else {
>   	unsupported "ARM compiler is not known"
>   	return -1
> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
> index 402450152ac..ac01a31655f 100644
> --- a/gdb/testsuite/lib/gdb.exp
> +++ b/gdb/testsuite/lib/gdb.exp
> @@ -8666,5 +8666,62 @@ proc get_set_option_choices {set_cmd} {
>       return $values
>   }
>   
> +# Return the compiler that can generate 32-bit ARM executables.  Used
> +# when testing biarch support on aarch64.  If ARM_CC_FOR_TARGET is
> +# set, use that.  If not, try a few common compiler names, making sure
> +# that the executable they produce can run.
> +
> +gdb_caching_proc arm_cc_for_target {
> +    if {[info exists ARM_CC_FOR_TARGET]} {
> +	# If the user specified the compiler explicitly, then don't
> +	# check whether the resulting binary runs outside GDB.  Assume
> +	# that it does, and if it turns out it doesn't, then the user
> +	# should get loud FAILs, instead of UNSUPPORTED.
> +	return $ARM_CC_FOR_TARGET
> +    }
> +
> +    # Fallback to a few common compiler names.  Also confirm the
> +    # produced binary actually runs on the system before declaring
> +    # we've found the right compiler.
> +
> +    if [istarget "*-linux*-*"] {
> +	set compilers {
> +	    arm-linux-gnueabi-gcc
> +	    arm-none-linux-gnueabi-gcc
> +	    arm-linux-gnueabihf-gcc
> +	}
> +    } else {
> +	set compilers {}
> +    }
> +
> +    foreach compiler $compilers {
> +	if {![is_remote host] && [which $compiler] == 0} {
> +	    # Avoid "default_target_compile: Can't find
> +	    # $compiler." warning issued from gdb_compile.
> +	    continue
> +	}
> +
> +	set src { int main() { return 0; } }
> +	if {[gdb_simple_compile aarch64-32bit \
> +		 $src \
> +		 executable [list compiler=$compiler]]} {
> +
> +	    set result [remote_exec target $obj]
> +	    set status [lindex $result 0]
> +	    set output [lindex $result 1]
> +
> +	    file delete $obj
> +
> +	    if { $output != "" || $status != 0} {
> +		continue
> +	    }
> +
> +	    return $compiler
> +	}
> +    }
> +
> +    return ""
> +}
> +
>   # Always load compatibility stuff.
>   load_lib future.exp
> 
> base-commit: bcdbf606bc054bd1fa9a1c8978f2d3a57e42adf4

That looks OK to me. Thanks for writing the patch.

I'll send a patch later documenting the ARM_CC_FOR_TARGET option and maybe another
one for listing/installing Ubuntu packages required by the testsuite for broad coverage.

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v2] aarch64: Add fallback if ARM_CC_FOR_TARGET not set (was: Re: [PATCH 5/5] gdb: native target invalid architecture detection)
  2022-06-08 12:50                       ` Luis Machado
@ 2022-06-08 13:23                         ` Pedro Alves
  0 siblings, 0 replies; 83+ messages in thread
From: Pedro Alves @ 2022-06-08 13:23 UTC (permalink / raw)
  To: Luis Machado, Andrew Burgess, John Baldwin, gdb-patches

On 2022-06-08 13:50, Luis Machado wrote:

> That looks OK to me. Thanks for writing the patch.
> 

Cool, I've now merged it (with some minor cosmetic touch-ups).

> I'll send a patch later documenting the ARM_CC_FOR_TARGET option and maybe another
> one for listing/installing Ubuntu packages required by the testsuite for broad coverage.

Great, thanks.  The script I envision would do something like:

ID="$(awk -F= '$1=="ID" { print $2 ;}' /etc/os-release)"
VERSION_ID="$(awk -F= '$1=="VERSION_ID" { print $2 ;}' /etc/os-release)"
case "$ID $VERSION_ID" in
    ....
    "ubuntu*")
        sudo apt install .....
    ;;
    "fedora*")
        sudo dnf install .....
    ;;
    ....
esac

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v2] aarch64: Add fallback if ARM_CC_FOR_TARGET not set (was: Re: [PATCH 5/5] gdb: native target invalid architecture detection)
  2022-06-08 11:20                     ` [PATCH v2] aarch64: Add fallback if ARM_CC_FOR_TARGET not set (was: Re: [PATCH 5/5] gdb: native target invalid architecture detection) Pedro Alves
  2022-06-08 12:50                       ` Luis Machado
@ 2022-06-08 13:38                       ` Andrew Burgess
  2022-06-08 19:01                       ` John Baldwin
  2 siblings, 0 replies; 83+ messages in thread
From: Andrew Burgess @ 2022-06-08 13:38 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Luis Machado, John Baldwin, gdb-patches

* Pedro Alves <pedro@palves.net> [2022-06-08 12:20:09 +0100]:

> On 2022-06-08 11:12, Pedro Alves wrote:
> > On 2022-06-08 08:54, Luis Machado wrote:
> 
> > A 64-bit program can always exec a 32-bit program.  Likewise the other way around.  That should be
> > debuggable with a single gdb.
> > 
> > As you say, it's supported.  So, better test it routinely.  Not testing it doesn't gain us anything,
> > other than leading to bitrot, as has happened.
> > 
> >>>
> >>> Maybe it would be possible to come up with a way to default ARM_CC_FOR_TARGET to
> >>> something that works for most people when testing aarch64, somehow.
> >> The problem is that a compiler is not enough to make things run fine. If you have an aarch64
> >> Ubuntu, for example, you'd need to add armhf as an architecture option and install both the
> >> compiler and the libraries (libc6:armhf mostly).
> > 
> > That is not an issue specific to aarch64.  On x86-64, you need to install extra runtime
> > packages to test -m32 too, just the compiler isn't enough, and those packages aren't installed
> > by default.
> > 
> >>
> >> Another problem is that not every processor/kernel supports running a 32-bit process in a
> >> 64-bit environment. This makes things more complicated.
> >>
> > 
> > Why "more complicated"?  If you're worried about FAILs in the testsuite, then we can e.g. make it run
> > the 32-bit program once outside gdb to check that running 32-bits works.  If that fails, then
> > we don't run the test.  Seems simple, not complicated.
> 
> Here's a new version of the patch, doing that.  This version also moves the ARM_CC_FOR_TARGET fallback
> discovery to lib/gdb.exp so it can be used by gdb.multi/multi-arch-exec.exp as well.  I've now tested
> this on gcc80 on the GCC compile farm (an aarch64 ubuntu 18.04 machine), and confirmed that it works.  As in,
> we pick the right compiler (turns out it is arm-linux-gnueabihf-gcc, the third fallback compiler, so the try-to-run
> code is exercised).  Of course, the testcases actually FAIL, due to
> 32-bit support bitrot in gdb itself.

Pedro,

Thanks for finding the test (and improving it).  I have a couple of
patches that I'm working on that fixes the ARM on AArch64
functionality, and I'll make sure to test it using this updated test
before posting to the m/l.

Thanks,
Andrew





> 
> From 689671e40f88f1bf29af2433c7b6c7662c8f38c6 Mon Sep 17 00:00:00 2001
> From: Pedro Alves <pedro@palves.net>
> Date: Tue, 7 Jun 2022 20:11:32 +0100
> Subject: [PATCH] aarch64: Add fallback if ARM_CC_FOR_TARGET not set
> 
> On Aarch64, you can set ARM_CC_FOR_TARGET to point to the 32-bit
> compiler to use when testing gdb.multi/multi-arch.exp and
> gdb.multi/multi-arch-exec.exp.  If you don't set it, then those
> testcases don't run.
> 
> I guess that approximately nobody remembers to set ARM_CC_FOR_TARGET.
> 
> This commit adds a fallback.  If ARM_CC_FOR_TARGET is not set, and
> testing for Linux, try arm-linux-gnueabi-gcc,
> arm-none-linux-gnueabi-gcc, arm-linux-gnueabihf-gcc as 32-bit
> compilers, making sure that the produced executable runs on the target
> machine before claiming that the compiler produces useful executables.
> 
> Change-Id: Iefe5865d5fc84b4032eaff7f4c5c61582bf75c39
> ---
>  gdb/testsuite/gdb.multi/multi-arch-exec.exp |  4 +-
>  gdb/testsuite/gdb.multi/multi-arch.exp      |  4 +-
>  gdb/testsuite/lib/gdb.exp                   | 57 +++++++++++++++++++++
>  3 files changed, 61 insertions(+), 4 deletions(-)
> 
> diff --git a/gdb/testsuite/gdb.multi/multi-arch-exec.exp b/gdb/testsuite/gdb.multi/multi-arch-exec.exp
> index a1496fb5571..a8e81e29ee9 100644
> --- a/gdb/testsuite/gdb.multi/multi-arch-exec.exp
> +++ b/gdb/testsuite/gdb.multi/multi-arch-exec.exp
> @@ -62,8 +62,8 @@ proc append_arch2_options {options_var} {
>      upvar 1 $options_var options
>  
>      if { [istarget "aarch64*-*-*"] } {
> -	if {[info exists ARM_CC_FOR_TARGET]} {
> -	    lappend options "compiler=${ARM_CC_FOR_TARGET}"
> +	if {[arm_cc_for_target] != ""} {
> +	    lappend options "compiler=[arm_cc_for_target]"
>  	    return 1
>  	} else {
>  	    unsupported "ARM compiler is not known"
> diff --git a/gdb/testsuite/gdb.multi/multi-arch.exp b/gdb/testsuite/gdb.multi/multi-arch.exp
> index e5c2d9cc161..b564e6caf25 100644
> --- a/gdb/testsuite/gdb.multi/multi-arch.exp
> +++ b/gdb/testsuite/gdb.multi/multi-arch.exp
> @@ -60,8 +60,8 @@ if { [build_executable "failed to prepare" ${exec1} "${srcfile1}" \
>  set options [list debug]
>  
>  if [istarget "aarch64*-*-*"] {
> -    if {[info exists ARM_CC_FOR_TARGET]} {
> -	lappend options "compiler=${ARM_CC_FOR_TARGET}"
> +    if {[arm_cc_for_target] != ""} {
> +	lappend options "compiler=[arm_cc_for_target]"
>      } else {
>  	unsupported "ARM compiler is not known"
>  	return -1
> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
> index 402450152ac..ac01a31655f 100644
> --- a/gdb/testsuite/lib/gdb.exp
> +++ b/gdb/testsuite/lib/gdb.exp
> @@ -8666,5 +8666,62 @@ proc get_set_option_choices {set_cmd} {
>      return $values
>  }
>  
> +# Return the compiler that can generate 32-bit ARM executables.  Used
> +# when testing biarch support on aarch64.  If ARM_CC_FOR_TARGET is
> +# set, use that.  If not, try a few common compiler names, making sure
> +# that the executable they produce can run.
> +
> +gdb_caching_proc arm_cc_for_target {
> +    if {[info exists ARM_CC_FOR_TARGET]} {
> +	# If the user specified the compiler explicitly, then don't
> +	# check whether the resulting binary runs outside GDB.  Assume
> +	# that it does, and if it turns out it doesn't, then the user
> +	# should get loud FAILs, instead of UNSUPPORTED.
> +	return $ARM_CC_FOR_TARGET
> +    }
> +
> +    # Fallback to a few common compiler names.  Also confirm the
> +    # produced binary actually runs on the system before declaring
> +    # we've found the right compiler.
> +
> +    if [istarget "*-linux*-*"] {
> +	set compilers {
> +	    arm-linux-gnueabi-gcc
> +	    arm-none-linux-gnueabi-gcc
> +	    arm-linux-gnueabihf-gcc
> +	}
> +    } else {
> +	set compilers {}
> +    }
> +
> +    foreach compiler $compilers {
> +	if {![is_remote host] && [which $compiler] == 0} {
> +	    # Avoid "default_target_compile: Can't find
> +	    # $compiler." warning issued from gdb_compile.
> +	    continue
> +	}
> +
> +	set src { int main() { return 0; } }
> +	if {[gdb_simple_compile aarch64-32bit \
> +		 $src \
> +		 executable [list compiler=$compiler]]} {
> +
> +	    set result [remote_exec target $obj]
> +	    set status [lindex $result 0]
> +	    set output [lindex $result 1]
> +
> +	    file delete $obj
> +
> +	    if { $output != "" || $status != 0} {
> +		continue
> +	    }
> +
> +	    return $compiler
> +	}
> +    }
> +
> +    return ""
> +}
> +
>  # Always load compatibility stuff.
>  load_lib future.exp
> 
> base-commit: bcdbf606bc054bd1fa9a1c8978f2d3a57e42adf4
> -- 
> 2.36.0
> 


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v2] aarch64: Add fallback if ARM_CC_FOR_TARGET not set (was: Re: [PATCH 5/5] gdb: native target invalid architecture detection)
  2022-06-08 11:20                     ` [PATCH v2] aarch64: Add fallback if ARM_CC_FOR_TARGET not set (was: Re: [PATCH 5/5] gdb: native target invalid architecture detection) Pedro Alves
  2022-06-08 12:50                       ` Luis Machado
  2022-06-08 13:38                       ` Andrew Burgess
@ 2022-06-08 19:01                       ` John Baldwin
  2022-06-08 21:48                         ` Pedro Alves
  2 siblings, 1 reply; 83+ messages in thread
From: John Baldwin @ 2022-06-08 19:01 UTC (permalink / raw)
  To: Pedro Alves, Luis Machado, Andrew Burgess, gdb-patches

On 6/8/22 4:20 AM, Pedro Alves wrote:
> On 2022-06-08 11:12, Pedro Alves wrote:
>> On 2022-06-08 08:54, Luis Machado wrote:
> 
>> A 64-bit program can always exec a 32-bit program.  Likewise the other way around.  That should be
>> debuggable with a single gdb.
>>
>> As you say, it's supported.  So, better test it routinely.  Not testing it doesn't gain us anything,
>> other than leading to bitrot, as has happened.
>>
>>>>
>>>> Maybe it would be possible to come up with a way to default ARM_CC_FOR_TARGET to
>>>> something that works for most people when testing aarch64, somehow.
>>> The problem is that a compiler is not enough to make things run fine. If you have an aarch64
>>> Ubuntu, for example, you'd need to add armhf as an architecture option and install both the
>>> compiler and the libraries (libc6:armhf mostly).
>>
>> That is not an issue specific to aarch64.  On x86-64, you need to install extra runtime
>> packages to test -m32 too, just the compiler isn't enough, and those packages aren't installed
>> by default.
>>
>>>
>>> Another problem is that not every processor/kernel supports running a 32-bit process in a
>>> 64-bit environment. This makes things more complicated.
>>>
>>
>> Why "more complicated"?  If you're worried about FAILs in the testsuite, then we can e.g. make it run
>> the 32-bit program once outside gdb to check that running 32-bits works.  If that fails, then
>> we don't run the test.  Seems simple, not complicated.
> 
> Here's a new version of the patch, doing that.  This version also moves the ARM_CC_FOR_TARGET fallback
> discovery to lib/gdb.exp so it can be used by gdb.multi/multi-arch-exec.exp as well.  I've now tested
> this on gcc80 on the GCC compile farm (an aarch64 ubuntu 18.04 machine), and confirmed that it works.  As in,
> we pick the right compiler (turns out it is arm-linux-gnueabihf-gcc, the third fallback compiler, so the try-to-run
> code is exercised).  Of course, the testcases actually FAIL, due to 32-bit support bitrot in gdb itself.
> 
>  From 689671e40f88f1bf29af2433c7b6c7662c8f38c6 Mon Sep 17 00:00:00 2001
> From: Pedro Alves <pedro@palves.net>
> Date: Tue, 7 Jun 2022 20:11:32 +0100
> Subject: [PATCH] aarch64: Add fallback if ARM_CC_FOR_TARGET not set
> 
> On Aarch64, you can set ARM_CC_FOR_TARGET to point to the 32-bit
> compiler to use when testing gdb.multi/multi-arch.exp and
> gdb.multi/multi-arch-exec.exp.  If you don't set it, then those
> testcases don't run.
> 
> I guess that approximately nobody remembers to set ARM_CC_FOR_TARGET.
> 
> This commit adds a fallback.  If ARM_CC_FOR_TARGET is not set, and
> testing for Linux, try arm-linux-gnueabi-gcc,
> arm-none-linux-gnueabi-gcc, arm-linux-gnueabihf-gcc as 32-bit
> compilers, making sure that the produced executable runs on the target
> machine before claiming that the compiler produces useful executables.

Note that if the target compiler is clang, it will probably already
support 32-bit ARM via a -target option.  Not sure if you want to try
to handle that case here as well?

The other wrinkle perhaps is that just because you have a capable
compiler around may not mean that you have 32-bit libraries available
to link against?  I'm not sure if the compilers you list in your patch
ensure that you have an ARM libc around as well via dependencies.

-- 
John Baldwin

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v2] aarch64: Add fallback if ARM_CC_FOR_TARGET not set (was: Re: [PATCH 5/5] gdb: native target invalid architecture detection)
  2022-06-08 19:01                       ` John Baldwin
@ 2022-06-08 21:48                         ` Pedro Alves
  2022-06-09 16:31                           ` John Baldwin
  0 siblings, 1 reply; 83+ messages in thread
From: Pedro Alves @ 2022-06-08 21:48 UTC (permalink / raw)
  To: John Baldwin, Luis Machado, Andrew Burgess, gdb-patches

On 2022-06-08 20:01, John Baldwin wrote:

>> This commit adds a fallback.  If ARM_CC_FOR_TARGET is not set, and
>> testing for Linux, try arm-linux-gnueabi-gcc,
>> arm-none-linux-gnueabi-gcc, arm-linux-gnueabihf-gcc as 32-bit
>> compilers, making sure that the produced executable runs on the target
>> machine before claiming that the compiler produces useful executables.
> 
> Note that if the target compiler is clang, it will probably already
> support 32-bit ARM via a -target option.  Not sure if you want to try
> to handle that case here as well?

Sure, why not.

Do these multi-arch tests work on FreeBSD?  At least gdb.multi/multi-arch.exp should,
since FreeBSD supports multi-process nowadays, right?

> 
> The other wrinkle perhaps is that just because you have a capable
> compiler around may not mean that you have 32-bit libraries available
> to link against?  I'm not sure if the compilers you list in your patch
> ensure that you have an ARM libc around as well via dependencies.
> 

That is exactly the same as on x86-64.  Just because you have gcc installed,
which can compile 32-bit x86 with "gcc -m32", it doesn't mean you have the 32-bit
runtime libs installed.  So any test using -m32 today may run into that issue already.

However, note the new arm_cc_for_target proc compiles/links AND tries to run the resulting
program.  If there's some basic 32-bit runtime dependency missing, then the probing 
program won't run successfully, and we'll try the next compiler in the list of potential
compilers.  If we run out of compilers, then the proc returns "" and the testcase that calls
arm_cc_for_target ends up bailing out with UNSUPPORTED, like so:

.    if {[arm_cc_for_target] != ""} {
        lappend options "compiler=[arm_cc_for_target]"
    } else {
        unsupported "ARM compiler is not known"
        return -1
    }

On the aarch64 ubuntu 18.04 machine on the compile farm, the first probed compiler
(arm-linux-gnueabi-gcc) compiles&links successfully, but then running the built probe
program fails.  The second alternative doesn't exist on the system (arm-none-linux-gnueabi-gcc),
so it's skipped, and then the last alternative (arm-linux-gnueabihf-gcc) compiles&links&runs
the probe program successfully, so that's then the compiler that is used by the actual testcases.

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v2] aarch64: Add fallback if ARM_CC_FOR_TARGET not set (was: Re: [PATCH 5/5] gdb: native target invalid architecture detection)
  2022-06-08 21:48                         ` Pedro Alves
@ 2022-06-09 16:31                           ` John Baldwin
  0 siblings, 0 replies; 83+ messages in thread
From: John Baldwin @ 2022-06-09 16:31 UTC (permalink / raw)
  To: Pedro Alves, Luis Machado, Andrew Burgess, gdb-patches

On 6/8/22 2:48 PM, Pedro Alves wrote:
> On 2022-06-08 20:01, John Baldwin wrote:
> 
>>> This commit adds a fallback.  If ARM_CC_FOR_TARGET is not set, and
>>> testing for Linux, try arm-linux-gnueabi-gcc,
>>> arm-none-linux-gnueabi-gcc, arm-linux-gnueabihf-gcc as 32-bit
>>> compilers, making sure that the produced executable runs on the target
>>> machine before claiming that the compiler produces useful executables.
>>
>> Note that if the target compiler is clang, it will probably already
>> support 32-bit ARM via a -target option.  Not sure if you want to try
>> to handle that case here as well?
> 
> Sure, why not.
> 
> Do these multi-arch tests work on FreeBSD?  At least gdb.multi/multi-arch.exp should,
> since FreeBSD supports multi-process nowadays, right?

Yes-ish.  There are some failures that are probably bugs in the FreeBSD
native target (or ptrace behavior with now signal catching works on
FreeBSD that breaks some test assumptions).
  
>> The other wrinkle perhaps is that just because you have a capable
>> compiler around may not mean that you have 32-bit libraries available
>> to link against?  I'm not sure if the compilers you list in your patch
>> ensure that you have an ARM libc around as well via dependencies.
>>
> 
> That is exactly the same as on x86-64.  Just because you have gcc installed,
> which can compile 32-bit x86 with "gcc -m32", it doesn't mean you have the 32-bit
> runtime libs installed.  So any test using -m32 today may run into that issue already.
> 
> However, note the new arm_cc_for_target proc compiles/links AND tries to run the resulting
> program.  If there's some basic 32-bit runtime dependency missing, then the probing
> program won't run successfully, and we'll try the next compiler in the list of potential
> compilers.  If we run out of compilers, then the proc returns "" and the testcase that calls
> arm_cc_for_target ends up bailing out with UNSUPPORTED, like so:
> 
> .    if {[arm_cc_for_target] != ""} {
>          lappend options "compiler=[arm_cc_for_target]"
>      } else {
>          unsupported "ARM compiler is not known"
>          return -1
>      }
> 
> On the aarch64 ubuntu 18.04 machine on the compile farm, the first probed compiler
> (arm-linux-gnueabi-gcc) compiles&links successfully, but then running the built probe
> program fails.  The second alternative doesn't exist on the system (arm-none-linux-gnueabi-gcc),
> so it's skipped, and then the last alternative (arm-linux-gnueabihf-gcc) compiles&links&runs
> the probe program successfully, so that's then the compiler that is used by the actual testcases.

Ok, that works great then.  Right now FreeBSD doesn't build and ship 32-bit
libraries for aarch64 by default.  If that changes in the future I will take
a stab at updating this function to support clang by trying to use -target
if the current CC is already clang.

-- 
John Baldwin

^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCHv2 0/6] Handle trying to use a native target with the wrong binary
  2022-05-31 14:30 [PATCH 0/5] Handle trying to use a native target with the wrong binary Andrew Burgess
                   ` (4 preceding siblings ...)
  2022-05-31 14:30 ` [PATCH 5/5] gdb: native target invalid architecture detection Andrew Burgess
@ 2022-06-10 13:08 ` Andrew Burgess
  2022-06-10 13:08   ` [PATCHv2 1/6] gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope Andrew Burgess
                     ` (6 more replies)
  5 siblings, 7 replies; 83+ messages in thread
From: Andrew Burgess @ 2022-06-10 13:08 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

Changes since v1:

 - Patches #1 and #2 are unchanged.

 - Patch #3 is new in this version.

 - Patch #4 is unchanged (was patch 3).

 - Patch #5 is updated inline with John's feedback (was patch 4).

 - Patch #6 is extended to handle multi-arch case for rs6000/ppc and
   arm/aarch64, commit message is updated to discuss these cases, as
   well as mentioning i386/x86-64 (was patch 5).

Series has been tested on x86-64/linux and aarch64/linux.

---

Andrew Burgess (6):
  gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope
  gdb/mips: rewrite show_mask_address
  gdb/arm: avoid undefined behaviour in arm_frame_is_thumb
  gdb: move the type cast into gdbarch_tdep
  gdb: ensure the cast in gdbarch_tdep is valid
  gdb: native target invalid architecture detection

 gdb/aarch64-fbsd-nat.c     |   4 +-
 gdb/aarch64-fbsd-tdep.c    |   6 +-
 gdb/aarch64-linux-nat.c    |  28 +++++---
 gdb/aarch64-linux-tdep.c   |  10 +--
 gdb/aarch64-newlib-tdep.c  |   2 +-
 gdb/aarch64-tdep.c         |  48 ++++++-------
 gdb/aix-thread.c           |  28 ++++----
 gdb/alpha-linux-tdep.c     |   2 +-
 gdb/alpha-netbsd-tdep.c    |   2 +-
 gdb/alpha-obsd-tdep.c      |   2 +-
 gdb/alpha-tdep.c           |  14 ++--
 gdb/amd64-darwin-tdep.c    |   2 +-
 gdb/amd64-fbsd-nat.c       |   4 +-
 gdb/amd64-fbsd-tdep.c      |   4 +-
 gdb/amd64-linux-tdep.c     |   8 +--
 gdb/amd64-netbsd-tdep.c    |   2 +-
 gdb/amd64-obsd-tdep.c      |   2 +-
 gdb/amd64-sol2-tdep.c      |   2 +-
 gdb/amd64-tdep.c           |  34 ++++-----
 gdb/amd64-windows-tdep.c   |   2 +-
 gdb/arc-linux-tdep.c       |   4 +-
 gdb/arc-newlib-tdep.c      |   2 +-
 gdb/arc-tdep.c             |   8 +--
 gdb/arch-utils.c           |  14 +++-
 gdb/arch-utils.h           |   5 ++
 gdb/arm-fbsd-nat.c         |   4 +-
 gdb/arm-fbsd-tdep.c        |   6 +-
 gdb/arm-linux-nat.c        |   8 +--
 gdb/arm-linux-tdep.c       |   4 +-
 gdb/arm-netbsd-nat.c       |   8 +--
 gdb/arm-netbsd-tdep.c      |   4 +-
 gdb/arm-none-tdep.c        |   2 +-
 gdb/arm-obsd-tdep.c        |   2 +-
 gdb/arm-tdep.c             | 140 ++++++++++++++++++++-----------------
 gdb/arm-wince-tdep.c       |   2 +-
 gdb/avr-tdep.c             |  12 ++--
 gdb/bfin-tdep.c            |   4 +-
 gdb/cris-linux-tdep.c      |   2 +-
 gdb/cris-tdep.c            |  18 ++---
 gdb/csky-tdep.c            |   2 +-
 gdb/frv-tdep.c             |   4 +-
 gdb/ft32-tdep.c            |   2 +-
 gdb/gdbarch.h              |  26 ++++++-
 gdb/hppa-bsd-tdep.c        |   2 +-
 gdb/hppa-linux-tdep.c      |   4 +-
 gdb/hppa-tdep.c            |  12 ++--
 gdb/i386-bsd-tdep.c        |   2 +-
 gdb/i386-darwin-tdep.c     |   4 +-
 gdb/i386-fbsd-tdep.c       |   4 +-
 gdb/i386-gnu-tdep.c        |   2 +-
 gdb/i386-go32-tdep.c       |   2 +-
 gdb/i386-linux-tdep.c      |   4 +-
 gdb/i386-netbsd-tdep.c     |   4 +-
 gdb/i386-nto-tdep.c        |   6 +-
 gdb/i386-obsd-tdep.c       |   2 +-
 gdb/i386-sol2-tdep.c       |   2 +-
 gdb/i386-tdep.c            |  98 +++++++++++++-------------
 gdb/i386-windows-tdep.c    |   2 +-
 gdb/i387-tdep.c            |  20 +++---
 gdb/ia64-linux-tdep.c      |   2 +-
 gdb/ia64-tdep.c            |  12 ++--
 gdb/inf-child.c            |  19 +++++
 gdb/inf-child.h            |   2 +
 gdb/infcmd.c               |   8 +++
 gdb/loongarch-linux-nat.c  |   6 +-
 gdb/loongarch-linux-tdep.c |   8 +--
 gdb/loongarch-tdep.c       |  10 +--
 gdb/m32c-tdep.c            |  58 +++++++--------
 gdb/m68hc11-tdep.c         |  12 ++--
 gdb/m68k-bsd-tdep.c        |   2 +-
 gdb/m68k-linux-tdep.c      |   2 +-
 gdb/m68k-tdep.c            |  38 +++++-----
 gdb/mep-tdep.c             |   6 +-
 gdb/mips-linux-tdep.c      |   4 +-
 gdb/mips-tdep.c            |  85 +++++++++++-----------
 gdb/mn10300-tdep.c         |   2 +-
 gdb/mn10300-tdep.h         |   2 +-
 gdb/msp430-tdep.c          |  12 ++--
 gdb/nds32-tdep.c           |  20 +++---
 gdb/nios2-linux-tdep.c     |   2 +-
 gdb/nios2-tdep.c           |   4 +-
 gdb/or1k-tdep.c            |   8 +--
 gdb/ppc-fbsd-nat.c         |  12 +++-
 gdb/ppc-fbsd-tdep.c        |   8 +--
 gdb/ppc-linux-nat.c        |  30 +++++---
 gdb/ppc-linux-tdep.c       |  18 ++---
 gdb/ppc-netbsd-nat.c       |   6 +-
 gdb/ppc-netbsd-tdep.c      |   2 +-
 gdb/ppc-obsd-nat.c         |  12 +++-
 gdb/ppc-obsd-tdep.c        |   2 +-
 gdb/ppc-sysv-tdep.c        |  22 +++---
 gdb/ppc64-tdep.c           |   2 +-
 gdb/riscv-linux-tdep.c     |   2 +-
 gdb/riscv-tdep.c           |  26 +++----
 gdb/rl78-tdep.c            |   8 +--
 gdb/rs6000-aix-nat.c       |  14 +++-
 gdb/rs6000-aix-tdep.c      |  16 ++---
 gdb/rs6000-lynx178-tdep.c  |   4 +-
 gdb/rs6000-tdep.c          | 132 +++++++++++++++++-----------------
 gdb/rx-tdep.c              |   2 +-
 gdb/s390-linux-tdep.c      |  20 +++---
 gdb/s390-tdep.c            |  42 +++++------
 gdb/sh-linux-tdep.c        |   2 +-
 gdb/sh-netbsd-tdep.c       |   2 +-
 gdb/sh-tdep.c              |   8 +--
 gdb/sparc-linux-tdep.c     |   4 +-
 gdb/sparc-netbsd-tdep.c    |   2 +-
 gdb/sparc-sol2-tdep.c      |   2 +-
 gdb/sparc-tdep.c           |  14 ++--
 gdb/sparc64-fbsd-tdep.c    |   2 +-
 gdb/sparc64-linux-tdep.c   |   4 +-
 gdb/sparc64-netbsd-tdep.c  |   2 +-
 gdb/sparc64-obsd-tdep.c    |   2 +-
 gdb/sparc64-sol2-tdep.c    |   2 +-
 gdb/sparc64-tdep.c         |  10 +--
 gdb/target-delegates.c     |  28 ++++++++
 gdb/target.h               |  13 +++-
 gdb/tic6x-linux-tdep.c     |   6 +-
 gdb/tic6x-tdep.c           |   6 +-
 gdb/v850-tdep.c            |   6 +-
 gdb/windows-nat.c          |   2 +-
 gdb/xtensa-linux-nat.c     |   4 +-
 gdb/xtensa-linux-tdep.c    |   2 +-
 gdb/xtensa-tdep.c          |  54 +++++++-------
 gdb/z80-tdep.c             |   8 +--
 125 files changed, 849 insertions(+), 699 deletions(-)

-- 
2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCHv2 1/6] gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope
  2022-06-10 13:08 ` [PATCHv2 0/6] Handle trying to use a native target with the wrong binary Andrew Burgess
@ 2022-06-10 13:08   ` Andrew Burgess
  2022-06-10 13:08   ` [PATCHv2 2/6] gdb/mips: rewrite show_mask_address Andrew Burgess
                     ` (5 subsequent siblings)
  6 siblings, 0 replies; 83+ messages in thread
From: Andrew Burgess @ 2022-06-10 13:08 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

This is a small refactor to resolve an issue before it becomes a
problem in a later commit.

Move the fetching of an arm_gdbarch_tdep into a more inner scope
within two functions in arm-tdep.c.

The problem with the current code is that the functions in question
are used as the callbacks for two set/show parameters.  These set/show
parameters are available no matter the current architecture, but are
really about controlling an ARM architecture specific setting.  And
so, if I build GDB for all targets on an x86-64/GNU-Linux system, I
can still do this:

  (gdb) show arm fpu
  (gdb) show arm abi

After these calls we end up in show_fp_model and arm_show_abi
respectively, where we unconditionally do this:

  arm_gdbarch_tdep *tdep
    = (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());

However, the gdbarch_tdep() result will only be a arm_gdbarch_tdep if
the current architecture is ARM, otherwise the result will actually be
of some other type.

This isn't actually a problem, as in both cases the use of tdep is
guarded by a later check that the gdbarch architecture is
bfd_arch_arm.

This commit just moves the call to gdbarch_tdep() after the
architecture check.

In a later commit gdbarch_tdep() will be able to spot when we are
casting the result to the wrong type, and this function will trigger
assertion failures if things are not fixed.

There should be not user visible changes after this commit.
---
 gdb/arm-tdep.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 456649afdaa..7f27d4bd6e8 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -9077,14 +9077,16 @@ static void
 show_fp_model (struct ui_file *file, int from_tty,
 	       struct cmd_list_element *c, const char *value)
 {
-  arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
-
   if (arm_fp_model == ARM_FLOAT_AUTO
       && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm)
-    gdb_printf (file, _("\
+    {
+      arm_gdbarch_tdep *tdep
+	= (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+
+      gdb_printf (file, _("\
 The current ARM floating point model is \"auto\" (currently \"%s\").\n"),
-		fp_model_strings[tdep->fp_model]);
+		  fp_model_strings[tdep->fp_model]);
+    }
   else
     gdb_printf (file, _("\
 The current ARM floating point model is \"%s\".\n"),
@@ -9115,14 +9117,16 @@ static void
 arm_show_abi (struct ui_file *file, int from_tty,
 	     struct cmd_list_element *c, const char *value)
 {
-  arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
-
   if (arm_abi_global == ARM_ABI_AUTO
       && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm)
-    gdb_printf (file, _("\
+    {
+      arm_gdbarch_tdep *tdep
+	= (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+
+      gdb_printf (file, _("\
 The current ARM ABI is \"auto\" (currently \"%s\").\n"),
-		arm_abi_strings[tdep->arm_abi]);
+		  arm_abi_strings[tdep->arm_abi]);
+    }
   else
     gdb_printf (file, _("The current ARM ABI is \"%s\".\n"),
 		arm_abi_string);
-- 
2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCHv2 2/6] gdb/mips: rewrite show_mask_address
  2022-06-10 13:08 ` [PATCHv2 0/6] Handle trying to use a native target with the wrong binary Andrew Burgess
  2022-06-10 13:08   ` [PATCHv2 1/6] gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope Andrew Burgess
@ 2022-06-10 13:08   ` Andrew Burgess
  2022-06-10 13:08   ` [PATCHv2 3/6] gdb/arm: avoid undefined behaviour in arm_frame_is_thumb Andrew Burgess
                     ` (4 subsequent siblings)
  6 siblings, 0 replies; 83+ messages in thread
From: Andrew Burgess @ 2022-06-10 13:08 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

This commit is similar to the previous commit, but in this case GDB is
actually relying on undefined behaviour.

Consider building GDB for all targets on x86-64/GNU-Linux, then doing
this:

  (gdb) show mips mask-address
  Zeroing of upper 32 bits of 64-bit addresses is auto.
  The 32 bit address mask is set automatically.  Currently disabled
  (gdb)

The 'show mips mask-address' command ends up in show_mask_address in
mips-tdep.c, and this function does this:

  mips_gdbarch_tdep *tdep
    = (mips_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());

Later we might pass TDEP to mips_mask_address_p.  However, in my
example above, on an x86-64 native target, the current target
architecture will be an x86-64 gdbarch, and the tdep field within the
gdbarch will be of type i386_gdbarch_tdep, not of type
mips_gdbarch_tdep, as a result the cast above was incorrect, and TDEP
is not pointing at what it thinks it is.

I also think the current output is a little confusing, we appear to
have two lines that show the same information, but using different
words.

The first line comes from calling deprecated_show_value_hack, while
the second line is printed directly from show_mask_address.  However,
both of these lines are printing the same mask_address_var value.  I
don't think the two lines actually adds any value here.

Finally, none of the text in this function is passed through the
internationalisation mechanism.

It would be nice to remove another use of deprecated_show_value_hack
if possible, so this commit does a complete rewrite of
show_mask_address.

After this commit the output of the above example command, still on my
x86-64 native target is:

    (gdb) show mips mask-address
    Zeroing of upper 32 bits of 64-bit addresses is "auto" (current architecture is not MIPS).

The 'current architecture is not MIPS' text is only displayed when the
current architecture is not MIPS.  If the architecture is mips then we
get the more commonly seen 'currently "on"' or 'currently "off"', like
this:

  (gdb) set architecture mips
  The target architecture is set to "mips".
  (gdb) show mips mask-address
  Zeroing of upper 32 bits of 64-bit addresses is "auto" (currently "off").
  (gdb)

All the text is passed through the internationalisation mechanism, and
we only call gdbarch_tdep when we know the gdbarch architecture is
bfd_arch_mips.
---
 gdb/mips-tdep.c | 37 +++++++++++++++++--------------------
 1 file changed, 17 insertions(+), 20 deletions(-)

diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index 805c5beba59..fc1cb46de84 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -1183,28 +1183,25 @@ static void
 show_mask_address (struct ui_file *file, int from_tty,
 		   struct cmd_list_element *c, const char *value)
 {
-  mips_gdbarch_tdep *tdep
-    = (mips_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
-
-  deprecated_show_value_hack (file, from_tty, c, value);
-  switch (mask_address_var)
+  const char *additional_text = "";
+  if (mask_address_var == AUTO_BOOLEAN_AUTO)
     {
-    case AUTO_BOOLEAN_TRUE:
-      gdb_printf (file, "The 32 bit mips address mask is enabled\n");
-      break;
-    case AUTO_BOOLEAN_FALSE:
-      gdb_printf (file, "The 32 bit mips address mask is disabled\n");
-      break;
-    case AUTO_BOOLEAN_AUTO:
-      gdb_printf
-	(file,
-	 "The 32 bit address mask is set automatically.  Currently %s\n",
-	 mips_mask_address_p (tdep) ? "enabled" : "disabled");
-      break;
-    default:
-      internal_error (__FILE__, __LINE__, _("show_mask_address: bad switch"));
-      break;
+      if (gdbarch_bfd_arch_info (target_gdbarch ())->arch != bfd_arch_mips)
+	additional_text = _(" (current architecture is not MIPS)");
+      else
+	{
+	  mips_gdbarch_tdep *tdep
+	    = (mips_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+
+	  if (mips_mask_address_p (tdep))
+	    additional_text = _(" (currently \"on\")");
+	  else
+	    additional_text = _(" (currently \"off\")");
+	}
     }
+
+  gdb_printf (file, _("Zeroing of upper 32 bits of 64-bit addresses is \"%s\"%s.\n"),
+	      value, additional_text);
 }
 
 /* Tell if the program counter value in MEMADDR is in a standard ISA
-- 
2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCHv2 3/6] gdb/arm: avoid undefined behaviour in arm_frame_is_thumb
  2022-06-10 13:08 ` [PATCHv2 0/6] Handle trying to use a native target with the wrong binary Andrew Burgess
  2022-06-10 13:08   ` [PATCHv2 1/6] gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope Andrew Burgess
  2022-06-10 13:08   ` [PATCHv2 2/6] gdb/mips: rewrite show_mask_address Andrew Burgess
@ 2022-06-10 13:08   ` Andrew Burgess
  2022-06-10 15:21     ` Luis Machado
  2022-06-10 13:08   ` [PATCHv2 4/6] gdb: move the type cast into gdbarch_tdep Andrew Burgess
                     ` (3 subsequent siblings)
  6 siblings, 1 reply; 83+ messages in thread
From: Andrew Burgess @ 2022-06-10 13:08 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

This commit fixes real undefined behaviour in GDB which I spotted when
working on a later patch in this series.  The later patch in this
series detects when the result of gdbarch_tdep() is cast to the wrong
type.

The issue is revealed by the gdb.multi/multi-arch.exp test.

In this test we setup two inferiors, an AArch64 process, and an ARM
process, then at one point we have inferior 1 selected (the AArch64
inferior), and we place a breakpoint on a symbol present in the other
inferior (the ARM inferior).

During the process of creating the breakpoint we call arm_pc_is_thumb,
the GDBARCH passed into this function is correct, that is, represents
the ARM process.

For whatever reason we are unable to figure out if the address in
question is thumb or not throughout most of arm_pc_is_thumb, and so we
get to this code at the end of the function:

  /* If we couldn't find any symbol, but we're talking to a running
     target, then trust the current value of $cpsr.  This lets
     "display/i $pc" always show the correct mode (though if there is
     a symbol table we will not reach here, so it still may not be
     displayed in the mode it will be executed).  */
  if (target_has_registers ())
    return arm_frame_is_thumb (get_current_frame ());

Which I guess is a last attempt to figure out the thumb status of an
address.  However, remember, we the AArch64 inferior is current at
this time, so the current frame is an AArch64 frame.

In arm_frame_is_thumb we call arm_psr_thumb_bit with the architecture
of the current frame (which will be an AArch64 architecture).

And in arm_psr_thumb_bit we do this:

  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);

which assumes that the current architecture is an ARM architecture.
In our case this is not true, its AArch64, and so we cast the tdep
object to arm_gdbarch_tdep when really it is of type
aarch64_gdbarch_tdep.

After this we access the fields of the tdep object, but this is
undefined behaviour.

To fix this I propose adding new code to arm_frame_is_thumb that
checks the bfd architecture of the current frame.  And frame that is
not bfd_arch_arm can't be a thumb frame.

I could add a gdb_assert to arm_psr_thumb_bit, however, I have not
done this.  A later commit in this series will add an assert to the
gdbarch_tdep() call to ensure that the cast is of the correct type.
This will make any assert (of bfd architecture) added to
arm_psr_thumb_bit redundant, so I've not added any such assert here.

With this commit in place the gdb.multi/multi-arch.exp test continues
to pass after I have applied the later patches that detect incorrect
casting of the gdbarch_tdep objects.
---
 gdb/arm-tdep.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 7f27d4bd6e8..46027afade4 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -546,15 +546,19 @@ arm_is_thumb (struct regcache *regcache)
 int
 arm_frame_is_thumb (struct frame_info *frame)
 {
-  CORE_ADDR cpsr;
-  ULONGEST t_bit = arm_psr_thumb_bit (get_frame_arch (frame));
+  /* If the current frame is not ARM then it can't be thumb.  */
+  struct gdbarch *gdbarch = get_frame_arch (frame);
+  if (gdbarch_bfd_arch_info (target_gdbarch ())->arch != bfd_arch_arm)
+    return 0;
 
   /* Every ARM frame unwinder can unwind the T bit of the CPSR, either
      directly (from a signal frame or dummy frame) or by interpreting
      the saved LR (from a prologue or DWARF frame).  So consult it and
      trust the unwinders.  */
-  cpsr = get_frame_register_unsigned (frame, ARM_PS_REGNUM);
+  CORE_ADDR cpsr = get_frame_register_unsigned (frame, ARM_PS_REGNUM);
 
+  /* Find and extract the thumb bit.  */
+  ULONGEST t_bit = arm_psr_thumb_bit (gdbarch);
   return (cpsr & t_bit) != 0;
 }
 
-- 
2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCHv2 4/6] gdb: move the type cast into gdbarch_tdep
  2022-06-10 13:08 ` [PATCHv2 0/6] Handle trying to use a native target with the wrong binary Andrew Burgess
                     ` (2 preceding siblings ...)
  2022-06-10 13:08   ` [PATCHv2 3/6] gdb/arm: avoid undefined behaviour in arm_frame_is_thumb Andrew Burgess
@ 2022-06-10 13:08   ` Andrew Burgess
  2022-06-10 16:35     ` Luis Machado
  2022-06-10 13:08   ` [PATCHv2 5/6] gdb: ensure the cast in gdbarch_tdep is valid Andrew Burgess
                     ` (2 subsequent siblings)
  6 siblings, 1 reply; 83+ messages in thread
From: Andrew Burgess @ 2022-06-10 13:08 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

I built GDB for all targets on a x86-64/GNU-Linux system, and
then (accidentally) passed GDB a RISC-V binary, and asked GDB to "run"
the binary on the native target.  I got this error:

  (gdb) show architecture
  The target architecture is set to "auto" (currently "i386").
  (gdb) file /tmp/hello.rv32.exe
  Reading symbols from /tmp/hello.rv32.exe...
  (gdb) show architecture
  The target architecture is set to "auto" (currently "riscv:rv32").
  (gdb) run
  Starting program: /tmp/hello.rv32.exe
  ../../src/gdb/i387-tdep.c:596: internal-error: i387_supply_fxsave: Assertion `tdep->st0_regnum >= I386_ST0_REGNUM' failed.

What's going on here is this; initially the architecture is i386, this
is based on the default architecture, which is set based on the native
target.  After loading the RISC-V executable the architecture of the
current inferior is updated based on the architecture of the
executable.

When we "run", GDB does a fork & exec, with the inferior being
controlled through ptrace.  GDB sees an initial stop from the inferior
as soon as the inferior comes to life.  In response to this stop GDB
ends up calling save_stop_reason (linux-nat.c), which ends up trying
to read register from the inferior, to do this we end up calling
target_ops::fetch_registers, which, for the x86-64 native target,
calls amd64_linux_nat_target::fetch_registers.

After this I eventually end up in i387_supply_fxsave, different x86
based targets will end in different functions to fetch registers, but
it doesn't really matter which function we end up in, the problem is
this line, which is repeated in many places:

  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);

The problem here is that the ARCH in this line comes from the current
inferior, which, as we discussed above, will be a RISC-V gdbarch, the
tdep field will actually be of type riscv_gdbarch_tdep, not
i386_gdbarch_tdep.  After this cast we are relying on undefined
behaviour, in my case I happen to trigger an assert, but this might
not always be the case.

The thing I tried that exposed this problem was of course, trying to
start an executable of the wrong architecture on a native target.  I
don't think that the correct solution for this problem is to detect,
at the point of cast, that the gdbarch_tdep object is of the wrong
type, but, I did wonder, is there a way that we could protect
ourselves from incorrectly casting the gdbarch_tdep object?

I think that there is something we can do here, and this commit is the
first step in that direction, though no actual check is added by this
commit.

This commit can be split into two parts:

 (1) In gdbarch.h and arch-utils.c.  In these files I have modified
 gdbarch_tdep (the function) so that it now takes a template argument,
 like this:

    template<typename TDepType>
    static inline TDepType *
    gdbarch_tdep (struct gdbarch *gdbarch)
    {
      struct gdbarch_tdep *tdep = gdbarch_tdep_1 (gdbarch);
      return static_cast<TDepType *> (tdep);
    }

  After this change we are no better protected, but the cast is now
  done within the gdbarch_tdep function rather than at the call sites,
  this leads to the second, much larger change in this commit,

  (2) Everywhere gdbarch_tdep is called, we make changes like this:

    -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
    +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);

There should be no functional change after this commit.

In the next commit I will build on this change to add an assertion in
gdbarch_tdep that checks we are casting to the correct type.
---
 gdb/aarch64-fbsd-nat.c     |   4 +-
 gdb/aarch64-fbsd-tdep.c    |   6 +-
 gdb/aarch64-linux-nat.c    |  20 +++---
 gdb/aarch64-linux-tdep.c   |  10 +--
 gdb/aarch64-newlib-tdep.c  |   2 +-
 gdb/aarch64-tdep.c         |  48 +++++++-------
 gdb/aix-thread.c           |  28 ++++----
 gdb/alpha-linux-tdep.c     |   2 +-
 gdb/alpha-netbsd-tdep.c    |   2 +-
 gdb/alpha-obsd-tdep.c      |   2 +-
 gdb/alpha-tdep.c           |  14 ++--
 gdb/amd64-darwin-tdep.c    |   2 +-
 gdb/amd64-fbsd-nat.c       |   4 +-
 gdb/amd64-fbsd-tdep.c      |   4 +-
 gdb/amd64-linux-tdep.c     |   8 +--
 gdb/amd64-netbsd-tdep.c    |   2 +-
 gdb/amd64-obsd-tdep.c      |   2 +-
 gdb/amd64-sol2-tdep.c      |   2 +-
 gdb/amd64-tdep.c           |  34 +++++-----
 gdb/amd64-windows-tdep.c   |   2 +-
 gdb/arc-linux-tdep.c       |   4 +-
 gdb/arc-newlib-tdep.c      |   2 +-
 gdb/arc-tdep.c             |   8 +--
 gdb/arch-utils.c           |   6 +-
 gdb/arm-fbsd-nat.c         |   4 +-
 gdb/arm-fbsd-tdep.c        |   6 +-
 gdb/arm-linux-nat.c        |   8 +--
 gdb/arm-linux-tdep.c       |   4 +-
 gdb/arm-netbsd-nat.c       |   8 +--
 gdb/arm-netbsd-tdep.c      |   4 +-
 gdb/arm-none-tdep.c        |   2 +-
 gdb/arm-obsd-tdep.c        |   2 +-
 gdb/arm-tdep.c             | 110 +++++++++++++++----------------
 gdb/arm-wince-tdep.c       |   2 +-
 gdb/avr-tdep.c             |  12 ++--
 gdb/bfin-tdep.c            |   4 +-
 gdb/cris-linux-tdep.c      |   2 +-
 gdb/cris-tdep.c            |  18 ++---
 gdb/csky-tdep.c            |   2 +-
 gdb/frv-tdep.c             |   4 +-
 gdb/ft32-tdep.c            |   2 +-
 gdb/gdbarch.h              |  17 ++++-
 gdb/hppa-bsd-tdep.c        |   2 +-
 gdb/hppa-linux-tdep.c      |   4 +-
 gdb/hppa-tdep.c            |  12 ++--
 gdb/i386-bsd-tdep.c        |   2 +-
 gdb/i386-darwin-tdep.c     |   4 +-
 gdb/i386-fbsd-tdep.c       |   4 +-
 gdb/i386-gnu-tdep.c        |   2 +-
 gdb/i386-go32-tdep.c       |   2 +-
 gdb/i386-linux-tdep.c      |   4 +-
 gdb/i386-netbsd-tdep.c     |   4 +-
 gdb/i386-nto-tdep.c        |   6 +-
 gdb/i386-obsd-tdep.c       |   2 +-
 gdb/i386-sol2-tdep.c       |   2 +-
 gdb/i386-tdep.c            |  98 +++++++++++++--------------
 gdb/i386-windows-tdep.c    |   2 +-
 gdb/i387-tdep.c            |  20 +++---
 gdb/ia64-linux-tdep.c      |   2 +-
 gdb/ia64-tdep.c            |  12 ++--
 gdb/loongarch-linux-nat.c  |   6 +-
 gdb/loongarch-linux-tdep.c |   8 +--
 gdb/loongarch-tdep.c       |  10 +--
 gdb/m32c-tdep.c            |  58 ++++++++--------
 gdb/m68hc11-tdep.c         |  12 ++--
 gdb/m68k-bsd-tdep.c        |   2 +-
 gdb/m68k-linux-tdep.c      |   2 +-
 gdb/m68k-tdep.c            |  38 +++++------
 gdb/mep-tdep.c             |   6 +-
 gdb/mips-linux-tdep.c      |   4 +-
 gdb/mips-tdep.c            |  50 +++++++-------
 gdb/mn10300-tdep.c         |   2 +-
 gdb/mn10300-tdep.h         |   2 +-
 gdb/msp430-tdep.c          |  12 ++--
 gdb/nds32-tdep.c           |  20 +++---
 gdb/nios2-linux-tdep.c     |   2 +-
 gdb/nios2-tdep.c           |   4 +-
 gdb/or1k-tdep.c            |   8 +--
 gdb/ppc-fbsd-nat.c         |   4 +-
 gdb/ppc-fbsd-tdep.c        |   8 +--
 gdb/ppc-linux-nat.c        |  22 +++----
 gdb/ppc-linux-tdep.c       |  18 ++---
 gdb/ppc-netbsd-nat.c       |   6 +-
 gdb/ppc-netbsd-tdep.c      |   2 +-
 gdb/ppc-obsd-nat.c         |   4 +-
 gdb/ppc-obsd-tdep.c        |   2 +-
 gdb/ppc-sysv-tdep.c        |  22 +++----
 gdb/ppc64-tdep.c           |   2 +-
 gdb/riscv-linux-tdep.c     |   2 +-
 gdb/riscv-tdep.c           |  26 ++++----
 gdb/rl78-tdep.c            |   8 +--
 gdb/rs6000-aix-nat.c       |   6 +-
 gdb/rs6000-aix-tdep.c      |  16 ++---
 gdb/rs6000-lynx178-tdep.c  |   4 +-
 gdb/rs6000-tdep.c          | 132 ++++++++++++++++++-------------------
 gdb/rx-tdep.c              |   2 +-
 gdb/s390-linux-tdep.c      |  20 +++---
 gdb/s390-tdep.c            |  42 ++++++------
 gdb/sh-linux-tdep.c        |   2 +-
 gdb/sh-netbsd-tdep.c       |   2 +-
 gdb/sh-tdep.c              |   8 +--
 gdb/sparc-linux-tdep.c     |   4 +-
 gdb/sparc-netbsd-tdep.c    |   2 +-
 gdb/sparc-sol2-tdep.c      |   2 +-
 gdb/sparc-tdep.c           |  14 ++--
 gdb/sparc64-fbsd-tdep.c    |   2 +-
 gdb/sparc64-linux-tdep.c   |   4 +-
 gdb/sparc64-netbsd-tdep.c  |   2 +-
 gdb/sparc64-obsd-tdep.c    |   2 +-
 gdb/sparc64-sol2-tdep.c    |   2 +-
 gdb/sparc64-tdep.c         |  10 +--
 gdb/tic6x-linux-tdep.c     |   6 +-
 gdb/tic6x-tdep.c           |   6 +-
 gdb/v850-tdep.c            |   6 +-
 gdb/windows-nat.c          |   2 +-
 gdb/xtensa-linux-nat.c     |   4 +-
 gdb/xtensa-linux-tdep.c    |   2 +-
 gdb/xtensa-tdep.c          |  54 +++++++--------
 gdb/z80-tdep.c             |   8 +--
 119 files changed, 684 insertions(+), 667 deletions(-)

diff --git a/gdb/aarch64-fbsd-nat.c b/gdb/aarch64-fbsd-nat.c
index d8cf6227e73..708ddc40d58 100644
--- a/gdb/aarch64-fbsd-nat.c
+++ b/gdb/aarch64-fbsd-nat.c
@@ -90,7 +90,7 @@ aarch64_fbsd_nat_target::fetch_registers (struct regcache *regcache,
 				    &aarch64_fbsd_fpregset);
 
   gdbarch *gdbarch = regcache->arch ();
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   if (tdep->has_tls ())
     {
       const struct regcache_map_entry aarch64_fbsd_tls_regmap[] =
@@ -123,7 +123,7 @@ aarch64_fbsd_nat_target::store_registers (struct regcache *regcache,
 				    PT_SETFPREGS, &aarch64_fbsd_fpregset);
 
   gdbarch *gdbarch = regcache->arch ();
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   if (tdep->has_tls ())
     {
       const struct regcache_map_entry aarch64_fbsd_tls_regmap[] =
diff --git a/gdb/aarch64-fbsd-tdep.c b/gdb/aarch64-fbsd-tdep.c
index 891546b3c64..4a6b4115234 100644
--- a/gdb/aarch64-fbsd-tdep.c
+++ b/gdb/aarch64-fbsd-tdep.c
@@ -143,7 +143,7 @@ aarch64_fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					   void *cb_data,
 					   const struct regcache *regcache)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   cb (".reg", AARCH64_FBSD_SIZEOF_GREGSET, AARCH64_FBSD_SIZEOF_GREGSET,
       &aarch64_fbsd_gregset, NULL, cb_data);
@@ -190,7 +190,7 @@ static CORE_ADDR
 aarch64_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 				       CORE_ADDR lm_addr, CORE_ADDR offset)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   struct regcache *regcache;
 
   regcache = get_thread_arch_regcache (current_inferior ()->process_target (),
@@ -213,7 +213,7 @@ aarch64_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 static void
 aarch64_fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support.  */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c
index d58ad0143a2..a457fcd48ad 100644
--- a/gdb/aarch64-linux-nat.c
+++ b/gdb/aarch64-linux-nat.c
@@ -359,7 +359,7 @@ static void
 fetch_pauth_masks_from_thread (struct regcache *regcache)
 {
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
   int ret;
   struct iovec iovec;
   uint64_t pauth_regset[2] = {0, 0};
@@ -385,7 +385,7 @@ static void
 fetch_mteregs_from_thread (struct regcache *regcache)
 {
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
   int regno = tdep->mte_reg_base;
 
   gdb_assert (regno != -1);
@@ -410,7 +410,7 @@ static void
 store_mteregs_to_thread (struct regcache *regcache)
 {
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
   int regno = tdep->mte_reg_base;
 
   gdb_assert (regno != -1);
@@ -439,7 +439,7 @@ static void
 fetch_tlsregs_from_thread (struct regcache *regcache)
 {
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
   int regno = tdep->tls_regnum;
 
   gdb_assert (regno != -1);
@@ -464,7 +464,7 @@ static void
 store_tlsregs_to_thread (struct regcache *regcache)
 {
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
   int regno = tdep->tls_regnum;
 
   gdb_assert (regno != -1);
@@ -493,7 +493,7 @@ static void
 aarch64_fetch_registers (struct regcache *regcache, int regno)
 {
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
 
   if (regno == -1)
     {
@@ -543,7 +543,7 @@ static void
 aarch32_fetch_registers (struct regcache *regcache, int regno)
 {
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
 
   if (regno == -1)
     {
@@ -579,7 +579,7 @@ static void
 aarch64_store_registers (struct regcache *regcache, int regno)
 {
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
 
   if (regno == -1)
     {
@@ -619,7 +619,7 @@ static void
 aarch32_store_registers (struct regcache *regcache, int regno)
 {
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
 
   if (regno == -1)
     {
@@ -893,7 +893,7 @@ aarch64_linux_nat_target::thread_architecture (ptid_t ptid)
 
   /* Only return it if the current vector length matches the one in the tdep.  */
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (inf->gdbarch);
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (inf->gdbarch);
   uint64_t vq = aarch64_sve_get_vq (ptid.lwp ());
   if (vq == tdep->vq)
     return inf->gdbarch;
diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c
index 453692df2f4..4c96662efb3 100644
--- a/gdb/aarch64-linux-tdep.c
+++ b/gdb/aarch64-linux-tdep.c
@@ -286,7 +286,7 @@ aarch64_linux_sigframe_init (const struct tramp_frame *self,
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   CORE_ADDR sp = get_frame_register_unsigned (this_frame, AARCH64_SP_REGNUM);
   CORE_ADDR sigcontext_addr = (sp + AARCH64_RT_SIGFRAME_UCONTEXT_OFFSET
 			       + AARCH64_UCONTEXT_SIGCONTEXT_OFFSET );
@@ -640,7 +640,7 @@ aarch64_linux_collect_sve_regset (const struct regset *regset,
   gdb_byte *header = (gdb_byte *) buf;
   struct gdbarch *gdbarch = regcache->arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   uint64_t vq = tdep->vq;
 
   gdb_assert (buf != NULL);
@@ -676,7 +676,7 @@ aarch64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					    void *cb_data,
 					    const struct regcache *regcache)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   cb (".reg", AARCH64_LINUX_SIZEOF_GREGSET, AARCH64_LINUX_SIZEOF_GREGSET,
       &aarch64_linux_gregset, NULL, cb_data);
@@ -1743,7 +1743,7 @@ aarch64_linux_report_signal_info (struct gdbarch *gdbarch,
 				  struct ui_out *uiout,
 				  enum gdb_signal siggnal)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (!tdep->has_mte () || siggnal != GDB_SIGNAL_SEGV)
     return;
@@ -1812,7 +1812,7 @@ aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 								    NULL };
   static const char *const stap_register_indirection_suffixes[] = { "]",
 								    NULL };
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   tdep->lowest_pc = 0x8000;
 
diff --git a/gdb/aarch64-newlib-tdep.c b/gdb/aarch64-newlib-tdep.c
index 507b7fc5a51..c9236b17801 100644
--- a/gdb/aarch64-newlib-tdep.c
+++ b/gdb/aarch64-newlib-tdep.c
@@ -29,7 +29,7 @@
 static void
 aarch64_newlib_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   /* Jump buffer - support for longjmp.
      Offset of original PC in jump buffer (in registers).  */
diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
index 15b577c8a00..8670197a888 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -502,7 +502,7 @@ aarch64_analyze_prologue (struct gdbarch *gdbarch,
       else if (inst.opcode->iclass == ic_system)
 	{
 	  aarch64_gdbarch_tdep *tdep
-	    = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	    = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 	  int ra_state_val = 0;
 
 	  if (insn == 0xd503233f /* paciasp.  */
@@ -640,7 +640,7 @@ aarch64_analyze_prologue_test (void)
   struct aarch64_prologue_cache cache;
   cache.saved_regs = trad_frame_alloc_saved_regs (gdbarch);
 
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   /* Test the simple prologue in which frame pointer is used.  */
   {
@@ -1076,7 +1076,7 @@ aarch64_prologue_frame_unwind_stop_reason (struct frame_info *this_frame,
 
   /* Halt the backtrace at "_start".  */
   gdbarch *arch = get_frame_arch (this_frame);
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (arch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (arch);
   if (cache->prev_pc <= tdep->lowest_pc)
     return UNWIND_OUTERMOST;
 
@@ -1120,7 +1120,7 @@ aarch64_prologue_prev_register (struct frame_info *this_frame,
       CORE_ADDR lr;
       struct gdbarch *gdbarch = get_frame_arch (this_frame);
       aarch64_gdbarch_tdep *tdep
-	= (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	= gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
       lr = frame_unwind_register_unsigned (this_frame, AARCH64_LR_REGNUM);
 
@@ -1289,7 +1289,7 @@ aarch64_dwarf2_prev_register (struct frame_info *this_frame,
 			      void **this_cache, int regnum)
 {
   gdbarch *arch = get_frame_arch (this_frame);
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (arch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (arch);
   CORE_ADDR lr;
 
   switch (regnum)
@@ -1315,7 +1315,7 @@ aarch64_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
 			       struct dwarf2_frame_state_reg *reg,
 			       struct frame_info *this_frame)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   switch (regnum)
     {
@@ -1355,7 +1355,7 @@ static bool
 aarch64_execute_dwarf_cfa_vendor_op (struct gdbarch *gdbarch, gdb_byte op,
 				     struct dwarf2_frame_state *fs)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   struct dwarf2_frame_state_reg *ra_state;
 
   if (op == DW_CFA_AARCH64_negate_ra_state)
@@ -1996,7 +1996,7 @@ aarch64_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
 static struct type *
 aarch64_vnq_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vnq_type == NULL)
     {
@@ -2023,7 +2023,7 @@ aarch64_vnq_type (struct gdbarch *gdbarch)
 static struct type *
 aarch64_vnd_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vnd_type == NULL)
     {
@@ -2053,7 +2053,7 @@ aarch64_vnd_type (struct gdbarch *gdbarch)
 static struct type *
 aarch64_vns_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vns_type == NULL)
     {
@@ -2083,7 +2083,7 @@ aarch64_vns_type (struct gdbarch *gdbarch)
 static struct type *
 aarch64_vnh_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vnh_type == NULL)
     {
@@ -2116,7 +2116,7 @@ aarch64_vnh_type (struct gdbarch *gdbarch)
 static struct type *
 aarch64_vnb_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vnb_type == NULL)
     {
@@ -2143,7 +2143,7 @@ aarch64_vnb_type (struct gdbarch *gdbarch)
 static struct type *
 aarch64_vnv_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vnv_type == NULL)
     {
@@ -2214,7 +2214,7 @@ aarch64_vnv_type (struct gdbarch *gdbarch)
 static int
 aarch64_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (reg >= AARCH64_DWARF_X0 && reg <= AARCH64_DWARF_X0 + 30)
     return AARCH64_X0_REGNUM + reg - AARCH64_DWARF_X0;
@@ -2518,7 +2518,7 @@ aarch64_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
   CORE_ADDR jb_addr;
   gdb_byte buf[X_REGISTER_SIZE];
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   jb_addr = get_frame_register_unsigned (frame, AARCH64_X0_REGNUM);
@@ -2549,7 +2549,7 @@ aarch64_gen_return_address (struct gdbarch *gdbarch,
 static const char *
 aarch64_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   static const char *const q_name[] =
     {
@@ -2663,7 +2663,7 @@ aarch64_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 static struct type *
 aarch64_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   int p_regnum = regnum - gdbarch_num_regs (gdbarch);
 
@@ -2700,7 +2700,7 @@ static int
 aarch64_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 				    const struct reggroup *group)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   int p_regnum = regnum - gdbarch_num_regs (gdbarch);
 
@@ -2754,7 +2754,7 @@ static struct value *
 aarch64_pseudo_read_value (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int regnum)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   struct value *result_value = allocate_value (register_type (gdbarch, regnum));
 
   VALUE_LVAL (result_value) = lval_register;
@@ -2824,7 +2824,7 @@ static void
 aarch64_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache,
 		      int regnum, const gdb_byte *buf)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   regnum -= gdbarch_num_regs (gdbarch);
 
   if (regnum >= AARCH64_Q0_REGNUM && regnum < AARCH64_Q0_REGNUM + 32)
@@ -3377,7 +3377,7 @@ aarch64_get_tdesc_vq (const struct target_desc *tdesc)
 static int
 aarch64_cannot_store_register (struct gdbarch *gdbarch, int regnum)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (!tdep->has_pauth ())
     return 0;
@@ -3444,7 +3444,7 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
     {
       aarch64_gdbarch_tdep *tdep
-	= (aarch64_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
+	= gdbarch_tdep<aarch64_gdbarch_tdep> (best_arch->gdbarch);
       if (tdep && tdep->vq == vq)
 	return best_arch->gdbarch;
     }
@@ -3693,7 +3693,7 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 aarch64_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep == NULL)
     return;
@@ -3915,7 +3915,7 @@ aarch64_record_branch_except_sys (aarch64_insn_decode_record *aarch64_insn_r)
 {
 
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (aarch64_insn_r->gdbarch);
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (aarch64_insn_r->gdbarch);
   uint8_t insn_bits24_27, insn_bits28_31, insn_bits22_23;
   uint32_t record_buf[4];
 
diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c
index ecd8200b692..3d76b8c6d01 100644
--- a/gdb/aix-thread.c
+++ b/gdb/aix-thread.c
@@ -1114,7 +1114,7 @@ static void
 supply_gprs64 (struct regcache *regcache, uint64_t *vals)
 {
   ppc_gdbarch_tdep *tdep
-    = (ppc_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<ppc_gdbarch_tdep> (regcache->arch ());
   int regno;
 
   for (regno = 0; regno < ppc_num_gprs; regno++)
@@ -1136,7 +1136,7 @@ static void
 supply_fprs (struct regcache *regcache, double *vals)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int regno;
 
   /* This function should never be called on architectures without
@@ -1154,7 +1154,7 @@ supply_fprs (struct regcache *regcache, double *vals)
 static int
 special_register_p (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   return regno == gdbarch_pc_regnum (gdbarch)
       || regno == tdep->ppc_ps_regnum
@@ -1177,7 +1177,7 @@ supply_sprs64 (struct regcache *regcache,
 	       uint32_t fpscr)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   regcache->raw_supply (gdbarch_pc_regnum (gdbarch), (char *) &iar);
   regcache->raw_supply (tdep->ppc_ps_regnum, (char *) &msr);
@@ -1199,7 +1199,7 @@ supply_sprs32 (struct regcache *regcache,
 	       uint32_t fpscr)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   regcache->raw_supply (gdbarch_pc_regnum (gdbarch), (char *) &iar);
   regcache->raw_supply (tdep->ppc_ps_regnum, (char *) &msr);
@@ -1222,7 +1222,7 @@ static void
 fetch_regs_user_thread (struct regcache *regcache, pthdb_pthread_t pdtid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int status, i;
   pthdb_context_t ctx;
 
@@ -1277,7 +1277,7 @@ fetch_regs_kernel_thread (struct regcache *regcache, int regno,
 			  pthdb_tid_t tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   uint64_t gprs64[ppc_num_gprs];
   uint32_t gprs32[ppc_num_gprs];
   double fprs[ppc_num_fprs];
@@ -1380,7 +1380,7 @@ static void
 fill_gprs64 (const struct regcache *regcache, uint64_t *vals)
 {
   ppc_gdbarch_tdep *tdep
-    = (ppc_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<ppc_gdbarch_tdep> (regcache->arch ());
   int regno;
 
   for (regno = 0; regno < ppc_num_gprs; regno++)
@@ -1393,7 +1393,7 @@ static void
 fill_gprs32 (const struct regcache *regcache, uint32_t *vals)
 {
   ppc_gdbarch_tdep *tdep
-    = (ppc_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<ppc_gdbarch_tdep> (regcache->arch ());
   int regno;
 
   for (regno = 0; regno < ppc_num_gprs; regno++)
@@ -1407,7 +1407,7 @@ static void
 fill_fprs (const struct regcache *regcache, double *vals)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int regno;
 
   /* This function should never be called on architectures without
@@ -1431,7 +1431,7 @@ fill_sprs64 (const struct regcache *regcache,
 	     uint32_t *fpscr)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* Verify that the size of the size of the IAR buffer is the
      same as the raw size of the PC (in the register cache).  If
@@ -1465,7 +1465,7 @@ fill_sprs32 (const struct regcache *regcache,
 	     uint32_t *fpscr)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* Verify that the size of the size of the IAR buffer is the
      same as the raw size of the PC (in the register cache).  If
@@ -1502,7 +1502,7 @@ static void
 store_regs_user_thread (const struct regcache *regcache, pthdb_pthread_t pdtid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int status, i;
   pthdb_context_t ctx;
   uint32_t int32;
@@ -1592,7 +1592,7 @@ store_regs_kernel_thread (const struct regcache *regcache, int regno,
 			  pthdb_tid_t tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   uint64_t gprs64[ppc_num_gprs];
   uint32_t gprs32[ppc_num_gprs];
   double fprs[ppc_num_fprs];
diff --git a/gdb/alpha-linux-tdep.c b/gdb/alpha-linux-tdep.c
index 6cea40d3f34..c103aafc1ff 100644
--- a/gdb/alpha-linux-tdep.c
+++ b/gdb/alpha-linux-tdep.c
@@ -362,7 +362,7 @@ alpha_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   /* Hook into the MDEBUG frame unwinder.  */
   alpha_mdebug_init_abi (info, gdbarch);
 
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
   tdep->dynamic_sigtramp_offset = alpha_linux_sigtramp_offset;
   tdep->sigcontext_addr = alpha_linux_sigcontext_addr;
   tdep->pc_in_sigtramp = alpha_linux_pc_in_sigtramp;
diff --git a/gdb/alpha-netbsd-tdep.c b/gdb/alpha-netbsd-tdep.c
index 6b604cfa9c6..72d7019377f 100644
--- a/gdb/alpha-netbsd-tdep.c
+++ b/gdb/alpha-netbsd-tdep.c
@@ -250,7 +250,7 @@ static void
 alphanbsd_init_abi (struct gdbarch_info info,
 		    struct gdbarch *gdbarch)
 {
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
 
   /* Hook into the DWARF CFI frame unwinder.  */
   alpha_dwarf2_init_abi (info, gdbarch);
diff --git a/gdb/alpha-obsd-tdep.c b/gdb/alpha-obsd-tdep.c
index 8baa8cc32c4..c0d672c3f72 100644
--- a/gdb/alpha-obsd-tdep.c
+++ b/gdb/alpha-obsd-tdep.c
@@ -97,7 +97,7 @@ alphaobsd_sigcontext_addr (struct frame_info *this_frame)
 static void
 alphaobsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
 
   /* Hook into the DWARF CFI frame unwinder.  */
   alpha_dwarf2_init_abi (info, gdbarch);
diff --git a/gdb/alpha-tdep.c b/gdb/alpha-tdep.c
index f04bad6bed8..44efc8e4bbb 100644
--- a/gdb/alpha-tdep.c
+++ b/gdb/alpha-tdep.c
@@ -615,7 +615,7 @@ alpha_return_value (struct gdbarch *gdbarch, struct value *function,
 		    gdb_byte *readbuf, const gdb_byte *writebuf)
 {
   enum type_code code = type->code ();
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
 
   if ((code == TYPE_CODE_STRUCT
        || code == TYPE_CODE_UNION
@@ -851,7 +851,7 @@ static int
 alpha_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR jb_addr;
   gdb_byte raw_buffer[ALPHA_REGISTER_SIZE];
@@ -891,7 +891,7 @@ alpha_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
   *this_prologue_cache = info;
 
   gdbarch *arch = get_frame_arch (this_frame);
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (arch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (arch);
   info->sigcontext_addr = tdep->sigcontext_addr (this_frame);
 
   return info;
@@ -904,7 +904,7 @@ static CORE_ADDR
 alpha_sigtramp_register_address (struct gdbarch *gdbarch,
 				 CORE_ADDR sigcontext_addr, int regnum)
 { 
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
 
   if (regnum >= 0 && regnum < 32)
     return sigcontext_addr + tdep->sc_regs_offset + regnum * 8;
@@ -925,7 +925,7 @@ alpha_sigtramp_frame_this_id (struct frame_info *this_frame,
 			      struct frame_id *this_id)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
   struct alpha_sigtramp_unwind_cache *info
     = alpha_sigtramp_frame_unwind_cache (this_frame, this_prologue_cache);
   CORE_ADDR stack_addr, code_addr;
@@ -1000,7 +1000,7 @@ alpha_sigtramp_frame_sniffer (const struct frame_unwind *self,
 
   /* We shouldn't even bother to try if the OSABI didn't register a
      sigcontext_addr handler or pc_in_sigtramp handler.  */
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
   if (tdep->sigcontext_addr == NULL)
     return 0;
 
@@ -1041,7 +1041,7 @@ static int heuristic_fence_post = 0;
 static CORE_ADDR
 alpha_heuristic_proc_start (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
   CORE_ADDR last_non_nop = pc;
   CORE_ADDR fence = pc - heuristic_fence_post;
   CORE_ADDR orig_pc = pc;
diff --git a/gdb/amd64-darwin-tdep.c b/gdb/amd64-darwin-tdep.c
index 74906f6a02d..7fc35536bc6 100644
--- a/gdb/amd64-darwin-tdep.c
+++ b/gdb/amd64-darwin-tdep.c
@@ -97,7 +97,7 @@ amd64_darwin_sigcontext_addr (struct frame_info *this_frame)
 static void
 x86_darwin_init_abi_64 (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   amd64_init_abi (info, gdbarch,
 		  amd64_target_description (X86_XSTATE_SSE_MASK, true));
diff --git a/gdb/amd64-fbsd-nat.c b/gdb/amd64-fbsd-nat.c
index d125d582a21..7023a182e78 100644
--- a/gdb/amd64-fbsd-nat.c
+++ b/gdb/amd64-fbsd-nat.c
@@ -102,7 +102,7 @@ amd64_fbsd_nat_target::fetch_registers (struct regcache *regcache, int regnum)
 {
   struct gdbarch *gdbarch = regcache->arch ();
 #if defined(PT_GETFSBASE) || defined(PT_GETGSBASE)
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 #endif
   pid_t pid = get_ptrace_pid (regcache->ptid ());
   const struct regset *gregset = find_gregset (gdbarch);
@@ -174,7 +174,7 @@ amd64_fbsd_nat_target::store_registers (struct regcache *regcache, int regnum)
 {
   struct gdbarch *gdbarch = regcache->arch ();
 #if defined(PT_GETFSBASE) || defined(PT_GETGSBASE)
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 #endif
   pid_t pid = get_ptrace_pid (regcache->ptid ());
   const struct regset *gregset = find_gregset (gdbarch);
diff --git a/gdb/amd64-fbsd-tdep.c b/gdb/amd64-fbsd-tdep.c
index 55764beaad2..8e40283d838 100644
--- a/gdb/amd64-fbsd-tdep.c
+++ b/gdb/amd64-fbsd-tdep.c
@@ -262,7 +262,7 @@ amd64fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					void *cb_data,
 					const struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   cb (".reg", AMD64_FBSD_SIZEOF_GREGSET, AMD64_FBSD_SIZEOF_GREGSET,
       &amd64_fbsd_gregset, NULL, cb_data);
@@ -299,7 +299,7 @@ amd64fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 static void
 amd64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support. */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
index 9a0759d639c..aa9c56586ab 100644
--- a/gdb/amd64-linux-tdep.c
+++ b/gdb/amd64-linux-tdep.c
@@ -1656,7 +1656,7 @@ amd64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					  void *cb_data,
 					  const struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   cb (".reg", 27 * 8, 27 * 8, &i386_gregset, NULL, cb_data);
   cb (".reg2", 512, 512, &amd64_fpregset, NULL, cb_data);
@@ -1793,7 +1793,7 @@ static void
 amd64_linux_init_abi_common(struct gdbarch_info info, struct gdbarch *gdbarch,
 			    int num_disp_step_buffers)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, num_disp_step_buffers);
 
@@ -1846,7 +1846,7 @@ amd64_linux_init_abi_common(struct gdbarch_info info, struct gdbarch *gdbarch,
 static void
 amd64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   struct tdesc_arch_data *tdesc_data = info.tdesc_data;
   const struct tdesc_feature *feature;
   int valid_p;
@@ -2060,7 +2060,7 @@ amd64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 static void
 amd64_x32_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   struct tdesc_arch_data *tdesc_data = info.tdesc_data;
   const struct tdesc_feature *feature;
   int valid_p;
diff --git a/gdb/amd64-netbsd-tdep.c b/gdb/amd64-netbsd-tdep.c
index 3ab0267060d..59d723caa55 100644
--- a/gdb/amd64-netbsd-tdep.c
+++ b/gdb/amd64-netbsd-tdep.c
@@ -97,7 +97,7 @@ int amd64nbsd_r_reg_offset[] =
 static void
 amd64nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* Initialize general-purpose register set details first.  */
   tdep->gregset_reg_offset = amd64nbsd_r_reg_offset;
diff --git a/gdb/amd64-obsd-tdep.c b/gdb/amd64-obsd-tdep.c
index 3cb64fe924f..f0bc7c474a6 100644
--- a/gdb/amd64-obsd-tdep.c
+++ b/gdb/amd64-obsd-tdep.c
@@ -420,7 +420,7 @@ static const struct frame_unwind amd64obsd_trapframe_unwind =
 static void
 amd64obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   amd64_init_abi (info, gdbarch,
 		  amd64_target_description (X86_XSTATE_SSE_MASK, true));
diff --git a/gdb/amd64-sol2-tdep.c b/gdb/amd64-sol2-tdep.c
index 22a48e476a5..ce96eb045ec 100644
--- a/gdb/amd64-sol2-tdep.c
+++ b/gdb/amd64-sol2-tdep.c
@@ -80,7 +80,7 @@ amd64_sol2_mcontext_addr (struct frame_info *this_frame)
 static void
 amd64_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   tdep->gregset_reg_offset = amd64_sol2_gregset_reg_offset;
   tdep->gregset_num_regs = ARRAY_SIZE (amd64_sol2_gregset_reg_offset);
diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index b95ab1e87b8..0563b32a54b 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -247,7 +247,7 @@ static const int amd64_dwarf_regmap_len =
 static int
 amd64_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int ymm0_regnum = tdep->ymm0_regnum;
   int regnum = -1;
 
@@ -331,7 +331,7 @@ static const char * const amd64_dword_names[] =
 static const char *
 amd64_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   if (i386_byte_regnum_p (gdbarch, regnum))
     return amd64_byte_names[regnum - tdep->al_regnum];
   else if (i386_zmm_regnum_p (gdbarch, regnum))
@@ -353,7 +353,7 @@ amd64_pseudo_register_read_value (struct gdbarch *gdbarch,
 				  readable_regcache *regcache,
 				  int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   value *result_value = allocate_value (register_type (gdbarch, regnum));
   VALUE_LVAL (result_value) = lval_register;
@@ -413,7 +413,7 @@ amd64_pseudo_register_write (struct gdbarch *gdbarch,
 			     struct regcache *regcache,
 			     int regnum, const gdb_byte *buf)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (i386_byte_regnum_p (gdbarch, regnum))
     {
@@ -465,7 +465,7 @@ static int
 amd64_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				  struct agent_expr *ax, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (i386_byte_regnum_p (gdbarch, regnum))
     {
@@ -2749,7 +2749,7 @@ static struct amd64_frame_cache *
 amd64_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct amd64_frame_cache *cache;
   CORE_ADDR addr;
@@ -2832,7 +2832,7 @@ amd64_sigtramp_frame_sniffer (const struct frame_unwind *self,
 			      void **this_cache)
 {
   gdbarch *arch = get_frame_arch (this_frame);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
 
   /* We shouldn't even bother if we don't have a sigcontext_addr
      handler.  */
@@ -3032,7 +3032,7 @@ amd64_supply_fpregset (const struct regset *regset, struct regcache *regcache,
 		       int regnum, const void *fpregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   gdb_assert (len >= tdep->sizeof_fpregset);
   amd64_supply_fxsave (regcache, regnum, fpregs);
@@ -3049,7 +3049,7 @@ amd64_collect_fpregset (const struct regset *regset,
 			int regnum, void *fpregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   gdb_assert (len >= tdep->sizeof_fpregset);
   amd64_collect_fxsave (regcache, regnum, fpregs);
@@ -3073,7 +3073,7 @@ amd64_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
   gdb_byte buf[8];
   CORE_ADDR jb_addr;
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int jb_pc_offset = tdep->jb_pc_offset;
   int len = TYPE_LENGTH (builtin_type (gdbarch)->builtin_func_ptr);
 
@@ -3117,7 +3117,7 @@ void
 amd64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch,
 		const target_desc *default_tdesc)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   const struct target_desc *tdesc = info.target_desc;
   static const char *const stap_integer_prefixes[] = { "$", NULL };
   static const char *const stap_register_prefixes[] = { "%", NULL };
@@ -3296,7 +3296,7 @@ amd64_none_init_abi (gdbarch_info info, gdbarch *arch)
 static struct type *
 amd64_x32_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   switch (regnum - tdep->eax_regnum)
     {
@@ -3314,7 +3314,7 @@ void
 amd64_x32_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch,
 		    const target_desc *default_tdesc)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   amd64_init_abi (info, gdbarch, default_tdesc);
 
@@ -3384,7 +3384,7 @@ amd64_supply_fxsave (struct regcache *regcache, int regnum,
 		     const void *fxsave)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   i387_supply_fxsave (regcache, regnum, fxsave);
 
@@ -3407,7 +3407,7 @@ amd64_supply_xsave (struct regcache *regcache, int regnum,
 		    const void *xsave)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   i387_supply_xsave (regcache, regnum, xsave);
 
@@ -3442,7 +3442,7 @@ amd64_collect_fxsave (const struct regcache *regcache, int regnum,
 		      void *fxsave)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   gdb_byte *regs = (gdb_byte *) fxsave;
 
   i387_collect_fxsave (regcache, regnum, fxsave);
@@ -3463,7 +3463,7 @@ amd64_collect_xsave (const struct regcache *regcache, int regnum,
 		     void *xsave, int gcore)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   gdb_byte *regs = (gdb_byte *) xsave;
 
   i387_collect_xsave (regcache, regnum, xsave, gcore);
diff --git a/gdb/amd64-windows-tdep.c b/gdb/amd64-windows-tdep.c
index eca94f2ea7c..a9aef0bab88 100644
--- a/gdb/amd64-windows-tdep.c
+++ b/gdb/amd64-windows-tdep.c
@@ -1277,7 +1277,7 @@ amd64_windows_auto_wide_charset (void)
 static void
 amd64_windows_init_abi_common (gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* The dwarf2 unwinder (appended very early by i386_gdbarch_init) is
      preferred over the SEH one.  The reasons are:
diff --git a/gdb/arc-linux-tdep.c b/gdb/arc-linux-tdep.c
index 13595f2e8e9..9c1febcd900 100644
--- a/gdb/arc-linux-tdep.c
+++ b/gdb/arc-linux-tdep.c
@@ -411,7 +411,7 @@ static std::vector<CORE_ADDR>
 arc_linux_software_single_step (struct regcache *regcache)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
   struct disassemble_info di = arc_disassemble_info (gdbarch);
 
   /* Read current instruction.  */
@@ -693,7 +693,7 @@ arc_linux_core_read_description (struct gdbarch *gdbarch,
 static void
 arc_linux_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
 
   arc_linux_debug_printf ("GNU/Linux OS/ABI initialization.");
 
diff --git a/gdb/arc-newlib-tdep.c b/gdb/arc-newlib-tdep.c
index 7d7406c501c..2499dff43ec 100644
--- a/gdb/arc-newlib-tdep.c
+++ b/gdb/arc-newlib-tdep.c
@@ -36,7 +36,7 @@ arc_newlib_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
   arc_newlib_debug_printf ("Initialization.");
 
-  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
 
   /* Offset of original PC in longjmp jump buffer (in registers).  Value of PC
      offset can be found in newlib/libc/machine/arc/setjmp.S.  */
diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c
index 3edfd466f3b..b9c734210fe 100644
--- a/gdb/arc-tdep.c
+++ b/gdb/arc-tdep.c
@@ -1002,7 +1002,7 @@ arc_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
   arc_debug_printf ("called");
 
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
   int pc_offset = tdep->jb_pc * ARC_REGISTER_SIZE;
   gdb_byte buf[ARC_REGISTER_SIZE];
   CORE_ADDR jb_addr = get_frame_register_unsigned (frame, ARC_FIRST_ARG_REGNUM);
@@ -1827,7 +1827,7 @@ arc_make_sigtramp_frame_cache (struct frame_info *this_frame)
   arc_debug_printf ("called");
 
   gdbarch *arch = get_frame_arch (this_frame);
-  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (arch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (arch);
 
   /* Allocate new frame cache instance and space for saved register info.  */
   struct arc_frame_cache *cache = FRAME_OBSTACK_ZALLOC (struct arc_frame_cache);
@@ -1904,7 +1904,7 @@ arc_sigtramp_frame_sniffer (const struct frame_unwind *self,
   arc_debug_printf ("called");
 
   gdbarch *arch = get_frame_arch (this_frame);
-  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (arch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (arch);
 
   /* If we have a sigcontext_addr handler, then just return 1 (same as the
      "default_frame_sniffer ()").  */
@@ -2431,7 +2431,7 @@ arc_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 arc_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
 
   gdb_printf (file, "arc_dump_tdep: jb_pc = %i\n", tdep->jb_pc);
 
diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index ff946ee3767..360b8d694be 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -1198,11 +1198,13 @@ gdbarch_free (struct gdbarch *arch)
   xfree (obstack);
 }
 
+/* See gdbarch.h.  */
+
 struct gdbarch_tdep *
-gdbarch_tdep (struct gdbarch *gdbarch)
+gdbarch_tdep_1 (struct gdbarch *gdbarch)
 {
   if (gdbarch_debug >= 2)
-    gdb_printf (gdb_stdlog, "gdbarch_tdep called\n");
+    gdb_printf (gdb_stdlog, "gdbarch_tdep_1 called\n");
   return gdbarch->tdep;
 }
 
diff --git a/gdb/arm-fbsd-nat.c b/gdb/arm-fbsd-nat.c
index a306e1e2ee0..b161b7ed908 100644
--- a/gdb/arm-fbsd-nat.c
+++ b/gdb/arm-fbsd-nat.c
@@ -55,7 +55,7 @@ arm_fbsd_nat_target::fetch_registers (struct regcache *regcache, int regnum)
 #endif
 #ifdef PT_GETREGSET
   gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->tls_regnum > 0)
     {
@@ -90,7 +90,7 @@ arm_fbsd_nat_target::store_registers (struct regcache *regcache, int regnum)
 #endif
 #ifdef PT_GETREGSET
   gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->tls_regnum > 0)
     {
diff --git a/gdb/arm-fbsd-tdep.c b/gdb/arm-fbsd-tdep.c
index 483820c1092..61c8f0cecad 100644
--- a/gdb/arm-fbsd-tdep.c
+++ b/gdb/arm-fbsd-tdep.c
@@ -159,7 +159,7 @@ arm_fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				       void *cb_data,
 				       const struct regcache *regcache)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   cb (".reg", ARM_FBSD_SIZEOF_GREGSET, ARM_FBSD_SIZEOF_GREGSET,
       &arm_fbsd_gregset, NULL, cb_data);
@@ -233,7 +233,7 @@ static CORE_ADDR
 arm_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 				   CORE_ADDR lm_addr, CORE_ADDR offset)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   struct regcache *regcache;
 
   regcache = get_thread_arch_regcache (current_inferior ()->process_target (),
@@ -256,7 +256,7 @@ arm_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 static void
 arm_fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support.  */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/arm-linux-nat.c b/gdb/arm-linux-nat.c
index 8dac8456282..0188c78fe7a 100644
--- a/gdb/arm-linux-nat.c
+++ b/gdb/arm-linux-nat.c
@@ -339,7 +339,7 @@ fetch_vfp_regs (struct regcache *regcache)
   gdb_byte regbuf[ARM_VFP3_REGS_SIZE];
   int ret, tid;
   struct gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Get the thread id for the ptrace call.  */
   tid = regcache->ptid ().lwp ();
@@ -368,7 +368,7 @@ store_vfp_regs (const struct regcache *regcache)
   gdb_byte regbuf[ARM_VFP3_REGS_SIZE];
   int ret, tid;
   struct gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Get the thread id for the ptrace call.  */
   tid = regcache->ptid ().lwp ();
@@ -413,7 +413,7 @@ void
 arm_linux_nat_target::fetch_registers (struct regcache *regcache, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (-1 == regno)
     {
@@ -450,7 +450,7 @@ void
 arm_linux_nat_target::store_registers (struct regcache *regcache, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (-1 == regno)
     {
diff --git a/gdb/arm-linux-tdep.c b/gdb/arm-linux-tdep.c
index f299e9665d5..d530b7f59a8 100644
--- a/gdb/arm-linux-tdep.c
+++ b/gdb/arm-linux-tdep.c
@@ -712,7 +712,7 @@ arm_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					void *cb_data,
 					const struct regcache *regcache)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   cb (".reg", ARM_LINUX_SIZEOF_GREGSET, ARM_LINUX_SIZEOF_GREGSET,
       &arm_linux_gregset, NULL, cb_data);
@@ -1715,7 +1715,7 @@ arm_linux_init_abi (struct gdbarch_info info,
 								    NULL };
   static const char *const stap_register_indirection_suffixes[] = { "]",
 								    NULL };
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 1);
 
diff --git a/gdb/arm-netbsd-nat.c b/gdb/arm-netbsd-nat.c
index 764bbe8cd3d..251159154c9 100644
--- a/gdb/arm-netbsd-nat.c
+++ b/gdb/arm-netbsd-nat.c
@@ -50,7 +50,7 @@ static arm_netbsd_nat_target the_arm_netbsd_nat_target;
 static void
 arm_supply_vfpregset (struct regcache *regcache, struct fpreg *fpregset)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
   if (tdep->vfp_register_count == 0)
     return;
 
@@ -97,7 +97,7 @@ fetch_fp_register (struct regcache *regcache, int regno)
       return;
     }
 
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
   if (regno == ARM_FPSCR_REGNUM && tdep->vfp_register_count != 0)
     regcache->raw_supply (ARM_FPSCR_REGNUM, (char *) &vfp.vfp_fpscr);
   else if (regno >= ARM_D0_REGNUM
@@ -279,7 +279,7 @@ store_fp_register (const struct regcache *regcache, int regno)
       return;
     }
 
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
   if (regno == ARM_FPSCR_REGNUM && tdep->vfp_register_count != 0)
     regcache->raw_collect (ARM_FPSCR_REGNUM, (char *) &vfp.vfp_fpscr);
   else if (regno >= ARM_D0_REGNUM
@@ -301,7 +301,7 @@ store_fp_register (const struct regcache *regcache, int regno)
 static void
 store_fp_regs (const struct regcache *regcache)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
   int lwp = regcache->ptid ().lwp ();
   if (tdep->vfp_register_count == 0)
     return;
diff --git a/gdb/arm-netbsd-tdep.c b/gdb/arm-netbsd-tdep.c
index a6a78f0b893..aa4d15df4c6 100644
--- a/gdb/arm-netbsd-tdep.c
+++ b/gdb/arm-netbsd-tdep.c
@@ -111,7 +111,7 @@ static void
 arm_netbsd_init_abi_common (struct gdbarch_info info,
 			    struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   tdep->lowest_pc = 0x8000;
   switch (info.byte_order)
@@ -148,7 +148,7 @@ static void
 arm_netbsd_elf_init_abi (struct gdbarch_info info,
 			 struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   arm_netbsd_init_abi_common (info, gdbarch);
 
diff --git a/gdb/arm-none-tdep.c b/gdb/arm-none-tdep.c
index 510ce4fa3c5..0d5eb04826e 100644
--- a/gdb/arm-none-tdep.c
+++ b/gdb/arm-none-tdep.c
@@ -177,7 +177,7 @@ arm_none_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				       void *cb_data,
 				       const struct regcache *regcache)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   cb (".reg", ARM_NONE_SIZEOF_GREGSET, ARM_NONE_SIZEOF_GREGSET,
       &arm_none_gregset, nullptr, cb_data);
diff --git a/gdb/arm-obsd-tdep.c b/gdb/arm-obsd-tdep.c
index 37cb30b9a2a..634c76b7561 100644
--- a/gdb/arm-obsd-tdep.c
+++ b/gdb/arm-obsd-tdep.c
@@ -76,7 +76,7 @@ static void
 armobsd_init_abi (struct gdbarch_info info,
 		  struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->fp_model == ARM_FLOAT_AUTO)
     tdep->fp_model = ARM_FLOAT_SOFT_VFP;
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 46027afade4..7d85759eff2 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -338,7 +338,7 @@ static void
 arm_cache_init (struct arm_prologue_cache *cache, struct frame_info *frame)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   arm_cache_init (cache, gdbarch);
 
@@ -520,7 +520,7 @@ bool arm_unwind_secure_frames = true;
 int
 arm_psr_thumb_bit (struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->is_m)
     return XPSR_T;
@@ -632,7 +632,7 @@ arm_pc_is_thumb (struct gdbarch *gdbarch, CORE_ADDR memaddr)
   struct bound_minimal_symbol sym;
   char type;
   arm_displaced_step_copy_insn_closure *dsc = nullptr;
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (gdbarch_displaced_step_copy_insn_closure_by_addr_p (gdbarch))
     dsc = ((arm_displaced_step_copy_insn_closure * )
@@ -736,7 +736,7 @@ arm_pc_is_thumb (struct gdbarch *gdbarch, CORE_ADDR memaddr)
 static int
 arm_m_addr_is_magic (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   if (tdep->have_sec_ext)
     {
       switch ((addr & 0xff000000))
@@ -778,7 +778,7 @@ arm_m_addr_is_magic (struct gdbarch *gdbarch, CORE_ADDR addr)
 static CORE_ADDR
 arm_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR val)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* On M-profile devices, do not strip the low bit from EXC_RETURN
      (the magic exception return address).  */
@@ -1382,7 +1382,7 @@ thumb_analyze_prologue (struct gdbarch *gdbarch,
 	    }
 
 	  arm_gdbarch_tdep *tdep
-	    = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	    = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
 	  /* Make sure we are dealing with a target that supports ARMv8.1-m
 	     PACBTI.  */
@@ -1844,7 +1844,7 @@ arm_analyze_prologue (struct gdbarch *gdbarch,
   CORE_ADDR offset, current_pc;
   pv_t regs[ARM_FPS_REGNUM];
   CORE_ADDR unrecognized_pc = 0;
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Search the prologue looking for instructions that set up the
      frame pointer, adjust the stack pointer, and save registers.
@@ -2088,7 +2088,7 @@ arm_scan_prologue (struct frame_info *this_frame,
   CORE_ADDR prologue_start, prologue_end;
   CORE_ADDR prev_pc = get_frame_pc (this_frame);
   CORE_ADDR block_addr = get_frame_address_in_block (this_frame);
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Assume there is no frame until proven otherwise.  */
   cache->framereg = ARM_SP_REGNUM;
@@ -2193,7 +2193,7 @@ arm_make_prologue_cache (struct frame_info *this_frame)
     return cache;
 
   arm_gdbarch_tdep *tdep =
-    (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
 
   prev_sp = unwound_fp + cache->framesize;
   arm_cache_set_active_sp_value (cache, tdep, prev_sp);
@@ -2224,7 +2224,7 @@ arm_prologue_unwind_stop_reason (struct frame_info *this_frame,
   /* This is meant to halt the backtrace at "_start".  */
   pc = get_frame_pc (this_frame);
   gdbarch *arch = get_frame_arch (this_frame);
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (arch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (arch);
   if (pc <= tdep->lowest_pc)
     return UNWIND_OUTERMOST;
 
@@ -2252,7 +2252,7 @@ arm_prologue_this_id (struct frame_info *this_frame,
   cache = (struct arm_prologue_cache *) *this_cache;
 
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
 
   /* Use function start address as part of the frame ID.  If we cannot
      identify the start address (due to missing symbol information),
@@ -2279,7 +2279,7 @@ arm_prologue_prev_register (struct frame_info *this_frame,
     *this_cache = arm_make_prologue_cache (this_frame);
   cache = (struct arm_prologue_cache *) *this_cache;
 
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* If this frame has signed the return address, mark it as so.  */
   if (tdep->have_pacbti && cache->ra_signed_state.has_value ()
@@ -2952,7 +2952,7 @@ arm_exidx_fill_cache (struct frame_info *this_frame, gdb_byte *entry)
 
   /* We already got the previous SP.  */
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   arm_cache_set_active_sp_value (cache, tdep, vsp);
 
   return cache;
@@ -3077,7 +3077,7 @@ arm_make_epilogue_frame_cache (struct frame_info *this_frame)
 
   /* Since we are in epilogue, the SP has been restored.  */
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   arm_cache_set_active_sp_value (cache, tdep,
 				 get_frame_register_unsigned (this_frame,
 							      ARM_SP_REGNUM));
@@ -3116,7 +3116,7 @@ arm_epilogue_frame_this_id (struct frame_info *this_frame,
     func = pc;
 
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   *this_id = frame_id_build (arm_cache_get_prev_sp_value (cache, tdep), pc);
 }
 
@@ -3240,7 +3240,7 @@ arm_make_stub_cache (struct frame_info *this_frame)
   arm_cache_init (cache, this_frame);
 
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   arm_cache_set_active_sp_value (cache, tdep,
 				 get_frame_register_unsigned (this_frame,
 							      ARM_SP_REGNUM));
@@ -3262,7 +3262,7 @@ arm_stub_this_id (struct frame_info *this_frame,
   cache = (struct arm_prologue_cache *) *this_cache;
 
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   *this_id = frame_id_build (arm_cache_get_prev_sp_value (cache, tdep),
 			     get_frame_pc (this_frame));
 }
@@ -3310,7 +3310,7 @@ static struct arm_prologue_cache *
 arm_m_exception_cache (struct frame_info *this_frame)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct arm_prologue_cache *cache;
   CORE_ADDR lr;
@@ -3597,7 +3597,7 @@ arm_m_exception_this_id (struct frame_info *this_frame,
 
   /* Our frame ID for a stub frame is the current SP and LR.  */
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   *this_id = frame_id_build (arm_cache_get_prev_sp_value (cache, tdep),
 			     get_frame_pc (this_frame));
 }
@@ -3619,7 +3619,7 @@ arm_m_exception_prev_register (struct frame_info *this_frame,
 
   /* The value was already reconstructed into PREV_SP.  */
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   if (prev_regnum == ARM_SP_REGNUM)
     return frame_unwind_got_constant (this_frame, prev_regnum,
 				      arm_cache_get_prev_sp_value (cache, tdep));
@@ -3677,7 +3677,7 @@ arm_normal_frame_base (struct frame_info *this_frame, void **this_cache)
   cache = (struct arm_prologue_cache *) *this_cache;
 
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   return arm_cache_get_prev_sp_value (cache, tdep) - cache->framesize;
 }
 
@@ -3693,7 +3693,7 @@ arm_dwarf2_prev_register (struct frame_info *this_frame, void **this_cache,
 			  int regnum)
 {
   struct gdbarch * gdbarch = get_frame_arch (this_frame);
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   CORE_ADDR lr, cpsr;
   ULONGEST t_bit = arm_psr_thumb_bit (gdbarch);
 
@@ -4220,7 +4220,7 @@ arm_vfp_call_candidate (struct type *t, enum arm_vfp_cprc_base_type *base_type,
 static int
 arm_vfp_abi_for_function (struct gdbarch *gdbarch, struct type *func_type)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Variadic functions always use the base ABI.  Assume that functions
      without debug info are not variadic.  */
@@ -4254,7 +4254,7 @@ arm_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   int use_vfp_abi;
   struct type *ftype;
   unsigned vfp_regs_free = (1 << 16) - 1;
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Determine the type of this function and whether the VFP ABI
      applies.  */
@@ -4526,7 +4526,7 @@ arm_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
 static struct type *
 arm_ext_type (struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (!tdep->arm_ext_type)
     tdep->arm_ext_type
@@ -4539,7 +4539,7 @@ arm_ext_type (struct gdbarch *gdbarch)
 static struct type *
 arm_neon_double_type (struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->neon_double_type == NULL)
     {
@@ -4578,7 +4578,7 @@ arm_neon_double_type (struct gdbarch *gdbarch)
 static struct type *
 arm_neon_quad_type (struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->neon_quad_type == NULL)
     {
@@ -4616,7 +4616,7 @@ arm_neon_quad_type (struct gdbarch *gdbarch)
 static bool
 is_q_pseudo (struct gdbarch *gdbarch, int regnum)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Q pseudo registers are available for both NEON (Q0~Q15) and
      MVE (Q0~Q7) features.  */
@@ -4637,7 +4637,7 @@ is_q_pseudo (struct gdbarch *gdbarch, int regnum)
 static bool
 is_s_pseudo (struct gdbarch *gdbarch, int regnum)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->have_s_pseudos
       && regnum >= tdep->s_pseudo_base
@@ -4656,7 +4656,7 @@ is_s_pseudo (struct gdbarch *gdbarch, int regnum)
 static bool
 is_mve_pseudo (struct gdbarch *gdbarch, int regnum)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->have_mve
       && regnum >= tdep->mve_pseudo_base
@@ -4675,7 +4675,7 @@ is_mve_pseudo (struct gdbarch *gdbarch, int regnum)
 static bool
 is_pacbti_pseudo (struct gdbarch *gdbarch, int regnum)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->have_pacbti
       && regnum >= tdep->pacbti_pseudo_base
@@ -4691,7 +4691,7 @@ is_pacbti_pseudo (struct gdbarch *gdbarch, int regnum)
 static struct type *
 arm_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (is_s_pseudo (gdbarch, regnum))
     return builtin_type (gdbarch)->builtin_float;
@@ -4770,7 +4770,7 @@ arm_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
   /* PACBTI register containing the Pointer Authentication Code.  */
   if (reg == ARM_DWARF_RA_AUTH_CODE)
     {
-      arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
       if (tdep->have_pacbti)
 	return tdep->pacbti_pseudo_base;
@@ -4916,7 +4916,7 @@ arm_adjust_breakpoint_address (struct gdbarch *gdbarch, CORE_ADDR bpaddr)
   int buf_len;
   enum bfd_endian order = gdbarch_byte_order_for_code (gdbarch);
   int i, any, last_it, last_it_count;
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* If we are using BKPT breakpoints, none of this is necessary.  */
   if (tdep->thumb2_breakpoint == NULL)
@@ -8224,7 +8224,7 @@ arm_displaced_init_closure (struct gdbarch *gdbarch, CORE_ADDR from,
 			    CORE_ADDR to,
 			    arm_displaced_step_copy_insn_closure *dsc)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   unsigned int i, len, offset;
   enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
   int size = dsc->is_thumb? 2 : 4;
@@ -8387,7 +8387,7 @@ static const gdb_byte arm_default_thumb_be_breakpoint[] = THUMB_BE_BREAKPOINT;
 static int
 arm_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
 
   if (arm_pc_is_thumb (gdbarch, *pcptr))
@@ -8422,7 +8422,7 @@ arm_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 static const gdb_byte *
 arm_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   switch (kind)
     {
@@ -8494,7 +8494,7 @@ arm_extract_return_value (struct type *type, struct regcache *regs,
 {
   struct gdbarch *gdbarch = regs->arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (TYPE_CODE_FLT == type->code ())
     {
@@ -8605,7 +8605,7 @@ arm_return_in_memory (struct gdbarch *gdbarch, struct type *type)
       return (TYPE_LENGTH (type) > 16);
     }
 
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   if (tdep->arm_abi != ARM_ABI_APCS)
     {
       /* The AAPCS says all aggregates not larger than a word are returned
@@ -8711,7 +8711,7 @@ arm_store_return_value (struct type *type, struct regcache *regs,
   if (type->code () == TYPE_CODE_FLT)
     {
       gdb_byte buf[ARM_FP_REGISTER_SIZE];
-      arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
       switch (tdep->fp_model)
 	{
@@ -8800,7 +8800,7 @@ arm_return_value (struct gdbarch *gdbarch, struct value *function,
 		  struct type *valtype, struct regcache *regcache,
 		  gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   struct type *func_type = function ? value_type (function) : NULL;
   enum arm_vfp_cprc_base_type vfp_base_type;
   int vfp_base_count;
@@ -8892,7 +8892,7 @@ static int
 arm_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR jb_addr;
   gdb_byte buf[ARM_INT_REGISTER_SIZE];
@@ -9085,7 +9085,7 @@ show_fp_model (struct ui_file *file, int from_tty,
       && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm)
     {
       arm_gdbarch_tdep *tdep
-	= (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+	= gdbarch_tdep<arm_gdbarch_tdep> (target_gdbarch ());
 
       gdb_printf (file, _("\
 The current ARM floating point model is \"auto\" (currently \"%s\").\n"),
@@ -9125,7 +9125,7 @@ arm_show_abi (struct ui_file *file, int from_tty,
       && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm)
     {
       arm_gdbarch_tdep *tdep
-	= (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+	= gdbarch_tdep<arm_gdbarch_tdep> (target_gdbarch ());
 
       gdb_printf (file, _("\
 The current ARM ABI is \"auto\" (currently \"%s\").\n"),
@@ -9204,7 +9204,7 @@ show_disassembly_style_sfunc (struct ui_file *file, int from_tty,
 static const char *
 arm_register_name (struct gdbarch *gdbarch, int i)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (is_s_pseudo (gdbarch, i))
     {
@@ -9375,7 +9375,7 @@ static enum register_status
 arm_mve_pseudo_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 		     int regnum, gdb_byte *buf)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* P0 is the first 16 bits of VPR.  */
   return regcache->raw_read_part (tdep->mve_vpr_regnum, 0, 2, buf);
@@ -9389,7 +9389,7 @@ arm_pseudo_read (struct gdbarch *gdbarch, readable_regcache *regcache,
   char name_buf[4];
   gdb_byte reg_buf[8];
   int offset, double_regnum;
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   gdb_assert (regnum >= num_regs);
 
@@ -9461,7 +9461,7 @@ static void
 arm_mve_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache,
 		      int regnum, const gdb_byte *buf)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* P0 is the first 16 bits of VPR.  */
   regcache->raw_write_part (tdep->mve_vpr_regnum, 0, 2, buf);
@@ -9475,7 +9475,7 @@ arm_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache,
   char name_buf[4];
   gdb_byte reg_buf[8];
   int offset, double_regnum;
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   gdb_assert (regnum >= num_regs);
 
@@ -9563,7 +9563,7 @@ arm_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 static void
 arm_register_g_packet_guesses (struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->is_m)
     {
@@ -9606,7 +9606,7 @@ arm_register_g_packet_guesses (struct gdbarch *gdbarch)
 static int
 arm_code_of_frame_writable (struct gdbarch *gdbarch, struct frame_info *frame)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->is_m && get_frame_type (frame) == SIGTRAMP_FRAME)
     {
@@ -10165,7 +10165,7 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
     {
       arm_gdbarch_tdep *tdep
-	= (arm_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
+	= gdbarch_tdep<arm_gdbarch_tdep> (best_arch->gdbarch);
 
       if (arm_abi != ARM_ABI_AUTO && arm_abi != tdep->arm_abi)
 	continue;
@@ -10485,7 +10485,7 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 arm_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep == NULL)
     return;
@@ -12694,7 +12694,7 @@ arm_record_coproc_data_proc (arm_insn_decode_record *arm_insn_r)
 {
   uint32_t op, op1_ebit, coproc, bits_24_25;
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (arm_insn_r->gdbarch);
+    = gdbarch_tdep<arm_gdbarch_tdep> (arm_insn_r->gdbarch);
   struct regcache *reg_cache = arm_insn_r->regcache;
 
   arm_insn_r->opcode = bits (arm_insn_r->arm_insn, 24, 27);
@@ -13182,7 +13182,7 @@ static int
 thumb_record_ldm_stm_swi (arm_insn_decode_record *thumb_insn_r)
 {
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep  (thumb_insn_r->gdbarch);
+    = gdbarch_tdep<arm_gdbarch_tdep>  (thumb_insn_r->gdbarch);
   struct regcache *reg_cache = thumb_insn_r->regcache;
 
   uint32_t ret = 0; /* function return value: -1:record failure ;  0:success  */
diff --git a/gdb/arm-wince-tdep.c b/gdb/arm-wince-tdep.c
index 354c6fbca7f..5063b308809 100644
--- a/gdb/arm-wince-tdep.c
+++ b/gdb/arm-wince-tdep.c
@@ -115,7 +115,7 @@ arm_wince_skip_main_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
 static void
 arm_wince_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   windows_init_abi (info, gdbarch);
 
diff --git a/gdb/avr-tdep.c b/gdb/avr-tdep.c
index e103045cb23..4722f7ee748 100644
--- a/gdb/avr-tdep.c
+++ b/gdb/avr-tdep.c
@@ -232,7 +232,7 @@ avr_register_type (struct gdbarch *gdbarch, int reg_nr)
   if (reg_nr == AVR_PC_REGNUM)
     return builtin_type (gdbarch)->builtin_uint32;
 
-  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
   if (reg_nr == AVR_PSEUDO_PC_REGNUM)
     return tdep->pc_type;
 
@@ -750,7 +750,7 @@ avr_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR pc_beg, CORE_ADDR pc_end,
   gdb_assert (vpc < AVR_MAX_PROLOGUE_SIZE);
 
   /* Handle static small stack allocation using rcall or push.  */
-  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
   while (scan_stage == 1 && vpc < len)
     {
       insn = extract_unsigned_integer (&prologue[vpc], 2, byte_order);
@@ -1053,7 +1053,7 @@ avr_frame_unwind_cache (struct frame_info *this_frame,
 
   /* The previous frame's SP needed to be computed.  Save the computed
      value.  */
-  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
   info->saved_regs[AVR_SP_REGNUM].set_value (info->prev_sp
 					     - 1 + tdep->call_length);
 
@@ -1135,7 +1135,7 @@ avr_frame_prev_register (struct frame_info *this_frame,
 	  int i;
 	  gdb_byte buf[3];
 	  struct gdbarch *gdbarch = get_frame_arch (this_frame);
-	  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
 
 	  read_memory (info->saved_regs[AVR_PC_REGNUM].addr (),
 		       buf, tdep->call_length);
@@ -1277,7 +1277,7 @@ avr_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 {
   int i;
   gdb_byte buf[3];
-  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
   int call_length = tdep->call_length;
   CORE_ADDR return_pc = avr_convert_iaddr_to_raw (bp_addr);
   int regnum = AVR_ARGN_REGNUM;
@@ -1461,7 +1461,7 @@ avr_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
     {
       avr_gdbarch_tdep *tdep
-	= (avr_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
+	= gdbarch_tdep<avr_gdbarch_tdep> (best_arch->gdbarch);
 
       if (tdep->call_length == call_length)
 	return best_arch->gdbarch;
diff --git a/gdb/bfin-tdep.c b/gdb/bfin-tdep.c
index 573eed94793..f232e22c37c 100644
--- a/gdb/bfin-tdep.c
+++ b/gdb/bfin-tdep.c
@@ -766,7 +766,7 @@ bfin_frame_align (struct gdbarch *gdbarch, CORE_ADDR address)
 enum bfin_abi
 bfin_abi (struct gdbarch *gdbarch)
 {
-  bfin_gdbarch_tdep *tdep = (bfin_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  bfin_gdbarch_tdep *tdep = gdbarch_tdep<bfin_gdbarch_tdep> (gdbarch);
   return tdep->bfin_abi;
 }
 
@@ -792,7 +792,7 @@ bfin_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       bfin_gdbarch_tdep *tdep
-	= (bfin_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<bfin_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->bfin_abi != abi)
 	continue;
diff --git a/gdb/cris-linux-tdep.c b/gdb/cris-linux-tdep.c
index f55f9b9083c..b3ed7450e99 100644
--- a/gdb/cris-linux-tdep.c
+++ b/gdb/cris-linux-tdep.c
@@ -33,7 +33,7 @@
 static void
 cris_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/cris-tdep.c b/gdb/cris-tdep.c
index efd728a5229..73110d97f2f 100644
--- a/gdb/cris-tdep.c
+++ b/gdb/cris-tdep.c
@@ -313,7 +313,7 @@ cris_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
 				  void **this_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct cris_unwind_cache *info;
   CORE_ADDR addr;
@@ -450,7 +450,7 @@ static int
 crisv32_single_step_through_delay (struct gdbarch *gdbarch,
 				   struct frame_info *this_frame)
 {
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   ULONGEST erp;
   int ret = 0;
 
@@ -696,7 +696,7 @@ cris_frame_unwind_cache (struct frame_info *this_frame,
 			 void **this_prologue_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   struct cris_unwind_cache *info;
 
   if ((*this_prologue_cache))
@@ -1334,7 +1334,7 @@ crisv32_scan_prologue (CORE_ADDR pc, struct frame_info *this_frame,
 static CORE_ADDR
 cris_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   CORE_ADDR func_addr, func_end;
   struct symtab_and_line sal;
   CORE_ADDR pc_after_prologue;
@@ -1369,7 +1369,7 @@ cris_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 static const gdb_byte *
 cris_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   static unsigned char break8_insn[] = {0x38, 0xe9};
   static unsigned char break15_insn[] = {0x3f, 0xe9};
 
@@ -1388,7 +1388,7 @@ static int
 cris_spec_reg_applicable (struct gdbarch *gdbarch,
 			  struct cris_spec_reg spec_reg)
 {
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   unsigned int version = tdep->cris_version;
   
   switch (spec_reg.applicable_version)
@@ -3767,7 +3767,7 @@ cris_supply_gregset (const struct regset *regset, struct regcache *regcache,
 		     int regnum, const void *gregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   int i;
   const cris_elf_greg_t *regp = static_cast<const cris_elf_greg_t *>(gregs);
 
@@ -3861,7 +3861,7 @@ Makes GDB use the NRP register instead of the ERP register in certain cases."),
 static void
 cris_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   if (tdep != NULL)
     {
       gdb_printf (file, "cris_dump_tdep: tdep->cris_version = %i\n",
@@ -3941,7 +3941,7 @@ cris_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       cris_gdbarch_tdep *tdep
-	= (cris_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<cris_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->cris_version == usr_cmd_cris_version
 	  && tdep->cris_mode == usr_cmd_cris_mode
diff --git a/gdb/csky-tdep.c b/gdb/csky-tdep.c
index 3b4db049d96..c9450802b32 100644
--- a/gdb/csky-tdep.c
+++ b/gdb/csky-tdep.c
@@ -2181,7 +2181,7 @@ csky_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       csky_gdbarch_tdep *tdep
-        = (csky_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<csky_gdbarch_tdep> (arches->gdbarch);
       if (fpu_abi != tdep->fpu_abi)
         continue;
       if (vdsp_version != tdep->vdsp_version)
diff --git a/gdb/frv-tdep.c b/gdb/frv-tdep.c
index 2328791a540..34f437764a9 100644
--- a/gdb/frv-tdep.c
+++ b/gdb/frv-tdep.c
@@ -93,7 +93,7 @@ struct frv_gdbarch_tdep : gdbarch_tdep
 enum frv_abi
 frv_abi (struct gdbarch *gdbarch)
 {
-  frv_gdbarch_tdep *tdep = (frv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  frv_gdbarch_tdep *tdep = gdbarch_tdep<frv_gdbarch_tdep> (gdbarch);
   return tdep->frv_abi;
 }
 
@@ -275,7 +275,7 @@ frv_register_name (struct gdbarch *gdbarch, int reg)
   if (reg >= frv_num_regs + frv_num_pseudo_regs)
     return "?toolarge?";
 
-  frv_gdbarch_tdep *tdep = (frv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  frv_gdbarch_tdep *tdep = gdbarch_tdep<frv_gdbarch_tdep> (gdbarch);
   return tdep->register_names[reg];
 }
 
diff --git a/gdb/ft32-tdep.c b/gdb/ft32-tdep.c
index f77e313e0dd..024ca47ce4d 100644
--- a/gdb/ft32-tdep.c
+++ b/gdb/ft32-tdep.c
@@ -110,7 +110,7 @@ ft32_register_type (struct gdbarch *gdbarch, int reg_nr)
 {
   if (reg_nr == FT32_PC_REGNUM)
     {
-      ft32_gdbarch_tdep *tdep = (ft32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      ft32_gdbarch_tdep *tdep = gdbarch_tdep<ft32_gdbarch_tdep> (gdbarch);
       return tdep->pc_type;
     }
   else if (reg_nr == FT32_SP_REGNUM || reg_nr == FT32_FP_REGNUM)
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index 3a7b7f92ef7..b2c91db0c4f 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -142,8 +142,23 @@ using read_core_file_mappings_loop_ftype =
 
 #include "gdbarch-gen.h"
 
-extern struct gdbarch_tdep *gdbarch_tdep (struct gdbarch *gdbarch);
+/* An internal function that should _only_ be called from gdbarch_tdep.
+   Returns the gdbarch_tdep field held within GDBARCH.  */
 
+extern struct gdbarch_tdep *gdbarch_tdep_1 (struct gdbarch *gdbarch);
+
+/* Return the gdbarch_tdep object held within GDBARCH cast to the type
+   TDepType, which should be a sub-class of gdbarch_tdep.  There is no
+   checking done that the gdbarch_tdep within GDBARCH actually is of the
+   type TDepType, we just assume the caller knows what they are doing.  */
+
+template<typename TDepType>
+static inline TDepType *
+gdbarch_tdep (struct gdbarch *gdbarch)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep_1 (gdbarch);
+  return static_cast<TDepType *> (tdep);
+}
 
 /* Mechanism for co-ordinating the selection of a specific
    architecture.
diff --git a/gdb/hppa-bsd-tdep.c b/gdb/hppa-bsd-tdep.c
index 34f57d2512a..c405511529d 100644
--- a/gdb/hppa-bsd-tdep.c
+++ b/gdb/hppa-bsd-tdep.c
@@ -118,7 +118,7 @@ hppabsd_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
 void
 hppabsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
 
   /* OpenBSD and NetBSD have a 64-bit 'long double'.  */
   set_gdbarch_long_double_bit (gdbarch, 64);
diff --git a/gdb/hppa-linux-tdep.c b/gdb/hppa-linux-tdep.c
index 40e32c115d2..f17d2ae6b02 100644
--- a/gdb/hppa-linux-tdep.c
+++ b/gdb/hppa-linux-tdep.c
@@ -476,7 +476,7 @@ hppa_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					 void *cb_data,
 					 const struct regcache *regcache)
 {
-  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
 
   cb (".reg", 80 * tdep->bytes_per_address, 80 * tdep->bytes_per_address,
       &hppa_linux_regset, NULL, cb_data);
@@ -486,7 +486,7 @@ hppa_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 static void
 hppa_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/hppa-tdep.c b/gdb/hppa-tdep.c
index f9ececbb04f..9f93a945a6a 100644
--- a/gdb/hppa-tdep.c
+++ b/gdb/hppa-tdep.c
@@ -247,7 +247,7 @@ internalize_unwinds (struct objfile *objfile, struct unwind_table_entry *table,
   if (size > 0)
     {
       struct gdbarch *gdbarch = objfile->arch ();
-      hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
       unsigned long tmp;
       unsigned i;
       char *buf = (char *) alloca (size);
@@ -718,7 +718,7 @@ hppa32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   /* Global pointer (r19) of the function we are trying to call.  */
   CORE_ADDR gp;
 
-  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
 
   for (write_pass = 0; write_pass < 2; write_pass++)
     {
@@ -955,7 +955,7 @@ hppa64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 			function_call_return_method return_method,
 			CORE_ADDR struct_addr)
 {
-  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int i, offset = 0;
   CORE_ADDR gp;
@@ -2241,7 +2241,7 @@ hppa_frame_cache (struct frame_info *this_frame, void **this_cache)
   }
 
   {
-    hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+    hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
 
     if (tdep->unwind_adjust_stub)
       tdep->unwind_adjust_stub (this_frame, cache->base, cache->saved_regs);
@@ -2471,7 +2471,7 @@ hppa_stub_unwind_sniffer (const struct frame_unwind *self,
 {
   CORE_ADDR pc = get_frame_address_in_block (this_frame);
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
 
   if (pc == 0
       || (tdep->in_solib_call_trampoline != NULL
@@ -3147,7 +3147,7 @@ hppa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 hppa_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
 
   gdb_printf (file, "bytes_per_address = %d\n", 
 	      tdep->bytes_per_address);
diff --git a/gdb/i386-bsd-tdep.c b/gdb/i386-bsd-tdep.c
index b38f8d05887..dbbd3c786c3 100644
--- a/gdb/i386-bsd-tdep.c
+++ b/gdb/i386-bsd-tdep.c
@@ -74,7 +74,7 @@ int i386bsd_sc_reg_offset[] =
 void
 i386bsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   tdep->jb_pc_offset = 0;
 
diff --git a/gdb/i386-darwin-tdep.c b/gdb/i386-darwin-tdep.c
index dc780583766..2a9198aceb3 100644
--- a/gdb/i386-darwin-tdep.c
+++ b/gdb/i386-darwin-tdep.c
@@ -156,7 +156,7 @@ i386_darwin_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 			     function_call_return_method return_method,
 			     CORE_ADDR struct_addr)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   gdb_byte buf[4];
   int i;
@@ -248,7 +248,7 @@ i386_darwin_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 static void
 i386_darwin_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* We support the SSE registers.  */
   tdep->num_xmm_regs = I386_NUM_XREGS - 1;
diff --git a/gdb/i386-fbsd-tdep.c b/gdb/i386-fbsd-tdep.c
index d68498cd5e9..b7a524db68c 100644
--- a/gdb/i386-fbsd-tdep.c
+++ b/gdb/i386-fbsd-tdep.c
@@ -325,7 +325,7 @@ i386fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				       void *cb_data,
 				       const struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   cb (".reg", I386_FBSD_SIZEOF_GREGSET, I386_FBSD_SIZEOF_GREGSET,
       &i386_fbsd_gregset, NULL, cb_data);
@@ -365,7 +365,7 @@ i386fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 static void
 i386fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support. */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/i386-gnu-tdep.c b/gdb/i386-gnu-tdep.c
index 51c253d2dfe..3d97fe36a85 100644
--- a/gdb/i386-gnu-tdep.c
+++ b/gdb/i386-gnu-tdep.c
@@ -173,7 +173,7 @@ static int i386gnu_gregset_reg_offset[] =
 static void
 i386gnu_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* GNU uses ELF.  */
   i386_elf_init_abi (info, gdbarch);
diff --git a/gdb/i386-go32-tdep.c b/gdb/i386-go32-tdep.c
index 15ac38dc12f..0c0c08e3579 100644
--- a/gdb/i386-go32-tdep.c
+++ b/gdb/i386-go32-tdep.c
@@ -26,7 +26,7 @@
 static void
 i386_go32_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* DJGPP doesn't have any special frames for signal handlers.  */
   tdep->sigtramp_p = NULL;
diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c
index 5d7f54194af..6033104230f 100644
--- a/gdb/i386-linux-tdep.c
+++ b/gdb/i386-linux-tdep.c
@@ -763,7 +763,7 @@ i386_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					 void *cb_data,
 					 const struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   cb (".reg", 68, 68, &i386_gregset, NULL, cb_data);
 
@@ -825,7 +825,7 @@ i386_linux_displaced_step_copy_insn (struct gdbarch *gdbarch,
 static void
 i386_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   const struct target_desc *tdesc = info.target_desc;
   struct tdesc_arch_data *tdesc_data = info.tdesc_data;
   const struct tdesc_feature *feature;
diff --git a/gdb/i386-netbsd-tdep.c b/gdb/i386-netbsd-tdep.c
index 2cee1b94760..a9ebc3dd827 100644
--- a/gdb/i386-netbsd-tdep.c
+++ b/gdb/i386-netbsd-tdep.c
@@ -372,7 +372,7 @@ i386nbsd_sigtramp_cache_init (const struct tramp_frame *self,
 static void 
 i386nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* Obviously NetBSD is BSD-based.  */
   i386bsd_init_abi (info, gdbarch);
@@ -407,7 +407,7 @@ i386nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 static void
 i386nbsdelf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* It's still NetBSD.  */
   i386nbsd_init_abi (info, gdbarch);
diff --git a/gdb/i386-nto-tdep.c b/gdb/i386-nto-tdep.c
index 6716329149b..259867f262b 100644
--- a/gdb/i386-nto-tdep.c
+++ b/gdb/i386-nto-tdep.c
@@ -77,7 +77,7 @@ static void
 i386nto_supply_gregset (struct regcache *regcache, char *gpregs)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   gdb_assert (tdep->gregset_reg_offset == i386nto_gregset_reg_offset);
   i386_gregset.supply_regset (&i386_gregset, regcache, -1,
@@ -126,7 +126,7 @@ static int
 i386nto_register_area (struct gdbarch *gdbarch,
 		       int regno, int regset, unsigned *off)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   *off = 0;
   if (regset == NTO_REG_GENERAL)
@@ -315,7 +315,7 @@ init_i386nto_ops (void)
 static void
 i386nto_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   static struct target_so_ops nto_svr4_so_ops;
 
   /* Deal with our strange signals.  */
diff --git a/gdb/i386-obsd-tdep.c b/gdb/i386-obsd-tdep.c
index b1f4d6c5e8d..798094509c6 100644
--- a/gdb/i386-obsd-tdep.c
+++ b/gdb/i386-obsd-tdep.c
@@ -407,7 +407,7 @@ static const struct frame_unwind i386obsd_trapframe_unwind = {
 static void 
 i386obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* Obviously OpenBSD is BSD-based.  */
   i386bsd_init_abi (info, gdbarch);
diff --git a/gdb/i386-sol2-tdep.c b/gdb/i386-sol2-tdep.c
index e8a3ba20045..5ee108d3578 100644
--- a/gdb/i386-sol2-tdep.c
+++ b/gdb/i386-sol2-tdep.c
@@ -65,7 +65,7 @@ i386_sol2_mcontext_addr (struct frame_info *this_frame)
 static void
 i386_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* Solaris is SVR4-based.  */
   i386_svr4_init_abi (info, gdbarch);
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 8501e12e241..d500f6998c5 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -169,7 +169,7 @@ const int num_lower_zmm_regs = 16;
 static int
 i386_mmx_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int mm0_regnum = tdep->mm0_regnum;
 
   if (mm0_regnum < 0)
@@ -184,7 +184,7 @@ i386_mmx_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_byte_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   regnum -= tdep->al_regnum;
   return regnum >= 0 && regnum < tdep->num_byte_regs;
@@ -195,7 +195,7 @@ i386_byte_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_word_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   regnum -= tdep->ax_regnum;
   return regnum >= 0 && regnum < tdep->num_word_regs;
@@ -206,7 +206,7 @@ i386_word_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_dword_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int eax_regnum = tdep->eax_regnum;
 
   if (eax_regnum < 0)
@@ -221,7 +221,7 @@ i386_dword_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_zmmh_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int zmm0h_regnum = tdep->zmm0h_regnum;
 
   if (zmm0h_regnum < 0)
@@ -234,7 +234,7 @@ i386_zmmh_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_zmm_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int zmm0_regnum = tdep->zmm0_regnum;
 
   if (zmm0_regnum < 0)
@@ -247,7 +247,7 @@ i386_zmm_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_k_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int k0_regnum = tdep->k0_regnum;
 
   if (k0_regnum < 0)
@@ -260,7 +260,7 @@ i386_k_regnum_p (struct gdbarch *gdbarch, int regnum)
 static int
 i386_ymmh_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int ymm0h_regnum = tdep->ymm0h_regnum;
 
   if (ymm0h_regnum < 0)
@@ -275,7 +275,7 @@ i386_ymmh_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_ymm_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int ymm0_regnum = tdep->ymm0_regnum;
 
   if (ymm0_regnum < 0)
@@ -288,7 +288,7 @@ i386_ymm_regnum_p (struct gdbarch *gdbarch, int regnum)
 static int
 i386_ymmh_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int ymm16h_regnum = tdep->ymm16h_regnum;
 
   if (ymm16h_regnum < 0)
@@ -301,7 +301,7 @@ i386_ymmh_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_ymm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int ymm16_regnum = tdep->ymm16_regnum;
 
   if (ymm16_regnum < 0)
@@ -316,7 +316,7 @@ i386_ymm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_bnd_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int bnd0_regnum = tdep->bnd0_regnum;
 
   if (bnd0_regnum < 0)
@@ -331,7 +331,7 @@ i386_bnd_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_xmm_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int num_xmm_regs = I387_NUM_XMM_REGS (tdep);
 
   if (num_xmm_regs == 0)
@@ -346,7 +346,7 @@ i386_xmm_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_xmm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int num_xmm_avx512_regs = I387_NUM_XMM_AVX512_REGS (tdep);
 
   if (num_xmm_avx512_regs == 0)
@@ -359,7 +359,7 @@ i386_xmm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 static int
 i386_mxcsr_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (I387_NUM_XMM_REGS (tdep) == 0)
     return 0;
@@ -372,7 +372,7 @@ i386_mxcsr_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_fp_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (I387_ST0_REGNUM (tdep) < 0)
     return 0;
@@ -384,7 +384,7 @@ i386_fp_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_fpc_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (I387_ST0_REGNUM (tdep) < 0)
     return 0;
@@ -398,7 +398,7 @@ i386_fpc_regnum_p (struct gdbarch *gdbarch, int regnum)
 static int
 i386_bndr_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
    if (I387_BND0R_REGNUM (tdep) < 0)
      return 0;
@@ -412,7 +412,7 @@ i386_bndr_regnum_p (struct gdbarch *gdbarch, int regnum)
 static int
 i386_mpx_ctrl_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
    if (I387_BNDCFGU_REGNUM (tdep) < 0)
      return 0;
@@ -426,7 +426,7 @@ i386_mpx_ctrl_regnum_p (struct gdbarch *gdbarch, int regnum)
 bool
 i386_pkru_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int pkru_regnum = tdep->pkru_regnum;
 
   if (pkru_regnum < 0)
@@ -462,7 +462,7 @@ i386_register_name (struct gdbarch *gdbarch, int regnum)
 const char *
 i386_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   if (i386_bnd_regnum_p (gdbarch, regnum))
     return i386_bnd_names[regnum - tdep->bnd0_regnum];
   if (i386_mmx_regnum_p (gdbarch, regnum))
@@ -485,7 +485,7 @@ i386_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 static int
 i386_dbx_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* This implements what GCC calls the "default" register map
      (dbx_register_map[]).  */
@@ -532,7 +532,7 @@ i386_dbx_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 static int
 i386_svr4_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* This implements the GCC register map that tries to be compatible
      with the SVR4 C compiler for DWARF (svr4_dbx_register_map[]).  */
@@ -2434,7 +2434,7 @@ static struct i386_frame_cache *
 i386_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct i386_frame_cache *cache;
   CORE_ADDR addr;
@@ -2524,7 +2524,7 @@ i386_sigtramp_frame_sniffer (const struct frame_unwind *self,
 			     void **this_prologue_cache)
 {
   gdbarch *arch = get_frame_arch (this_frame);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
 
   /* We shouldn't even bother if we don't have a sigcontext_addr
      handler.  */
@@ -2611,7 +2611,7 @@ i386_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
   CORE_ADDR sp, jb_addr;
   struct gdbarch *gdbarch = get_frame_arch (frame);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int jb_pc_offset = tdep->jb_pc_offset;
 
   /* If JB_PC_OFFSET is -1, we have no way to find out where the
@@ -2860,7 +2860,7 @@ static void
 i386_extract_return_value (struct gdbarch *gdbarch, struct type *type,
 			   struct regcache *regcache, gdb_byte *valbuf)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int len = TYPE_LENGTH (type);
   gdb_byte buf[I386_MAX_REGISTER_SIZE];
 
@@ -2918,7 +2918,7 @@ static void
 i386_store_return_value (struct gdbarch *gdbarch, struct type *type,
 			 struct regcache *regcache, const gdb_byte *valbuf)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int len = TYPE_LENGTH (type);
 
   if (type->code () == TYPE_CODE_FLT)
@@ -2997,7 +2997,7 @@ static const char *struct_convention = default_struct_convention;
 static int
 i386_reg_struct_return_p (struct gdbarch *gdbarch, struct type *type)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   enum type_code code = type->code ();
   int len = TYPE_LENGTH (type);
 
@@ -3099,7 +3099,7 @@ i386_return_value (struct gdbarch *gdbarch, struct value *function,
 struct type *
 i387_ext_type (struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (!tdep->i387_ext_type)
     {
@@ -3117,7 +3117,7 @@ i387_ext_type (struct gdbarch *gdbarch)
 static struct type *
 i386_bnd_type (struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
 
   if (!tdep->i386_bnd_type)
@@ -3153,7 +3153,7 @@ i386_bnd_type (struct gdbarch *gdbarch)
 static struct type *
 i386_zmm_type (struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (!tdep->i386_zmm_type)
     {
@@ -3212,7 +3212,7 @@ i386_zmm_type (struct gdbarch *gdbarch)
 static struct type *
 i386_ymm_type (struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (!tdep->i386_ymm_type)
     {
@@ -3269,7 +3269,7 @@ i386_ymm_type (struct gdbarch *gdbarch)
 static struct type *
 i386_mmx_type (struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (!tdep->i386_mmx_type)
     {
@@ -3346,7 +3346,7 @@ static int
 i386_mmx_regnum_to_fp_regnum (readable_regcache *regcache, int regnum)
 {
   gdbarch *arch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
   int mmxreg, fpreg;
   ULONGEST fstat;
   int tos;
@@ -3387,7 +3387,7 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
     }
   else
     {
-      i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
       if (i386_bnd_regnum_p (gdbarch, regnum))
 	{
 	  regnum -= tdep->bnd0_regnum;
@@ -3577,7 +3577,7 @@ i386_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
     }
   else
     {
-      i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
       if (i386_bnd_regnum_p (gdbarch, regnum))
 	{
@@ -3685,7 +3685,7 @@ int
 i386_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				 struct agent_expr *ax, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (i386_mmx_regnum_p (gdbarch, regnum))
     {
@@ -3902,7 +3902,7 @@ i386_supply_gregset (const struct regset *regset, struct regcache *regcache,
 		     int regnum, const void *gregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   const gdb_byte *regs = (const gdb_byte *) gregs;
   int i;
 
@@ -3927,7 +3927,7 @@ i386_collect_gregset (const struct regset *regset,
 		      int regnum, void *gregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   gdb_byte *regs = (gdb_byte *) gregs;
   int i;
 
@@ -3950,7 +3950,7 @@ i386_supply_fpregset (const struct regset *regset, struct regcache *regcache,
 		      int regnum, const void *fpregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (len == I387_SIZEOF_FXSAVE)
     {
@@ -3973,7 +3973,7 @@ i386_collect_fpregset (const struct regset *regset,
 		       int regnum, void *fpregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (len == I387_SIZEOF_FXSAVE)
     {
@@ -4005,7 +4005,7 @@ i386_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				   void *cb_data,
 				   const struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   cb (".reg", tdep->sizeof_gregset, tdep->sizeof_gregset, &i386_gregset, NULL,
       cb_data);
@@ -4510,7 +4510,7 @@ i386_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 void
 i386_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* System V Release 4 uses ELF.  */
   i386_elf_init_abi (info, gdbarch);
@@ -4552,7 +4552,7 @@ int
 i386_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 			  const struct reggroup *group)
 {
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int fp_regnum_p, mmx_regnum_p, xmm_regnum_p, mxcsr_regnum_p,
       ymm_regnum_p, ymmh_regnum_p, ymm_avx512_regnum_p, ymmh_avx512_regnum_p,
       bndr_regnum_p, bnd_regnum_p, zmm_regnum_p, zmmh_regnum_p,
@@ -4997,7 +4997,7 @@ static int i386_record_floats (struct gdbarch *gdbarch,
 			       struct i386_record_s *ir,
 			       uint32_t iregnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int i;
 
   /* Oza: Because of floating point insn push/pop of fpu stack is going to
@@ -5068,7 +5068,7 @@ i386_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
   ULONGEST addr;
   gdb_byte buf[I386_MAX_REGISTER_SIZE];
   struct i386_record_s ir;
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   uint8_t rex_w = -1;
   uint8_t rex_r = 0;
 
@@ -8839,7 +8839,7 @@ i386_mpx_bd_base (void)
 
   rcache = get_current_regcache ();
   gdbarch *arch = rcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
 
   regstatus = regcache_raw_read_unsigned (rcache, tdep->bndcfgu_regnum, &ret);
 
@@ -8853,7 +8853,7 @@ int
 i386_mpx_enabled (void)
 {
   gdbarch *arch = get_current_arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
   const struct target_desc *tdesc = tdep->tdesc;
 
   return (tdesc_find_feature (tdesc, "org.gnu.gdb.i386.mpx") != NULL);
diff --git a/gdb/i386-windows-tdep.c b/gdb/i386-windows-tdep.c
index 8e1cc17b91c..9eec6e28109 100644
--- a/gdb/i386-windows-tdep.c
+++ b/gdb/i386-windows-tdep.c
@@ -136,7 +136,7 @@ i386_windows_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 static void
 i386_windows_init_abi_common (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   set_gdbarch_skip_trampoline_code (gdbarch, i386_windows_skip_trampoline_code);
 
diff --git a/gdb/i387-tdep.c b/gdb/i387-tdep.c
index f056ea59347..42ed4eebc2c 100644
--- a/gdb/i387-tdep.c
+++ b/gdb/i387-tdep.c
@@ -204,7 +204,7 @@ void
 i387_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
 		       struct frame_info *frame, const char *args)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   ULONGEST fctrl;
   int fctrl_p;
   ULONGEST fstat;
@@ -440,7 +440,7 @@ void
 i387_supply_fsave (struct regcache *regcache, int regnum, const void *fsave)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   const gdb_byte *regs = (const gdb_byte *) fsave;
   int i;
@@ -495,7 +495,7 @@ void
 i387_collect_fsave (const struct regcache *regcache, int regnum, void *fsave)
 {
   gdbarch *arch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
   gdb_byte *regs = (gdb_byte *) fsave;
   int i;
 
@@ -589,7 +589,7 @@ void
 i387_supply_fxsave (struct regcache *regcache, int regnum, const void *fxsave)
 {
   gdbarch *arch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
   const gdb_byte *regs = (const gdb_byte *) fxsave;
   int i;
 
@@ -673,7 +673,7 @@ void
 i387_collect_fxsave (const struct regcache *regcache, int regnum, void *fxsave)
 {
   gdbarch *arch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
   gdb_byte *regs = (gdb_byte *) fxsave;
   int i;
 
@@ -906,7 +906,7 @@ i387_xsave_get_clear_bv (struct gdbarch *gdbarch, const void *xsave)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   const gdb_byte *regs = (const gdb_byte *) xsave;
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* Get `xstat_bv'.  The supported bits in `xstat_bv' are 8 bytes.  */
   ULONGEST xstate_bv = extract_unsigned_integer (XSAVE_XSTATE_BV_ADDR (regs),
@@ -926,7 +926,7 @@ i387_supply_xsave (struct regcache *regcache, int regnum,
 {
   struct gdbarch *gdbarch = regcache->arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   const gdb_byte *regs = (const gdb_byte *) xsave;
   int i;
   /* In 64-bit mode the split between "low" and "high" ZMM registers is at
@@ -1349,7 +1349,7 @@ i387_collect_xsave (const struct regcache *regcache, int regnum,
 {
   struct gdbarch *gdbarch = regcache->arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   gdb_byte *p, *regs = (gdb_byte *) xsave;
   gdb_byte raw[I386_MAX_REGISTER_SIZE];
   ULONGEST initial_xstate_bv, clear_bv, xstate_bv = 0;
@@ -1934,7 +1934,7 @@ i387_tag (const gdb_byte *raw)
 void
 i387_return_value (struct gdbarch *gdbarch, struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   ULONGEST fstat;
 
   /* Set the top of the floating-point register stack to 7.  The
@@ -1957,7 +1957,7 @@ i387_return_value (struct gdbarch *gdbarch, struct regcache *regcache)
 void
 i387_reset_bnd_regs (struct gdbarch *gdbarch, struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (I387_BND0R_REGNUM (tdep) > 0)
     {
diff --git a/gdb/ia64-linux-tdep.c b/gdb/ia64-linux-tdep.c
index 64a57f5bf2f..508d4e6f7c6 100644
--- a/gdb/ia64-linux-tdep.c
+++ b/gdb/ia64-linux-tdep.c
@@ -216,7 +216,7 @@ ia64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 static void
 ia64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
   static const char *const stap_register_prefixes[] = { "r", NULL };
   static const char *const stap_register_indirection_prefixes[] = { "[",
 								    NULL };
diff --git a/gdb/ia64-tdep.c b/gdb/ia64-tdep.c
index 82456dc9c98..de343cfe17d 100644
--- a/gdb/ia64-tdep.c
+++ b/gdb/ia64-tdep.c
@@ -310,7 +310,7 @@ static const struct floatformat *floatformats_ia64_ext[2] =
 static struct type *
 ia64_ext_type (struct gdbarch *gdbarch)
 {
-  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
 
   if (!tdep->ia64_ext_type)
     tdep->ia64_ext_type
@@ -2177,7 +2177,7 @@ ia64_sigtramp_frame_init_saved_regs (struct frame_info *this_frame,
 				     struct ia64_frame_cache *cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
 
   if (tdep->sigcontext_register_address)
     {
@@ -2336,7 +2336,7 @@ ia64_sigtramp_frame_sniffer (const struct frame_unwind *self,
 			     void **this_cache)
 {
   gdbarch *arch = get_frame_arch (this_frame);
-  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (arch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (arch);
   if (tdep->pc_in_sigtramp)
     {
       CORE_ADDR pc = get_frame_pc (this_frame);
@@ -2485,7 +2485,7 @@ ia64_access_reg (unw_addr_space_t as, unw_regnum_t uw_regnum, unw_word_t *val,
   unw_word_t bsp, sof, cfm, psr, ip;
   struct frame_info *this_frame = (struct frame_info *) arg;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
   
   /* We never call any libunwind routines that need to write registers.  */
   gdb_assert (!write);
@@ -3484,7 +3484,7 @@ ia64_find_global_pointer_from_dynamic_section (struct gdbarch *gdbarch,
 static CORE_ADDR
 ia64_find_global_pointer (struct gdbarch *gdbarch, CORE_ADDR faddr)
 {
-  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
   CORE_ADDR addr = 0;
 
   if (tdep->find_global_pointer_from_solib)
@@ -3679,7 +3679,7 @@ ia64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 		      function_call_return_method return_method,
 		      CORE_ADDR struct_addr)
 {
-  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int argno;
   struct value *arg;
diff --git a/gdb/loongarch-linux-nat.c b/gdb/loongarch-linux-nat.c
index edc3d697d7b..689c10bd57e 100644
--- a/gdb/loongarch-linux-nat.c
+++ b/gdb/loongarch-linux-nat.c
@@ -51,7 +51,7 @@ static void
 fetch_gregs_from_thread (struct regcache *regcache, int regno, pid_t tid)
 {
   loongarch_gdbarch_tdep *tdep
-    = (loongarch_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<loongarch_gdbarch_tdep> (regcache->arch ());
   auto regs = tdep->regs;
   elf_gregset_t regset;
 
@@ -78,7 +78,7 @@ static void
 store_gregs_to_thread (struct regcache *regcache, int regno, pid_t tid)
 {
   loongarch_gdbarch_tdep *tdep
-    = (loongarch_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<loongarch_gdbarch_tdep> (regcache->arch ());
   auto regs = tdep->regs;
   elf_gregset_t regset;
 
@@ -131,7 +131,7 @@ loongarch_linux_nat_target::register_u_offset (struct gdbarch *gdbarch,
 					       int regno, int store_p)
 {
   loongarch_gdbarch_tdep *tdep
-    = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+    = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
   auto regs = tdep->regs;
 
   /* According to <asm/ptrace.h> */
diff --git a/gdb/loongarch-linux-tdep.c b/gdb/loongarch-linux-tdep.c
index 372643761b1..b6d790ab185 100644
--- a/gdb/loongarch-linux-tdep.c
+++ b/gdb/loongarch-linux-tdep.c
@@ -41,7 +41,7 @@ loongarch_supply_gregset (const struct regset *r,
 			  const void *gprs, size_t len)
 {
   loongarch_gdbarch_tdep *tdep
-    = (loongarch_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<loongarch_gdbarch_tdep> (regcache->arch ());
   auto regs = tdep->regs;
 
   int regsize = register_size (regcache->arch (), regs.r);
@@ -85,7 +85,7 @@ loongarch_fill_gregset (const struct regset *r,
 			void *gprs, size_t len)
 {
   loongarch_gdbarch_tdep *tdep
-    = (loongarch_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<loongarch_gdbarch_tdep> (regcache->arch ());
   auto regs = tdep->regs;
   int regsize = register_size (regcache->arch (), regs.r);
   gdb_byte *buf = nullptr;
@@ -136,7 +136,7 @@ loongarch_linux_rt_sigframe_init (const struct tramp_frame *self,
 				  CORE_ADDR func)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  loongarch_gdbarch_tdep *tdep = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
   auto regs = tdep->regs;
 
   CORE_ADDR frame_sp = get_frame_sp (this_frame);
@@ -177,7 +177,7 @@ loongarch_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					const struct regcache *regcache)
 {
   loongarch_gdbarch_tdep *tdep
-    = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+    = gdbarch_tdep<loongarch_gdbarch_tdep> (regcache->arch ());
   auto regs = tdep->regs;
   int regsize = register_size (gdbarch, regs.r);
 
diff --git a/gdb/loongarch-tdep.c b/gdb/loongarch-tdep.c
index 963e832454a..af5ccb17286 100644
--- a/gdb/loongarch-tdep.c
+++ b/gdb/loongarch-tdep.c
@@ -74,7 +74,7 @@ loongarch_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc,
 			 struct trad_frame_cache *this_cache)
 {
   CORE_ADDR cur_pc = start_pc, prologue_end = 0;
-  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  loongarch_gdbarch_tdep *tdep = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
   auto regs = tdep->regs;
   int32_t sp = regs.r + 3;
   int32_t fp = regs.r + 22;
@@ -306,7 +306,7 @@ loongarch_frame_cache (struct frame_info *this_frame, void **this_cache)
   cache = trad_frame_cache_zalloc (this_frame);
   *this_cache = cache;
 
-  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  loongarch_gdbarch_tdep *tdep = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
   trad_frame_set_reg_realreg (cache, gdbarch_pc_regnum (gdbarch), tdep->regs.ra);
 
   pc = get_frame_address_in_block (this_frame);
@@ -358,7 +358,7 @@ loongarch_return_value (struct gdbarch *gdbarch, struct value *function,
 			struct type *type, struct regcache *regcache,
 			gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  loongarch_gdbarch_tdep *tdep = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
   auto regs = tdep->regs;
   int len = TYPE_LENGTH (type);
   int regnum = -1;
@@ -386,7 +386,7 @@ loongarch_return_value (struct gdbarch *gdbarch, struct value *function,
 static int
 loongarch_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int num)
 {
-  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  loongarch_gdbarch_tdep *tdep = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
   auto regs = tdep->regs;
 
   if (0 <= num && num < 32)
@@ -512,7 +512,7 @@ loongarch_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 	 we are looking for.  If it doesn't then we can't reuse this
 	 gdbarch.  */
       loongarch_gdbarch_tdep *candidate_tdep
-	= (loongarch_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<loongarch_gdbarch_tdep> (arches->gdbarch);
 
       if (candidate_tdep->abi_features != abi_features)
 	continue;
diff --git a/gdb/m32c-tdep.c b/gdb/m32c-tdep.c
index 4971be796cd..37456d16cb3 100644
--- a/gdb/m32c-tdep.c
+++ b/gdb/m32c-tdep.c
@@ -142,7 +142,7 @@ struct m32c_gdbarch_tdep : gdbarch_tdep
 static void
 make_types (struct gdbarch *arch)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   unsigned long mach = gdbarch_bfd_arch_info (arch)->mach;
   int data_addr_reg_bits, code_addr_reg_bits;
   char type_name[50];
@@ -215,7 +215,7 @@ make_types (struct gdbarch *arch)
 static const char *
 m32c_register_name (struct gdbarch *gdbarch, int num)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   return tdep->regs[num].name;
 }
 
@@ -223,7 +223,7 @@ m32c_register_name (struct gdbarch *gdbarch, int num)
 static struct type *
 m32c_register_type (struct gdbarch *arch, int reg_nr)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   return tdep->regs[reg_nr].type;
 }
 
@@ -231,7 +231,7 @@ m32c_register_type (struct gdbarch *arch, int reg_nr)
 static int
 m32c_register_sim_regno (struct gdbarch *gdbarch, int reg_nr)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   return tdep->regs[reg_nr].sim_num;
 }
 
@@ -239,7 +239,7 @@ m32c_register_sim_regno (struct gdbarch *gdbarch, int reg_nr)
 static int
 m32c_debug_info_reg_to_regnum (struct gdbarch *gdbarch, int reg_nr)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   if (0 <= reg_nr && reg_nr <= M32C_MAX_DWARF_REGNUM
       && tdep->dwarf_regs[reg_nr])
     return tdep->dwarf_regs[reg_nr]->num;
@@ -254,7 +254,7 @@ static int
 m32c_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 			  const struct reggroup *group)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   struct m32c_reg *reg = &tdep->regs[regnum];
 
   /* The anonymous raw registers aren't in any groups.  */
@@ -330,7 +330,7 @@ static int
 m32c_read_flg (readable_regcache *cache)
 {
   gdbarch *arch = cache->arch ();
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   ULONGEST flg;
 
   cache->raw_read (tdep->flg->num, &flg);
@@ -530,7 +530,7 @@ static enum register_status
 m32c_r3r2r1r0_read (struct m32c_reg *reg, readable_regcache *cache, gdb_byte *buf)
 {
   gdbarch *arch = reg->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   int len = TYPE_LENGTH (tdep->r0->type);
   enum register_status status;
 
@@ -567,7 +567,7 @@ m32c_r3r2r1r0_write (struct m32c_reg *reg, struct regcache *cache,
 		     const gdb_byte *buf)
 {
   gdbarch *arch = reg->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   int len = TYPE_LENGTH (tdep->r0->type);
 
   if (gdbarch_byte_order (reg->arch) == BFD_ENDIAN_BIG)
@@ -595,7 +595,7 @@ m32c_pseudo_register_read (struct gdbarch *arch,
 			   int cookednum,
 			   gdb_byte *buf)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   struct m32c_reg *reg;
 
   gdb_assert (0 <= cookednum && cookednum < tdep->num_regs);
@@ -613,7 +613,7 @@ m32c_pseudo_register_write (struct gdbarch *arch,
 			    int cookednum,
 			    const gdb_byte *buf)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   struct m32c_reg *reg;
 
   gdb_assert (0 <= cookednum && cookednum < tdep->num_regs);
@@ -638,7 +638,7 @@ add_reg (struct gdbarch *arch,
 	 struct m32c_reg *ry,
 	 int n)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   struct m32c_reg *r = &tdep->regs[tdep->num_regs];
 
   gdb_assert (tdep->num_regs < M32C_MAX_NUM_REGS);
@@ -678,7 +678,7 @@ set_dwarf_regnum (struct m32c_reg *reg, int num)
 
   /* Update the DWARF->reg mapping.  */
   gdbarch *arch = reg->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   tdep->dwarf_regs[num] = reg;
 }
 
@@ -800,7 +800,7 @@ mark_save_restore (struct m32c_reg *reg)
 static void
 make_regs (struct gdbarch *arch)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   int mach = gdbarch_bfd_arch_info (arch)->mach;
   int num_raw_regs;
   int num_cooked_regs;
@@ -1349,7 +1349,7 @@ m32c_pv_enter (struct m32c_pv_state *state, int size)
     return 1;
 
   gdbarch *arch = state->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   if (m32c_pv_push (state, state->fb, tdep->push_addr_bytes))
     return 1;
 
@@ -1379,7 +1379,7 @@ static int
 m32c_pv_pushm (struct m32c_pv_state *state, int src)
 {
   gdbarch *arch = state->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   /* The bits in SRC indicating which registers to save are:
      r0 r1 r2 r3 a0 a1 sb fb */
@@ -1400,7 +1400,7 @@ static int
 m32c_is_1st_arg_reg (struct m32c_pv_state *state, pv_t value)
 {
   gdbarch *arch = state->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   return (value.kind == pvk_register
 	  && (gdbarch_bfd_arch_info (state->arch)->mach == bfd_mach_m16c
@@ -1415,7 +1415,7 @@ static int
 m32c_is_arg_reg (struct m32c_pv_state *state, pv_t value)
 {
   gdbarch *arch = state->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   return (value.kind == pvk_register
 	  && (gdbarch_bfd_arch_info (state->arch)->mach == bfd_mach_m16c
@@ -1440,7 +1440,7 @@ m32c_is_arg_spill (struct m32c_pv_state *st,
 		   pv_t value)
 {
   gdbarch *arch = st->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   return (m32c_is_arg_reg (st, value)
 	  && loc.kind == srcdest_mem
@@ -1464,7 +1464,7 @@ m32c_is_struct_return (struct m32c_pv_state *st,
 		       pv_t value)
 {
   gdbarch *arch = st->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   return (m32c_is_1st_arg_reg (st, value)
 	  && !st->stack->find_reg (st->arch, value.reg, 0)
@@ -1482,7 +1482,7 @@ static int
 m32c_pushm_is_reg_save (struct m32c_pv_state *st, int src)
 {
   gdbarch *arch = st->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   /* The bits in SRC indicating which registers to save are:
      r0 r1 r2 r3 a0 a1 sb fb */
@@ -1510,7 +1510,7 @@ check_for_saved (void *prologue_untyped, pv_t addr, CORE_ADDR size, pv_t value)
 {
   struct m32c_prologue *prologue = (struct m32c_prologue *) prologue_untyped;
   struct gdbarch *arch = prologue->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   /* Is this the unchanged value of some register being saved on the
      stack?  */
@@ -1550,7 +1550,7 @@ m32c_analyze_prologue (struct gdbarch *arch,
 		       CORE_ADDR start, CORE_ADDR limit,
 		       struct m32c_prologue *prologue)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   unsigned long mach = gdbarch_bfd_arch_info (arch)->mach;
   CORE_ADDR after_last_frame_related_insn;
   struct m32c_pv_state st;
@@ -1881,7 +1881,7 @@ m32c_frame_base (struct frame_info *this_frame,
   struct m32c_prologue *p
     = m32c_analyze_frame_prologue (this_frame, this_prologue_cache);
   gdbarch *arch = get_frame_arch (this_frame);
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   /* In functions that use alloca, the distance between the stack
      pointer and the frame base varies dynamically, so we can't use
@@ -1932,7 +1932,7 @@ m32c_prev_register (struct frame_info *this_frame,
 		    void **this_prologue_cache, int regnum)
 {
   gdbarch *arch = get_frame_arch (this_frame);
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   struct m32c_prologue *p
     = m32c_analyze_frame_prologue (this_frame, this_prologue_cache);
   CORE_ADDR frame_base = m32c_frame_base (this_frame, this_prologue_cache);
@@ -2015,7 +2015,7 @@ m32c_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 		      function_call_return_method return_method,
 		      CORE_ADDR struct_addr)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   unsigned long mach = gdbarch_bfd_arch_info (gdbarch)->mach;
   CORE_ADDR cfa;
@@ -2178,7 +2178,7 @@ m32c_return_value (struct gdbarch *gdbarch,
 		   gdb_byte *readbuf,
 		   const gdb_byte *writebuf)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   enum return_value_convention conv;
   ULONGEST valtype_len = TYPE_LENGTH (valtype);
@@ -2309,7 +2309,7 @@ static CORE_ADDR
 m32c_skip_trampoline_code (struct frame_info *frame, CORE_ADDR stop_pc)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   /* It would be nicer to simply look up the addresses of known
@@ -2555,7 +2555,7 @@ m32c_virtual_frame_pointer (struct gdbarch *gdbarch, CORE_ADDR pc,
   struct m32c_prologue p;
 
   struct regcache *regcache = get_current_regcache ();
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   
   if (!find_pc_partial_function (pc, &name, &func_addr, &func_end))
     internal_error (__FILE__, __LINE__,
diff --git a/gdb/m68hc11-tdep.c b/gdb/m68hc11-tdep.c
index 98f1367423e..9eb18b937be 100644
--- a/gdb/m68hc11-tdep.c
+++ b/gdb/m68hc11-tdep.c
@@ -146,14 +146,14 @@ struct m68gc11_gdbarch_tdep : gdbarch_tdep
 static int
 stack_correction (gdbarch *arch)
 {
-  m68gc11_gdbarch_tdep *tdep = (m68gc11_gdbarch_tdep *) gdbarch_tdep (arch);
+  m68gc11_gdbarch_tdep *tdep = gdbarch_tdep<m68gc11_gdbarch_tdep> (arch);
   return tdep->stack_correction;
 }
 
 static int
 use_page_register (gdbarch *arch)
 {
-  m68gc11_gdbarch_tdep *tdep = (m68gc11_gdbarch_tdep *) gdbarch_tdep (arch);
+  m68gc11_gdbarch_tdep *tdep = gdbarch_tdep<m68gc11_gdbarch_tdep> (arch);
   return tdep->stack_correction;
 }
 
@@ -642,7 +642,7 @@ m68hc11_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
       return pc;
     }
 
-  m68gc11_gdbarch_tdep *tdep = (m68gc11_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68gc11_gdbarch_tdep *tdep = gdbarch_tdep<m68gc11_gdbarch_tdep> (gdbarch);
   seq_table = tdep->prologue;
   
   /* The 68hc11 stack is as follows:
@@ -1020,7 +1020,7 @@ m68hc11_print_register (struct gdbarch *gdbarch, struct ui_file *file,
   else
     {
       m68gc11_gdbarch_tdep *tdep
-	= (m68gc11_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	= gdbarch_tdep<m68gc11_gdbarch_tdep> (gdbarch);
 
       if (regno == HARD_PC_REGNUM && tdep->use_page_register)
 	{
@@ -1125,7 +1125,7 @@ m68hc11_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file,
       gdb_printf (file, " Y=");
       m68hc11_print_register (gdbarch, file, frame, HARD_Y_REGNUM);
   
-      m68gc11_gdbarch_tdep *tdep = (m68gc11_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      m68gc11_gdbarch_tdep *tdep = gdbarch_tdep<m68gc11_gdbarch_tdep> (gdbarch);
 
       if (tdep->use_page_register)
 	{
@@ -1417,7 +1417,7 @@ m68hc11_gdbarch_init (struct gdbarch_info info,
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       m68gc11_gdbarch_tdep *tdep
-	= (m68gc11_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<m68gc11_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->elf_flags != elf_flags)
 	continue;
diff --git a/gdb/m68k-bsd-tdep.c b/gdb/m68k-bsd-tdep.c
index 9ef70f0dda4..2614c223f8e 100644
--- a/gdb/m68k-bsd-tdep.c
+++ b/gdb/m68k-bsd-tdep.c
@@ -133,7 +133,7 @@ m68kbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 static void
 m68kbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   tdep->jb_pc = 5;
   tdep->jb_elt_size = 4;
diff --git a/gdb/m68k-linux-tdep.c b/gdb/m68k-linux-tdep.c
index 85ad4741b1f..28401d3ecc6 100644
--- a/gdb/m68k-linux-tdep.c
+++ b/gdb/m68k-linux-tdep.c
@@ -384,7 +384,7 @@ m68k_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 static void
 m68k_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/m68k-tdep.c b/gdb/m68k-tdep.c
index 568bde66f93..9e59f5904c3 100644
--- a/gdb/m68k-tdep.c
+++ b/gdb/m68k-tdep.c
@@ -70,7 +70,7 @@ typedef BP_MANIPULATION (m68k_break_insn) m68k_breakpoint;
 static struct type *
 m68k_ps_type (struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (!tdep->m68k_ps_type)
     {
@@ -99,7 +99,7 @@ m68k_ps_type (struct gdbarch *gdbarch)
 static struct type *
 m68881_ext_type (struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (!tdep->m68881_ext_type)
     tdep->m68881_ext_type
@@ -120,7 +120,7 @@ m68881_ext_type (struct gdbarch *gdbarch)
 static struct type *
 m68k_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (tdep->fpregs_present)
     {
@@ -171,7 +171,7 @@ static const char * const m68k_register_names[] = {
 static const char *
 m68k_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (regnum < 0 || regnum >= ARRAY_SIZE (m68k_register_names))
     internal_error (__FILE__, __LINE__,
@@ -191,7 +191,7 @@ static int
 m68k_convert_register_p (struct gdbarch *gdbarch,
 			 int regnum, struct type *type)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (!tdep->fpregs_present)
     return 0;
@@ -300,7 +300,7 @@ m68k_extract_return_value (struct type *type, struct regcache *regcache,
   if (type->code () == TYPE_CODE_PTR && len == 4)
     {
       struct gdbarch *gdbarch = regcache->arch ();
-      m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
       regcache->raw_read (tdep->pointer_result_regnum, valbuf);
     }
   else if (len <= 4)
@@ -325,7 +325,7 @@ m68k_svr4_extract_return_value (struct type *type, struct regcache *regcache,
 {
   gdb_byte buf[M68K_MAX_REGISTER_SIZE];
   struct gdbarch *gdbarch = regcache->arch ();
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (tdep->float_return && type->code () == TYPE_CODE_FLT)
     {
@@ -348,7 +348,7 @@ m68k_store_return_value (struct type *type, struct regcache *regcache,
   if (type->code () == TYPE_CODE_PTR && len == 4)
     {
       struct gdbarch *gdbarch = regcache->arch ();
-      m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
       regcache->raw_write (tdep->pointer_result_regnum, valbuf);
       /* gdb historically also set D0 in the SVR4 case.  */
       if (tdep->pointer_result_regnum != M68K_D0_REGNUM)
@@ -371,7 +371,7 @@ m68k_svr4_store_return_value (struct type *type, struct regcache *regcache,
 			      const gdb_byte *valbuf)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (tdep->float_return && type->code () == TYPE_CODE_FLT)
     {
@@ -391,7 +391,7 @@ m68k_svr4_store_return_value (struct type *type, struct regcache *regcache,
 static int
 m68k_reg_struct_return_p (struct gdbarch *gdbarch, struct type *type)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
   enum type_code code = type->code ();
   int len = TYPE_LENGTH (type);
 
@@ -469,7 +469,7 @@ m68k_svr4_return_value (struct gdbarch *gdbarch, struct value *function,
 			gdb_byte *readbuf, const gdb_byte *writebuf)
 {
   enum type_code code = type->code ();
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   /* Aggregates with a single member are always returned like their
      sole element.  */
@@ -541,7 +541,7 @@ m68k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 		      function_call_return_method return_method,
 		      CORE_ADDR struct_addr)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   gdb_byte buf[4];
   int i;
@@ -596,7 +596,7 @@ m68k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 static int
 m68k_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int num)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (num < 8)
     /* d0..7 */
@@ -766,7 +766,7 @@ m68k_analyze_register_saves (struct gdbarch *gdbarch, CORE_ADDR pc,
 			     struct m68k_frame_cache *cache)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (cache->locals >= 0)
     {
@@ -1058,7 +1058,7 @@ m68k_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
   gdb_byte *buf;
   CORE_ADDR sp, jb_addr;
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   if (tdep->jb_pc < 0)
@@ -1104,7 +1104,7 @@ m68k_return_in_first_hidden_param_p (struct gdbarch *gdbarch,
 void
 m68k_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   /* SVR4 uses a different calling convention.  */
   set_gdbarch_return_value (gdbarch, m68k_svr4_return_value);
@@ -1122,7 +1122,7 @@ m68k_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 static void
 m68k_embedded_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   m68k_svr4_init_abi (info, gdbarch);
   tdep->pointer_result_regnum = M68K_D0_REGNUM;
@@ -1237,7 +1237,7 @@ m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
     {
       m68k_gdbarch_tdep *tdep
-	= (m68k_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
+	= gdbarch_tdep<m68k_gdbarch_tdep> (best_arch->gdbarch);
 
       if (flavour != tdep->flavour)
 	continue;
@@ -1339,7 +1339,7 @@ m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 m68k_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (tdep == NULL)
     return;
diff --git a/gdb/mep-tdep.c b/gdb/mep-tdep.c
index 6b3a62391c0..d5ba78c6df9 100644
--- a/gdb/mep-tdep.c
+++ b/gdb/mep-tdep.c
@@ -260,7 +260,7 @@ me_module_register_set (CONFIG_ATTR me_module,
        specifically excluding the generic coprocessor register sets.  */
 
   mep_gdbarch_tdep *tdep
-    = (mep_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+    = gdbarch_tdep<mep_gdbarch_tdep> (target_gdbarch ());
   CGEN_CPU_DESC desc = tdep->cpu_desc;
   const CGEN_HW_ENTRY *hw;
 
@@ -856,7 +856,7 @@ current_me_module (void)
   else
     {
       mep_gdbarch_tdep *tdep
-	= (mep_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+	= gdbarch_tdep<mep_gdbarch_tdep> (target_gdbarch ());
       return tdep->me_module;
     }
 }
@@ -2391,7 +2391,7 @@ mep_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       mep_gdbarch_tdep *tdep
-	= (mep_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<mep_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->me_module == me_module)
 	return arches->gdbarch;
diff --git a/gdb/mips-linux-tdep.c b/gdb/mips-linux-tdep.c
index d8f90ccf881..ca313a28279 100644
--- a/gdb/mips-linux-tdep.c
+++ b/gdb/mips-linux-tdep.c
@@ -1317,7 +1317,7 @@ mips_linux_get_syscall_number (struct gdbarch *gdbarch,
 			       thread_info *thread)
 {
   struct regcache *regcache = get_thread_regcache (thread);
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int regsize = register_size (gdbarch, MIPS_V0_REGNUM);
   /* The content of a register */
@@ -1527,7 +1527,7 @@ static void
 mips_linux_init_abi (struct gdbarch_info info,
 		     struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   enum mips_abi abi = mips_abi (gdbarch);
   struct tdesc_arch_data *tdesc_data = info.tdesc_data;
 
diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index fc1cb46de84..1ea16767e54 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -227,7 +227,7 @@ static const char mips_disassembler_options_n64[] = "gpr-names=64";
 const struct mips_regnum *
 mips_regnum (struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   return tdep->regnum;
 }
 
@@ -252,7 +252,7 @@ mips_float_register_p (struct gdbarch *gdbarch, int regnum)
 static bool
 mips_eabi (gdbarch *arch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (arch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (arch);
   return (tdep->mips_abi == MIPS_ABI_EABI32 \
 	  || tdep->mips_abi == MIPS_ABI_EABI64);
 }
@@ -260,21 +260,21 @@ mips_eabi (gdbarch *arch)
 static int
 mips_last_fp_arg_regnum (gdbarch *arch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (arch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (arch);
   return tdep->mips_last_fp_arg_regnum;
 }
 
 static int
 mips_last_arg_regnum (gdbarch *arch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (arch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (arch);
   return tdep->mips_last_arg_regnum;
 }
 
 static enum mips_fpu_type
 mips_get_fpu_type (gdbarch *arch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (arch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (arch);
   return tdep->mips_fpu_type;
 }
 
@@ -282,14 +282,14 @@ mips_get_fpu_type (gdbarch *arch)
 enum mips_abi
 mips_abi (struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   return tdep->mips_abi;
 }
 
 int
 mips_isa_regsize (struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
   /* If we know how big the registers are, use that size.  */
   if (tdep->register_size_valid_p)
@@ -335,7 +335,7 @@ mips_abi_regsize (struct gdbarch *gdbarch)
 static int
 is_mips16_isa (struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   return tdep->mips_isa == ISA_MIPS16;
 }
 
@@ -344,7 +344,7 @@ is_mips16_isa (struct gdbarch *gdbarch)
 static int
 is_micromips_isa (struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   return tdep->mips_isa == ISA_MICROMIPS;
 }
 
@@ -636,7 +636,7 @@ static const char * const mips_linux_reg_names[NUM_MIPS_PROCESSOR_REGS] = {
 static const char *
 mips_register_name (struct gdbarch *gdbarch, int regno)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   /* GPR names for all ABIs other than n32/n64.  */
   static const char *mips_gpr_names[] = {
     "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
@@ -777,7 +777,7 @@ mips_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
   else if (register_size (gdbarch, rawnum) >
 	   register_size (gdbarch, cookednum))
     {
-      mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
       if (tdep->mips64_transfers_32bit_regs_p)
 	return regcache->raw_read_part (rawnum, 0, 4, buf);
@@ -810,7 +810,7 @@ mips_pseudo_register_write (struct gdbarch *gdbarch,
   else if (register_size (gdbarch, rawnum) >
 	   register_size (gdbarch, cookednum))
     {
-      mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
       if (tdep->mips64_transfers_32bit_regs_p)
 	regcache->raw_write_part (rawnum, 0, 4, buf);
@@ -855,7 +855,7 @@ mips_ax_pseudo_register_push_stack (struct gdbarch *gdbarch,
       if (register_size (gdbarch, rawnum) > register_size (gdbarch, reg))
 	{
 	  mips_gdbarch_tdep *tdep
-	    = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	    = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
 	  if (!tdep->mips64_transfers_32bit_regs_p
 	      || gdbarch_byte_order (gdbarch) != BFD_ENDIAN_BIG)
@@ -1059,7 +1059,7 @@ mips_register_type (struct gdbarch *gdbarch, int regnum)
   else
     {
       int rawnum = regnum - gdbarch_num_regs (gdbarch);
-      mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
       /* The cooked or ABI registers.  These are sized according to
 	 the ABI (with a few complications).  */
@@ -1191,7 +1191,7 @@ show_mask_address (struct ui_file *file, int from_tty,
       else
 	{
 	  mips_gdbarch_tdep *tdep
-	    = (mips_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+	    = gdbarch_tdep<mips_gdbarch_tdep> (target_gdbarch ());
 
 	  if (mips_mask_address_p (tdep))
 	    additional_text = _(" (currently \"on\")");
@@ -1727,7 +1727,7 @@ mips32_next_pc (struct regcache *regcache, CORE_ADDR pc)
 	    case 12:            /* SYSCALL */
 	      {
 		mips_gdbarch_tdep *tdep
-		  = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+		  = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
 		if (tdep->syscall_next_pc != NULL)
 		  pc = tdep->syscall_next_pc (get_current_frame ());
@@ -1938,7 +1938,7 @@ micromips_next_pc (struct regcache *regcache, CORE_ADDR pc)
 		case 0x22d: /* SYSCALL:  000000 1000101101 111100 */
 		  {
 		    mips_gdbarch_tdep *tdep
-		      = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+		      = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
 		    if (tdep->syscall_next_pc != NULL)
 		      pc = tdep->syscall_next_pc (get_current_frame ());
@@ -3901,7 +3901,7 @@ mips_stub_frame_base_sniffer (struct frame_info *this_frame)
 static CORE_ADDR
 mips_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
   if (mips_mask_address_p (tdep) && (((ULONGEST) addr) >> 32 == 0xffffffffUL))
     /* This hack is a work-around for existing boards using PMON, the
@@ -4804,7 +4804,7 @@ mips_eabi_return_value (struct gdbarch *gdbarch, struct value *function,
 			struct type *type, struct regcache *regcache,
 			gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   int fp_return_type = 0;
   int offset, regnum, xfer;
 
@@ -5195,7 +5195,7 @@ mips_n32n64_return_value (struct gdbarch *gdbarch, struct value *function,
 			  struct type *type, struct regcache *regcache,
 			  gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
   /* From MIPSpro N32 ABI Handbook, Document Number: 007-2816-004
 
@@ -5704,7 +5704,7 @@ mips_o32_return_value (struct gdbarch *gdbarch, struct value *function,
 {
   CORE_ADDR func_addr = function ? find_function_addr (function, NULL) : 0;
   int mips16 = mips_pc_is_mips16 (gdbarch, func_addr);
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   enum mips_fval_reg fval_reg;
 
   fval_reg = readbuf ? mips16 ? mips_fval_gpr : mips_fval_fpr : mips_fval_both;
@@ -8101,7 +8101,7 @@ mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   else if (arches != NULL)
     {
       mips_gdbarch_tdep *tdep
-	= (mips_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<mips_gdbarch_tdep> (arches->gdbarch);
       elf_flags = tdep->elf_flags;
     }
   else
@@ -8142,7 +8142,7 @@ mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   if (found_abi == MIPS_ABI_UNKNOWN && info.abfd == NULL && arches != NULL)
     {
       mips_gdbarch_tdep *tdep
-	= (mips_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<mips_gdbarch_tdep> (arches->gdbarch);
       found_abi = tdep->found_abi;
     }
 
@@ -8459,7 +8459,7 @@ mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       mips_gdbarch_tdep *tdep
-        = (mips_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+        = gdbarch_tdep<mips_gdbarch_tdep> (arches->gdbarch);
 
       /* MIPS needs to be pedantic about which ABI and the compressed
 	 ISA variation the object is using.  */
@@ -8917,7 +8917,7 @@ mips_fpu_type_str (enum mips_fpu_type fpu_type)
 static void
 mips_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   if (tdep != NULL)
     {
       int ef_mips_arch;
diff --git a/gdb/mn10300-tdep.c b/gdb/mn10300-tdep.c
index 7a41070bb30..22511d894d4 100644
--- a/gdb/mn10300-tdep.c
+++ b/gdb/mn10300-tdep.c
@@ -1412,7 +1412,7 @@ mn10300_gdbarch_init (struct gdbarch_info info,
 static void
 mn10300_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  mn10300_gdbarch_tdep *tdep = (mn10300_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mn10300_gdbarch_tdep *tdep = gdbarch_tdep<mn10300_gdbarch_tdep> (gdbarch);
   gdb_printf (file, "mn10300_dump_tdep: am33_mode = %d\n",
 	      tdep->am33_mode);
 }
diff --git a/gdb/mn10300-tdep.h b/gdb/mn10300-tdep.h
index 10fef99c5d7..87b861ead90 100644
--- a/gdb/mn10300-tdep.h
+++ b/gdb/mn10300-tdep.h
@@ -84,7 +84,7 @@ struct mn10300_gdbarch_tdep : gdbarch_tdep
 static inline int
 get_am33_mode (gdbarch *arch)
 {
-  mn10300_gdbarch_tdep *tdep = (mn10300_gdbarch_tdep *) gdbarch_tdep (arch);
+  mn10300_gdbarch_tdep *tdep = gdbarch_tdep<mn10300_gdbarch_tdep> (arch);
   return tdep->am33_mode;
 }
 
diff --git a/gdb/msp430-tdep.c b/gdb/msp430-tdep.c
index 28268a95139..4ae8b3d5626 100644
--- a/gdb/msp430-tdep.c
+++ b/gdb/msp430-tdep.c
@@ -341,7 +341,7 @@ msp430_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc,
   int rn;
   pv_t reg[MSP430_NUM_TOTAL_REGS];
   CORE_ADDR after_last_frame_setup_insn = start_pc;
-  msp430_gdbarch_tdep *tdep = (msp430_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  msp430_gdbarch_tdep *tdep = gdbarch_tdep<msp430_gdbarch_tdep> (gdbarch);
   int code_model = tdep->code_model;
   int sz;
 
@@ -570,7 +570,7 @@ msp430_return_value (struct gdbarch *gdbarch,
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   LONGEST valtype_len = TYPE_LENGTH (valtype);
-  msp430_gdbarch_tdep *tdep = (msp430_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  msp430_gdbarch_tdep *tdep = gdbarch_tdep<msp430_gdbarch_tdep> (gdbarch);
   int code_model = tdep->code_model;
 
   if (TYPE_LENGTH (valtype) > 8
@@ -651,7 +651,7 @@ msp430_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   int write_pass;
   int sp_off = 0;
   CORE_ADDR cfa;
-  msp430_gdbarch_tdep *tdep = (msp430_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  msp430_gdbarch_tdep *tdep = gdbarch_tdep<msp430_gdbarch_tdep> (gdbarch);
   int code_model = tdep->code_model;
 
   struct type *func_type = value_type (function);
@@ -814,7 +814,7 @@ msp430_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
 
   stub_name = bms.minsym->linkage_name ();
 
-  msp430_gdbarch_tdep *tdep = (msp430_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  msp430_gdbarch_tdep *tdep = gdbarch_tdep<msp430_gdbarch_tdep> (gdbarch);
   if (tdep->code_model == MSP_SMALL_CODE_MODEL
       && msp430_in_return_stub (gdbarch, pc, stub_name))
     {
@@ -877,7 +877,7 @@ msp430_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 	  if (ca && gdbarch_bfd_arch_info (ca)->arch == bfd_arch_msp430)
 	    {
 	      msp430_gdbarch_tdep *ca_tdep
-		= (msp430_gdbarch_tdep *) gdbarch_tdep (ca);
+		= gdbarch_tdep<msp430_gdbarch_tdep> (ca);
 
 	      elf_flags = ca_tdep->elf_flags;
 	      isa = ca_tdep->isa;
@@ -904,7 +904,7 @@ msp430_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       msp430_gdbarch_tdep *candidate_tdep
-	= (msp430_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<msp430_gdbarch_tdep> (arches->gdbarch);
 
       if (candidate_tdep->elf_flags != elf_flags
 	  || candidate_tdep->isa != isa
diff --git a/gdb/nds32-tdep.c b/gdb/nds32-tdep.c
index e95ad7cc662..11bfd2d1f54 100644
--- a/gdb/nds32-tdep.c
+++ b/gdb/nds32-tdep.c
@@ -289,7 +289,7 @@ typedef BP_MANIPULATION (nds32_break_insn) nds32_breakpoint;
 static int
 nds32_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int num)
 {
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   const int FSR = 38;
   const int FDR = FSR + 32;
 
@@ -432,7 +432,7 @@ nds32_pseudo_register_read (struct gdbarch *gdbarch,
 			    readable_regcache *regcache, int regnum,
 			    gdb_byte *buf)
 {
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   gdb_byte reg_buf[8];
   int offset, fdr_regnum;
   enum register_status status;
@@ -471,7 +471,7 @@ nds32_pseudo_register_write (struct gdbarch *gdbarch,
 			     struct regcache *regcache, int regnum,
 			     const gdb_byte *buf)
 {
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   gdb_byte reg_buf[8];
   int offset, fdr_regnum;
 
@@ -608,7 +608,7 @@ static CORE_ADDR
 nds32_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
 			CORE_ADDR limit_pc, struct nds32_frame_cache *cache)
 {
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   /* Current scanning status.  */
   int in_prologue_bb = 0;
@@ -1169,7 +1169,7 @@ static int
 nds32_analyze_epilogue (struct gdbarch *gdbarch, CORE_ADDR pc,
 			struct nds32_frame_cache *cache)
 {
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   CORE_ADDR limit_pc;
   uint32_t insn, insn_len;
@@ -1220,7 +1220,7 @@ nds32_analyze_epilogue (struct gdbarch *gdbarch, CORE_ADDR pc,
 static int
 nds32_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   int insn_type = INSN_NORMAL;
   int ret_found = 0;
@@ -1424,7 +1424,7 @@ nds32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   int i;
   ULONGEST regval;
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   struct type *func_type = value_type (function);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   int abi_split = nds32_abi_split (tdep->elf_abi);
@@ -1652,7 +1652,7 @@ nds32_extract_return_value (struct gdbarch *gdbarch, struct type *type,
 			    struct regcache *regcache, gdb_byte *valbuf)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   int calling_use_fpr;
   int len;
@@ -1742,7 +1742,7 @@ nds32_store_return_value (struct gdbarch *gdbarch, struct type *type,
 			  struct regcache *regcache, const gdb_byte *valbuf)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   int calling_use_fpr;
   int len;
@@ -1965,7 +1965,7 @@ nds32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
     {
       nds32_gdbarch_tdep *idep
-	= (nds32_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
+	= gdbarch_tdep<nds32_gdbarch_tdep> (best_arch->gdbarch);
 
       if (idep->elf_abi != elf_abi)
 	continue;
diff --git a/gdb/nios2-linux-tdep.c b/gdb/nios2-linux-tdep.c
index a32f79aa28a..da69638b20b 100644
--- a/gdb/nios2-linux-tdep.c
+++ b/gdb/nios2-linux-tdep.c
@@ -217,7 +217,7 @@ nios2_linux_is_kernel_helper (CORE_ADDR pc)
 static void
 nios2_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  nios2_gdbarch_tdep *tdep = (nios2_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nios2_gdbarch_tdep *tdep = gdbarch_tdep<nios2_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/nios2-tdep.c b/gdb/nios2-tdep.c
index 159d31b2d0f..0bad229b44a 100644
--- a/gdb/nios2-tdep.c
+++ b/gdb/nios2-tdep.c
@@ -2098,7 +2098,7 @@ static CORE_ADDR
 nios2_get_next_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  nios2_gdbarch_tdep *tdep = (nios2_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nios2_gdbarch_tdep *tdep = gdbarch_tdep<nios2_gdbarch_tdep> (gdbarch);
   unsigned long mach = gdbarch_bfd_arch_info (gdbarch)->mach;
   unsigned int insn;
   const struct nios2_opcode *op = nios2_fetch_insn (gdbarch, pc, &insn);
@@ -2221,7 +2221,7 @@ static int
 nios2_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  nios2_gdbarch_tdep *tdep = (nios2_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nios2_gdbarch_tdep *tdep = gdbarch_tdep<nios2_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR jb_addr = get_frame_register_unsigned (frame, NIOS2_R4_REGNUM);
   gdb_byte buf[4];
diff --git a/gdb/or1k-tdep.c b/gdb/or1k-tdep.c
index 2b906fa69d3..4699b755d42 100644
--- a/gdb/or1k-tdep.c
+++ b/gdb/or1k-tdep.c
@@ -248,7 +248,7 @@ or1k_return_value (struct gdbarch *gdbarch, struct value *functype,
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   enum type_code rv_type = valtype->code ();
   unsigned int rv_size = TYPE_LENGTH (valtype);
-  or1k_gdbarch_tdep *tdep = (or1k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  or1k_gdbarch_tdep *tdep = gdbarch_tdep<or1k_gdbarch_tdep> (gdbarch);
   int bpw = tdep->bytes_per_word;
 
   /* Deal with struct/union as addresses.  If an array won't fit in a
@@ -353,7 +353,7 @@ or1k_delay_slot_p (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
   const CGEN_INSN *insn;
   CGEN_FIELDS tmp_fields;
-  or1k_gdbarch_tdep *tdep = (or1k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  or1k_gdbarch_tdep *tdep = gdbarch_tdep<or1k_gdbarch_tdep> (gdbarch);
 
   insn = cgen_lookup_insn (tdep->gdb_cgen_cpu_desc,
 			   NULL,
@@ -635,7 +635,7 @@ or1k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   int heap_offset = 0;
   CORE_ADDR heap_sp = sp - 128;
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  or1k_gdbarch_tdep *tdep = (or1k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  or1k_gdbarch_tdep *tdep = gdbarch_tdep<or1k_gdbarch_tdep> (gdbarch);
   int bpa = tdep->bytes_per_address;
   int bpw = tdep->bytes_per_word;
   struct type *func_type = value_type (function);
@@ -1273,7 +1273,7 @@ or1k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 or1k_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  or1k_gdbarch_tdep *tdep = (or1k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  or1k_gdbarch_tdep *tdep = gdbarch_tdep<or1k_gdbarch_tdep> (gdbarch);
 
   if (NULL == tdep)
     return; /* Nothing to report */
diff --git a/gdb/ppc-fbsd-nat.c b/gdb/ppc-fbsd-nat.c
index ce045ac55ab..d0a5778e2d3 100644
--- a/gdb/ppc-fbsd-nat.c
+++ b/gdb/ppc-fbsd-nat.c
@@ -100,7 +100,7 @@ fill_fpregset (const struct regcache *regcache,
 static int
 getfpregs_supplies (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
 	 point registers.  Traditionally, GDB's register set has still
@@ -185,7 +185,7 @@ static int
 ppcfbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i, regnum;
 
   /* The stack pointer shouldn't be zero.  */
diff --git a/gdb/ppc-fbsd-tdep.c b/gdb/ppc-fbsd-tdep.c
index 4afcc3019a4..f5b482921a7 100644
--- a/gdb/ppc-fbsd-tdep.c
+++ b/gdb/ppc-fbsd-tdep.c
@@ -126,7 +126,7 @@ ppcfbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				      void *cb_data,
 				      const struct regcache *regcache)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (tdep->wordsize == 4)
     cb (".reg", 148, 148, &ppc32_fbsd_gregset, NULL, cb_data);
@@ -200,7 +200,7 @@ static struct trad_frame_cache *
 ppcfbsd_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   struct trad_frame_cache *cache;
   CORE_ADDR addr, base, func;
   gdb_byte buf[PPC_INSN_SIZE];
@@ -287,7 +287,7 @@ static CORE_ADDR
 ppcfbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 				  CORE_ADDR lm_addr, CORE_ADDR offset)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   struct regcache *regcache;
   int tp_offset, tp_regnum;
 
@@ -319,7 +319,7 @@ ppcfbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 static void
 ppcfbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support. */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c
index f959bb0c1ad..de4158c411a 100644
--- a/gdb/ppc-linux-nat.c
+++ b/gdb/ppc-linux-nat.c
@@ -649,7 +649,7 @@ static int
 ppc_register_u_addr (struct gdbarch *gdbarch, int regno)
 {
   int u_addr = -1;
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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 +802,7 @@ static void
 fetch_spe_register (struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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 +911,7 @@ static void
 fetch_register (struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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;
@@ -1156,7 +1156,7 @@ static void
 fetch_gp_regs (struct regcache *regcache, int tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   if (have_ptrace_getsetregs)
@@ -1208,7 +1208,7 @@ static void
 fetch_fp_regs (struct regcache *regcache, int tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   if (have_ptrace_getsetfpregs)
@@ -1226,7 +1226,7 @@ static void
 fetch_ppc_registers (struct regcache *regcache, int tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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 +1425,7 @@ static void
 store_spe_register (const struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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 +1477,7 @@ static void
 store_register (const struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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;
@@ -1718,7 +1718,7 @@ static void
 store_gp_regs (const struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   if (have_ptrace_getsetregs)
@@ -1780,7 +1780,7 @@ static void
 store_fp_regs (const struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   if (have_ptrace_getsetfpregs)
@@ -1798,7 +1798,7 @@ static void
 store_ppc_registers (const struct regcache *regcache, int tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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)
diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c
index 4c5f8b7a281..5a8ba239343 100644
--- a/gdb/ppc-linux-tdep.c
+++ b/gdb/ppc-linux-tdep.c
@@ -332,7 +332,7 @@ ppc_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
 {
   unsigned int insnbuf[POWERPC32_PLT_CHECK_LEN];
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR target = 0;
   int scan_limit, i;
@@ -898,7 +898,7 @@ ppc_linux_vsxregset (void)
 const struct regset *
 ppc_linux_cgprregset (struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (tdep->wordsize == 4)
     {
@@ -938,7 +938,7 @@ ppc_linux_collect_core_cpgrregset (const struct regset *regset,
 				   int regnum, void *buf, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   const struct regset *cgprregset = ppc_linux_cgprregset (gdbarch);
 
@@ -985,7 +985,7 @@ ppc_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					void *cb_data,
 					const struct regcache *regcache)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int have_altivec = tdep->ppc_vr0_regnum != -1;
   int have_vsx = tdep->ppc_vsr0_upper_regnum != -1;
   int have_ppr = tdep->ppc_ppr_regnum != -1;
@@ -1170,7 +1170,7 @@ ppc_linux_sigtramp_cache (struct frame_info *this_frame,
   CORE_ADDR fpregs;
   int i;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   base = get_frame_register_unsigned (this_frame,
@@ -1341,7 +1341,7 @@ ppc_linux_get_syscall_number (struct gdbarch *gdbarch,
 			      thread_info *thread)
 {
   struct regcache *regcache = get_thread_regcache (thread);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   /* Make sure we're in a 32- or 64-bit machine */
@@ -1417,7 +1417,7 @@ static int
 ppc_linux_syscall_record (struct regcache *regcache)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   ULONGEST scnum;
   enum gdb_syscall syscall_gdb;
   int ret;
@@ -1507,7 +1507,7 @@ ppc_linux_record_signal (struct gdbarch *gdbarch, struct regcache *regcache,
   const int SIGNAL_FRAMESIZE = 128;
   const int sizeof_rt_sigframe = 1440 * 2 + 8 * 2 + 4 * 6 + 8 + 8 + 128 + 512;
   ULONGEST sp;
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   for (i = 3; i <= 12; i++)
@@ -2036,7 +2036,7 @@ static void
 ppc_linux_init_abi (struct gdbarch_info info,
 		    struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   struct tdesc_arch_data *tdesc_data = info.tdesc_data;
   static const char *const stap_integer_prefixes[] = { "i", NULL };
   static const char *const stap_register_indirection_prefixes[] = { "(",
diff --git a/gdb/ppc-netbsd-nat.c b/gdb/ppc-netbsd-nat.c
index fb2dce501a4..91f18fbb83f 100644
--- a/gdb/ppc-netbsd-nat.c
+++ b/gdb/ppc-netbsd-nat.c
@@ -52,7 +52,7 @@ static ppc_nbsd_nat_target the_ppc_nbsd_nat_target;
 static int
 getregs_supplies (struct gdbarch *gdbarch, int regnum)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   return ((regnum >= tdep->ppc_gp0_regnum
 	   && regnum < tdep->ppc_gp0_regnum + ppc_num_gprs)
@@ -68,7 +68,7 @@ getregs_supplies (struct gdbarch *gdbarch, int regnum)
 static int
 getfpregs_supplies (struct gdbarch *gdbarch, int regnum)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
      point registers.  Traditionally, GDB's register set has still
@@ -159,7 +159,7 @@ ppcnbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
   struct switchframe sf;
   struct callframe cf;
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   /* The stack pointer shouldn't be zero.  */
diff --git a/gdb/ppc-netbsd-tdep.c b/gdb/ppc-netbsd-tdep.c
index cb3d8d5e5df..d8dc494979a 100644
--- a/gdb/ppc-netbsd-tdep.c
+++ b/gdb/ppc-netbsd-tdep.c
@@ -102,7 +102,7 @@ ppcnbsd_sigtramp_cache_init (const struct tramp_frame *self,
 			     CORE_ADDR func)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   CORE_ADDR addr, base;
   int i;
 
diff --git a/gdb/ppc-obsd-nat.c b/gdb/ppc-obsd-nat.c
index 93e1024b589..e480f19dc73 100644
--- a/gdb/ppc-obsd-nat.c
+++ b/gdb/ppc-obsd-nat.c
@@ -54,7 +54,7 @@ static ppc_obsd_nat_target the_ppc_obsd_nat_target;
 static int
 getfpregs_supplies (struct gdbarch *gdbarch, int regnum)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
      point registers.  Traditionally, GDB's register set has still
@@ -154,7 +154,7 @@ static int
 ppcobsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   struct switchframe sf;
   struct callframe cf;
   int i, regnum;
diff --git a/gdb/ppc-obsd-tdep.c b/gdb/ppc-obsd-tdep.c
index a2924e35bbc..90fb5e3a399 100644
--- a/gdb/ppc-obsd-tdep.c
+++ b/gdb/ppc-obsd-tdep.c
@@ -161,7 +161,7 @@ static struct trad_frame_cache *
 ppcobsd_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct trad_frame_cache *cache;
   CORE_ADDR addr, base, func;
diff --git a/gdb/ppc-sysv-tdep.c b/gdb/ppc-sysv-tdep.c
index 6c2fd1bfc99..ed6c2d4449d 100644
--- a/gdb/ppc-sysv-tdep.c
+++ b/gdb/ppc-sysv-tdep.c
@@ -65,7 +65,7 @@ ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 			      function_call_return_method return_method,
 			      CORE_ADDR struct_addr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int opencl_abi = ppc_sysv_use_opencl_abi (value_type (function));
   ULONGEST saved_sp;
@@ -597,7 +597,7 @@ get_decimal_float_return_value (struct gdbarch *gdbarch, struct type *valtype,
 				struct regcache *regcache, gdb_byte *readbuf,
 				const gdb_byte *writebuf)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   gdb_assert (valtype->code () == TYPE_CODE_DECFLOAT);
 
@@ -675,7 +675,7 @@ do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *func_type,
 			  gdb_byte *readbuf, const gdb_byte *writebuf,
 			  int broken_gcc)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int opencl_abi = func_type? ppc_sysv_use_opencl_abi (func_type) : 0;
 
@@ -1250,7 +1250,7 @@ ppc64_sysv_abi_push_val (struct gdbarch *gdbarch,
 			 const bfd_byte *val, int len, int align,
 			 struct ppc64_sysv_argpos *argpos)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int offset = 0;
 
   /* Enforce alignment of stack location, if requested.  */
@@ -1300,7 +1300,7 @@ static void
 ppc64_sysv_abi_push_integer (struct gdbarch *gdbarch, ULONGEST val,
 			     struct ppc64_sysv_argpos *argpos)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   gdb_byte buf[PPC_MAX_REGISTER_SIZE];
 
@@ -1318,7 +1318,7 @@ ppc64_sysv_abi_push_freg (struct gdbarch *gdbarch,
 			  struct type *type, const bfd_byte *val,
 			  struct ppc64_sysv_argpos *argpos)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   if (tdep->soft_float)
     return;
 
@@ -1403,7 +1403,7 @@ static void
 ppc64_sysv_abi_push_vreg (struct gdbarch *gdbarch, const bfd_byte *val,
 			  struct ppc64_sysv_argpos *argpos)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (argpos->regcache && argpos->vreg <= 13)
     argpos->regcache->cooked_write (tdep->ppc_vr0_regnum + argpos->vreg, val);
@@ -1419,7 +1419,7 @@ ppc64_sysv_abi_push_param (struct gdbarch *gdbarch,
 			   struct type *type, const bfd_byte *val,
 			   struct ppc64_sysv_argpos *argpos)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (type->code () == TYPE_CODE_FLT
       || type->code () == TYPE_CODE_DECFLOAT)
@@ -1545,7 +1545,7 @@ ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch,
 				CORE_ADDR struct_addr)
 {
   CORE_ADDR func_addr = find_function_addr (function, NULL);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int opencl_abi = ppc_sysv_use_opencl_abi (value_type (function));
   ULONGEST back_chain;
@@ -1739,7 +1739,7 @@ ppc64_sysv_abi_return_value_base (struct gdbarch *gdbarch, struct type *valtype,
 				  struct regcache *regcache, gdb_byte *readbuf,
 				  const gdb_byte *writebuf, int index)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* Integers live in GPRs starting at r3.  */
   if ((valtype->code () == TYPE_CODE_INT
@@ -1922,7 +1922,7 @@ ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct value *function,
 			     struct type *valtype, struct regcache *regcache,
 			     gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   struct type *func_type = function ? value_type (function) : NULL;
   int opencl_abi = func_type? ppc_sysv_use_opencl_abi (func_type) : 0;
   struct type *eltype;
diff --git a/gdb/ppc64-tdep.c b/gdb/ppc64-tdep.c
index 32931f72691..0437ca7e3f3 100644
--- a/gdb/ppc64-tdep.c
+++ b/gdb/ppc64-tdep.c
@@ -89,7 +89,7 @@ ppc64_plt_entry_point (struct frame_info *frame, CORE_ADDR plt_off)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   CORE_ADDR tocp;
 
   if (execution_direction == EXEC_REVERSE)
diff --git a/gdb/riscv-linux-tdep.c b/gdb/riscv-linux-tdep.c
index 387b8bdbc2f..5bda2e5c824 100644
--- a/gdb/riscv-linux-tdep.c
+++ b/gdb/riscv-linux-tdep.c
@@ -179,7 +179,7 @@ riscv_linux_syscall_next_pc (struct frame_info *frame)
 static void
 riscv_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
index 69f2123dcdb..2d41be96b20 100644
--- a/gdb/riscv-tdep.c
+++ b/gdb/riscv-tdep.c
@@ -733,7 +733,7 @@ show_riscv_debug_variable (struct ui_file *file, int from_tty,
 int
 riscv_isa_xlen (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   return tdep->isa_features.xlen;
 }
 
@@ -742,7 +742,7 @@ riscv_isa_xlen (struct gdbarch *gdbarch)
 int
 riscv_abi_xlen (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   return tdep->abi_features.xlen;
 }
 
@@ -751,7 +751,7 @@ riscv_abi_xlen (struct gdbarch *gdbarch)
 int
 riscv_isa_flen (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   return tdep->isa_features.flen;
 }
 
@@ -760,7 +760,7 @@ riscv_isa_flen (struct gdbarch *gdbarch)
 int
 riscv_abi_flen (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   return tdep->abi_features.flen;
 }
 
@@ -769,7 +769,7 @@ riscv_abi_flen (struct gdbarch *gdbarch)
 bool
 riscv_abi_embedded (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   return tdep->abi_features.embedded;
 }
 
@@ -786,7 +786,7 @@ riscv_has_fp_regs (struct gdbarch *gdbarch)
 static bool
 riscv_has_fp_abi (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   return tdep->abi_features.flen > 0;
 }
 
@@ -910,7 +910,7 @@ riscv_register_name (struct gdbarch *gdbarch, int regnum)
      will show up in 'info register all'.  Unless, we identify the
      duplicate copies of these registers (in riscv_tdesc_unknown_reg) and
      then hide the registers here by giving them no name.  */
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   if (tdep->duplicate_fflags_regnum == regnum)
     return NULL;
   if (tdep->duplicate_frm_regnum == regnum)
@@ -938,7 +938,7 @@ riscv_register_name (struct gdbarch *gdbarch, int regnum)
 static struct type *
 riscv_fpreg_d_type (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
 
   if (tdep->riscv_fpreg_d_type == nullptr)
     {
@@ -1260,7 +1260,7 @@ riscv_is_regnum_a_named_csr (int regnum)
 static bool
 riscv_is_unknown_csr (struct gdbarch *gdbarch, int regnum)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   return (regnum >= tdep->unknown_csrs_first_regnum
 	  && regnum < (tdep->unknown_csrs_first_regnum
 		       + tdep->unknown_csrs_count));
@@ -3600,7 +3600,7 @@ riscv_tdesc_unknown_reg (struct gdbarch *gdbarch, tdesc_feature *feature,
      record their register numbers here.  */
   if (strcmp (tdesc_feature_name (feature), riscv_freg_feature.name ()) == 0)
     {
-      riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
       int *regnum_ptr = nullptr;
 
       if (strcmp (reg_name, "fflags") == 0)
@@ -3631,7 +3631,7 @@ riscv_tdesc_unknown_reg (struct gdbarch *gdbarch, tdesc_feature *feature,
      about register groups in riscv_register_reggroup_p.  */
   if (strcmp (tdesc_feature_name (feature), riscv_csr_feature.name ()) == 0)
     {
-      riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
       if (tdep->unknown_csrs_first_regnum == -1)
 	tdep->unknown_csrs_first_regnum = possible_regnum;
       gdb_assert (tdep->unknown_csrs_first_regnum
@@ -3733,7 +3733,7 @@ riscv_gdbarch_init (struct gdbarch_info info,
 	 we are looking for.  If it doesn't then we can't reuse this
 	 gdbarch.  */
       riscv_gdbarch_tdep *other_tdep
-	= (riscv_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<riscv_gdbarch_tdep> (arches->gdbarch);
 
       if (other_tdep->isa_features != features
 	  || other_tdep->abi_features != abi_features)
@@ -3858,7 +3858,7 @@ riscv_next_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   struct gdbarch *gdbarch = regcache->arch ();
   const riscv_gdbarch_tdep *tdep
-    = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+    = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   struct riscv_insn insn;
   CORE_ADDR next_pc;
 
diff --git a/gdb/rl78-tdep.c b/gdb/rl78-tdep.c
index 6ea0473081d..2462e7a191d 100644
--- a/gdb/rl78-tdep.c
+++ b/gdb/rl78-tdep.c
@@ -267,7 +267,7 @@ struct rl78_prologue
 static struct type *
 rl78_psw_type (struct gdbarch *gdbarch)
 {
-  rl78_gdbarch_tdep *tdep = (rl78_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  rl78_gdbarch_tdep *tdep = gdbarch_tdep<rl78_gdbarch_tdep> (gdbarch);
 
   if (tdep->rl78_psw_type == NULL)
     {
@@ -291,7 +291,7 @@ rl78_psw_type (struct gdbarch *gdbarch)
 static struct type *
 rl78_register_type (struct gdbarch *gdbarch, int reg_nr)
 {
-  rl78_gdbarch_tdep *tdep = (rl78_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  rl78_gdbarch_tdep *tdep = gdbarch_tdep<rl78_gdbarch_tdep> (gdbarch);
 
   if (reg_nr == RL78_PC_REGNUM)
     return tdep->rl78_code_pointer;
@@ -1248,7 +1248,7 @@ rl78_return_value (struct gdbarch *gdbarch,
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   ULONGEST valtype_len = TYPE_LENGTH (valtype);
-  rl78_gdbarch_tdep *tdep = (rl78_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  rl78_gdbarch_tdep *tdep = gdbarch_tdep<rl78_gdbarch_tdep> (gdbarch);
   int is_g10 = tdep->elf_flags & E_FLAG_RL78_G10;
 
   if (valtype_len > 8)
@@ -1394,7 +1394,7 @@ rl78_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       rl78_gdbarch_tdep *tdep
-	= (rl78_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<rl78_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->elf_flags != elf_flags)
 	continue;
diff --git a/gdb/rs6000-aix-nat.c b/gdb/rs6000-aix-nat.c
index 8563aea313a..8697d27b4ed 100644
--- a/gdb/rs6000-aix-nat.c
+++ b/gdb/rs6000-aix-nat.c
@@ -115,7 +115,7 @@ static rs6000_nat_target the_rs6000_nat_target;
 static int
 regmap (struct gdbarch *gdbarch, int regno, int *isfloat)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   *isfloat = 0;
   if (tdep->ppc_gp0_regnum <= regno
@@ -317,7 +317,7 @@ rs6000_nat_target::fetch_registers (struct regcache *regcache, int regno)
 
   else
     {
-      ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
       /* Read 32 general purpose registers.  */
       for (regno = tdep->ppc_gp0_regnum;
@@ -359,7 +359,7 @@ rs6000_nat_target::store_registers (struct regcache *regcache, int regno)
 
   else
     {
-      ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
       /* Write general purpose registers first.  */
       for (regno = tdep->ppc_gp0_regnum;
diff --git a/gdb/rs6000-aix-tdep.c b/gdb/rs6000-aix-tdep.c
index 867f21dc634..41384993c26 100644
--- a/gdb/rs6000-aix-tdep.c
+++ b/gdb/rs6000-aix-tdep.c
@@ -75,7 +75,7 @@ aix_sighandle_frame_cache (struct frame_info *this_frame,
   LONGEST backchain;
   CORE_ADDR base, base_orig, func;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct trad_frame_cache *this_trad_cache;
 
@@ -261,7 +261,7 @@ rs6000_aix_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					 void *cb_data,
 					 const struct regcache *regcache)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   if (tdep->wordsize == 4)
     cb (".reg", 592, 592, &rs6000_aix32_regset, NULL, cb_data);
   else
@@ -292,7 +292,7 @@ rs6000_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 			function_call_return_method return_method,
 			CORE_ADDR struct_addr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int ii;
   int len = 0;
@@ -522,7 +522,7 @@ rs6000_return_value (struct gdbarch *gdbarch, struct value *function,
 		     struct type *valtype, struct regcache *regcache,
 		     gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   /* The calling convention this function implements assumes the
@@ -660,7 +660,7 @@ rs6000_convert_from_func_ptr_addr (struct gdbarch *gdbarch,
 				   CORE_ADDR addr,
 				   struct target_ops *targ)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct obj_section *s;
 
@@ -704,7 +704,7 @@ branch_dest (struct regcache *regcache, int opcode, int instr,
 	     CORE_ADDR pc, CORE_ADDR safety)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR dest;
   int immediate;
@@ -972,7 +972,7 @@ static struct ld_info
 rs6000_aix_extract_ld_info (struct gdbarch *gdbarch,
 			    const gdb_byte *ldi_buf)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
   const struct ld_info_desc desc
@@ -1131,7 +1131,7 @@ rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch,
 static void
 rs6000_aix_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* RS6000/AIX does not support PT_STEP.  Has to be simulated.  */
   set_gdbarch_software_single_step (gdbarch, rs6000_software_single_step);
diff --git a/gdb/rs6000-lynx178-tdep.c b/gdb/rs6000-lynx178-tdep.c
index 844d0a4ede2..dc13dd3fa73 100644
--- a/gdb/rs6000-lynx178-tdep.c
+++ b/gdb/rs6000-lynx178-tdep.c
@@ -36,7 +36,7 @@ rs6000_lynx178_push_dummy_call (struct gdbarch *gdbarch,
 				function_call_return_method return_method,
 				CORE_ADDR struct_addr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int ii;
   int len = 0;
@@ -265,7 +265,7 @@ rs6000_lynx178_return_value (struct gdbarch *gdbarch, struct value *function,
 			     struct type *valtype, struct regcache *regcache,
 			     gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   /* The calling convention this function implements assumes the
diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
index 6815dfaa820..640459f1c28 100644
--- a/gdb/rs6000-tdep.c
+++ b/gdb/rs6000-tdep.c
@@ -201,7 +201,7 @@ struct rs6000_framedata
 int
 vsx_register_p (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   if (tdep->ppc_vsr0_regnum < 0)
     return 0;
   else
@@ -213,7 +213,7 @@ vsx_register_p (struct gdbarch *gdbarch, int regno)
 int
 altivec_register_p (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   if (tdep->ppc_vr0_regnum < 0 || tdep->ppc_vrsave_regnum < 0)
     return 0;
   else
@@ -225,7 +225,7 @@ altivec_register_p (struct gdbarch *gdbarch, int regno)
 int
 spe_register_p (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   
   /* Is it a reference to EV0 -- EV31, and do we have those?  */
   if (IS_SPE_PSEUDOREG (tdep, regno))
@@ -257,7 +257,7 @@ spe_register_p (struct gdbarch *gdbarch, int regno)
 int
 ppc_floating_point_unit_p (struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   return (tdep->ppc_fp0_regnum >= 0
 	  && tdep->ppc_fpscr_regnum >= 0);
@@ -268,7 +268,7 @@ ppc_floating_point_unit_p (struct gdbarch *gdbarch)
 int
 ppc_altivec_support_p (struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   return (tdep->ppc_vr0_regnum >= 0
 	  && tdep->ppc_vrsave_regnum >= 0);
@@ -297,7 +297,7 @@ set_sim_regno (int *table, int gdb_regno, int sim_regno)
 static void
 init_sim_regno_table (struct gdbarch *arch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (arch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (arch);
   int total_regs = gdbarch_num_regs (arch);
   int *sim_regno = GDBARCH_OBSTACK_CALLOC (arch, total_regs, int);
   int i;
@@ -391,7 +391,7 @@ init_sim_regno_table (struct gdbarch *arch)
 static int
 rs6000_register_sim_regno (struct gdbarch *gdbarch, int reg)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int sim_regno;
 
   if (tdep->sim_regno == NULL)
@@ -522,7 +522,7 @@ ppc_supply_gregset (const struct regset *regset, struct regcache *regcache,
 		    int regnum, const void *gregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   const struct ppc_reg_offsets *offsets
     = (const struct ppc_reg_offsets *) regset->regmap;
   size_t offset;
@@ -578,7 +578,7 @@ ppc_supply_fpregset (const struct regset *regset, struct regcache *regcache,
   if (!ppc_floating_point_unit_p (gdbarch))
     return;
 
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   offsets = (const struct ppc_reg_offsets *) regset->regmap;
   if (regnum == -1)
     {
@@ -611,7 +611,7 @@ ppc_collect_gregset (const struct regset *regset,
 		     int regnum, void *gregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   const struct ppc_reg_offsets *offsets
     = (const struct ppc_reg_offsets *) regset->regmap;
   size_t offset;
@@ -668,7 +668,7 @@ ppc_collect_fpregset (const struct regset *regset,
   if (!ppc_floating_point_unit_p (gdbarch))
     return;
 
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   offsets = (const struct ppc_reg_offsets *) regset->regmap;
   if (regnum == -1)
     {
@@ -746,7 +746,7 @@ static int
 rs6000_in_function_epilogue_frame_p (struct frame_info *curfrm,
 				     struct gdbarch *gdbarch, CORE_ADDR pc)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   bfd_byte insn_buf[PPC_INSN_SIZE];
   CORE_ADDR scan_pc, func_start, func_end, epilogue_start, epilogue_end;
@@ -1042,7 +1042,7 @@ ppc_displaced_step_fixup (struct gdbarch *gdbarch,
       if (insn & 0x1)
 	{
 	  /* Link register needs to be set to the next instruction's PC.  */
-	  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 	  regcache_cooked_write_unsigned (regs,
 					  tdep->ppc_lr_regnum,
 					  from + PPC_INSN_SIZE);
@@ -1590,7 +1590,7 @@ skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc, CORE_ADDR lim_pc,
   int num_skip_non_prologue_insns = 0;
   int r0_contains_arg = 0;
   const struct bfd_arch_info *arch_info = gdbarch_bfd_arch_info (gdbarch);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   memset (fdata, 0, sizeof (struct rs6000_framedata));
@@ -2310,7 +2310,7 @@ static CORE_ADDR
 rs6000_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   unsigned int ii, op;
   int rel;
@@ -2368,7 +2368,7 @@ rs6000_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
 static struct type *
 rs6000_builtin_type_vec64 (struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->ppc_builtin_type_vec64)
     {
@@ -2413,7 +2413,7 @@ rs6000_builtin_type_vec64 (struct gdbarch *gdbarch)
 static struct type *
 rs6000_builtin_type_vec128 (struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->ppc_builtin_type_vec128)
     {
@@ -2467,7 +2467,7 @@ rs6000_builtin_type_vec128 (struct gdbarch *gdbarch)
 static const char *
 rs6000_register_name (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* The upper half "registers" have names in the XML description,
      but we present only the low GPRs and the full 64-bit registers
@@ -2605,7 +2605,7 @@ rs6000_register_name (struct gdbarch *gdbarch, int regno)
 static struct type *
 rs6000_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* These are the e500 pseudo-registers.  */
   if (IS_SPE_PSEUDOREG (tdep, regnum))
@@ -2644,7 +2644,7 @@ static int
 rs6000_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 				   const struct reggroup *group)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (IS_V_ALIAS_PSEUDOREG (tdep, regnum))
     return 0;
@@ -2659,7 +2659,7 @@ static int
 rs6000_convert_register_p (struct gdbarch *gdbarch, int regnum,
 			   struct type *type)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   return (tdep->ppc_fp0_regnum >= 0
 	  && regnum >= tdep->ppc_fp0_regnum
@@ -2744,7 +2744,7 @@ e500_move_ev_register (move_ev_register_func move,
 		       struct regcache *regcache, int ev_reg, void *buffer)
 {
   struct gdbarch *arch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (arch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (arch);
   int reg_index;
   gdb_byte *byte_buffer = (gdb_byte *) buffer;
   enum register_status status;
@@ -2785,7 +2785,7 @@ e500_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int ev_reg, gdb_byte *buffer)
 {
   struct gdbarch *arch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index;
   enum register_status status;
 
@@ -2826,7 +2826,7 @@ static enum register_status
 dfp_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int reg_nr, gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, fp0;
   enum register_status status;
 
@@ -2866,7 +2866,7 @@ static void
 dfp_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
 			    int reg_nr, const gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, fp0;
 
   if (IS_DFP_PSEUDOREG (tdep, reg_nr))
@@ -2903,7 +2903,7 @@ v_alias_pseudo_register_read (struct gdbarch *gdbarch,
 			      readable_regcache *regcache, int reg_nr,
 			      gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   gdb_assert (IS_V_ALIAS_PSEUDOREG (tdep, reg_nr));
 
   return regcache->raw_read (tdep->ppc_vr0_regnum
@@ -2918,7 +2918,7 @@ v_alias_pseudo_register_write (struct gdbarch *gdbarch,
 			       struct regcache *regcache,
 			       int reg_nr, const gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   gdb_assert (IS_V_ALIAS_PSEUDOREG (tdep, reg_nr));
 
   regcache->raw_write (tdep->ppc_vr0_regnum
@@ -2930,7 +2930,7 @@ static enum register_status
 vsx_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int reg_nr, gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0, fp0, vsr0_upper;
   enum register_status status;
 
@@ -2978,7 +2978,7 @@ static void
 vsx_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
 			    int reg_nr, const gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0, fp0, vsr0_upper;
 
   if (IS_VSX_PSEUDOREG (tdep, reg_nr))
@@ -3020,7 +3020,7 @@ static enum register_status
 efp_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int reg_nr, gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0;
 
   if (IS_EFP_PSEUDOREG (tdep, reg_nr))
@@ -3049,7 +3049,7 @@ static void
 efp_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
 			    int reg_nr, const gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0;
   int offset = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG ? 0 : 8;
 
@@ -3085,7 +3085,7 @@ rs6000_pseudo_register_read (struct gdbarch *gdbarch,
 			     int reg_nr, gdb_byte *buffer)
 {
   struct gdbarch *regcache_arch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   gdb_assert (regcache_arch == gdbarch);
 
@@ -3116,7 +3116,7 @@ rs6000_pseudo_register_write (struct gdbarch *gdbarch,
 			      int reg_nr, const gdb_byte *buffer)
 {
   struct gdbarch *regcache_arch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   gdb_assert (regcache_arch == gdbarch);
 
@@ -3147,7 +3147,7 @@ static void
 dfp_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				struct agent_expr *ax, int reg_nr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, fp0;
 
   if (IS_DFP_PSEUDOREG (tdep, reg_nr))
@@ -3174,7 +3174,7 @@ static void
 v_alias_pseudo_register_collect (struct gdbarch *gdbarch,
 				 struct agent_expr *ax, int reg_nr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   gdb_assert (IS_V_ALIAS_PSEUDOREG (tdep, reg_nr));
 
   ax_reg_mask (ax, tdep->ppc_vr0_regnum
@@ -3188,7 +3188,7 @@ static void
 vsx_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				struct agent_expr *ax, int reg_nr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0, fp0, vsr0_upper;
 
   if (IS_VSX_PSEUDOREG (tdep, reg_nr))
@@ -3226,7 +3226,7 @@ static void
 efp_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				struct agent_expr *ax, int reg_nr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0;
 
   if (IS_EFP_PSEUDOREG (tdep, reg_nr))
@@ -3249,7 +3249,7 @@ static int
 rs6000_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				   struct agent_expr *ax, int reg_nr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   if (IS_SPE_PSEUDOREG (tdep, reg_nr))
     {
       int reg_index = reg_nr - tdep->ppc_ev0_regnum;
@@ -3289,7 +3289,7 @@ rs6000_gen_return_address (struct gdbarch *gdbarch,
 			   struct agent_expr *ax, struct axs_value *value,
 			   CORE_ADDR scope)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   value->type = register_type (gdbarch, tdep->ppc_lr_regnum);
   value->kind = axs_lvalue_register;
   value->u.reg = tdep->ppc_lr_regnum;
@@ -3300,7 +3300,7 @@ rs6000_gen_return_address (struct gdbarch *gdbarch,
 static int
 rs6000_stab_reg_to_regnum (struct gdbarch *gdbarch, int num)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (0 <= num && num <= 31)
     return tdep->ppc_gp0_regnum + num;
@@ -3342,7 +3342,7 @@ rs6000_stab_reg_to_regnum (struct gdbarch *gdbarch, int num)
 static int
 rs6000_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int num)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (0 <= num && num <= 31)
     return tdep->ppc_gp0_regnum + num;
@@ -3561,7 +3561,7 @@ rs6000_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct rs6000_frame_cache *cache;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct rs6000_framedata fdata;
   int wordsize = tdep->wordsize;
@@ -3797,7 +3797,7 @@ rs6000_epilogue_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct rs6000_frame_cache *cache;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (*this_cache)
     return (struct rs6000_frame_cache *) *this_cache;
@@ -3918,7 +3918,7 @@ ppc_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
 			    struct dwarf2_frame_state_reg *reg,
 			    struct frame_info *this_frame)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* PPC32 and PPC64 ABI's are the same regarding volatile and
      non-volatile registers.  We will use the same code for both.  */
@@ -4229,7 +4229,7 @@ static int
 ppc_process_record_op4 (struct gdbarch *gdbarch, struct regcache *regcache,
 			CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_FIELD (insn, 21, 11);
   int vra = PPC_FIELD (insn, 11, 5);
 
@@ -4771,7 +4771,7 @@ static int
 ppc_process_record_op6 (struct gdbarch *gdbarch, struct regcache *regcache,
 			CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int subtype = PPC_FIELD (insn, 28, 4);
   CORE_ADDR ea = 0;
 
@@ -4799,7 +4799,7 @@ static int
 ppc_process_record_op19 (struct gdbarch *gdbarch, struct regcache *regcache,
 			   CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_EXTOP (insn);
 
   switch (ext & 0x01f)
@@ -4855,7 +4855,7 @@ ppc_process_record_op31_177 (struct gdbarch *gdbarch,
 {
   int RA_opcode = PPC_RA(insn);
   int as = PPC_FIELD (insn, 6, 3);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   switch (RA_opcode)
     {
@@ -4875,7 +4875,7 @@ static int
 ppc_process_record_op31 (struct gdbarch *gdbarch, struct regcache *regcache,
 			   CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_EXTOP (insn);
   int tmp, nr, nb = 0, i;
   CORE_ADDR at_dcsz, ea = 0;
@@ -5536,7 +5536,7 @@ static int
 ppc_process_record_op59 (struct gdbarch *gdbarch, struct regcache *regcache,
 			 CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_EXTOP (insn);
   int at = PPC_FIELD (insn, 6, 3);
 
@@ -5701,7 +5701,7 @@ ppc_process_record_op60_XX2 (struct gdbarch *gdbarch,
 			     struct regcache *regcache,
 			     CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int RA_opcode = PPC_RA(insn);
 
   switch (RA_opcode)
@@ -5742,7 +5742,7 @@ static int
 ppc_process_record_op60 (struct gdbarch *gdbarch, struct regcache *regcache,
 			   CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_EXTOP (insn);
 
   switch (ext >> 2)
@@ -6097,7 +6097,7 @@ static int
 ppc_process_record_op61 (struct gdbarch *gdbarch, struct regcache *regcache,
 			   CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   ULONGEST ea = 0;
   int size;
 
@@ -6156,7 +6156,7 @@ static int
 ppc_process_record_op63 (struct gdbarch *gdbarch, struct regcache *regcache,
 			   CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_EXTOP (insn);
   int tmp;
 
@@ -6453,7 +6453,7 @@ ppc_process_record_prefix_op42 (struct gdbarch *gdbarch,
 				struct regcache *regcache,
 				uint32_t insn_prefix, uint32_t insn_suffix)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST1 = PPC_FIELD (insn_prefix, 8, 1);
 
@@ -6489,7 +6489,7 @@ ppc_process_record_prefix_op59_XX3 (struct gdbarch *gdbarch,
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST4 = PPC_FIELD (insn_prefix, 8, 4);
   int at = PPC_FIELD (insn_suffix, 6, 3);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (type == 3)
     {
@@ -6603,7 +6603,7 @@ ppc_process_record_prefix_store (struct gdbarch *gdbarch,
 				 CORE_ADDR addr, uint32_t insn_prefix,
 				 uint32_t insn_suffix)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   ULONGEST iaddr = 0;
   int size;
   int R = PPC_BIT (insn_prefix, 11);
@@ -6659,7 +6659,7 @@ ppc_process_record_prefix_op32 (struct gdbarch *gdbarch,
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST1 = PPC_FIELD (insn_prefix, 8, 1);
   int ST4 = PPC_FIELD (insn_prefix, 8, 4);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (type == 1)
     {
@@ -6713,7 +6713,7 @@ ppc_process_record_prefix_op33 (struct gdbarch *gdbarch,
 {
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST4 = PPC_FIELD (insn_prefix, 8, 4);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (type == 1)
     {
@@ -6751,7 +6751,7 @@ ppc_process_record_prefix_op34 (struct gdbarch *gdbarch,
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST1 = PPC_FIELD (insn_prefix, 8, 1);
   int ST4 = PPC_FIELD (insn_prefix, 8, 4);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (type == 1)
     {
@@ -6797,7 +6797,7 @@ ppc_process_record_prefix_store_vsx_ds_form (struct gdbarch *gdbarch,
 					     uint32_t insn_prefix,
 					     uint32_t insn_suffix)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   ULONGEST ea = 0;
   int size;
   int R = PPC_BIT (insn_prefix, 11);
@@ -6850,7 +6850,7 @@ ppc_process_record_prefix_vsx_d_form (struct gdbarch *gdbarch,
 				      uint32_t insn_prefix,
 				      uint32_t insn_suffix)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   ULONGEST ea = 0;
   int size;
   int R = PPC_BIT (insn_prefix, 11);
@@ -6907,7 +6907,7 @@ ppc_process_prefix_instruction (int insn_prefix, int insn_suffix,
 {
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST1 = PPC_FIELD (insn_prefix, 8, 1);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int op6;
 
   /* D-form has uses a 5-bit opcode in the instruction suffix */
@@ -7086,7 +7086,7 @@ int
 ppc_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
 		      CORE_ADDR addr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   uint32_t insn, insn_suffix;
   int op6, tmp, i;
@@ -8150,7 +8150,7 @@ rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 	 meaningful, because 64-bit CPUs can run in 32-bit mode.  So, perform
 	 separate word size check.  */
       ppc_gdbarch_tdep *tdep
-	= (ppc_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<ppc_gdbarch_tdep> (arches->gdbarch);
       if (tdep && tdep->elf_abi != elf_abi)
 	continue;
       if (tdep && tdep->soft_float != soft_float)
@@ -8452,7 +8452,7 @@ rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 rs6000_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (tdep == NULL)
     return;
diff --git a/gdb/rx-tdep.c b/gdb/rx-tdep.c
index 2a24ebba2b6..c67d4057195 100644
--- a/gdb/rx-tdep.c
+++ b/gdb/rx-tdep.c
@@ -964,7 +964,7 @@ rx_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       rx_gdbarch_tdep *tdep
-	= (rx_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<rx_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->elf_flags != elf_flags)
 	continue;
diff --git a/gdb/s390-linux-tdep.c b/gdb/s390-linux-tdep.c
index 9d4e2d09f2a..03611fe1d23 100644
--- a/gdb/s390-linux-tdep.c
+++ b/gdb/s390-linux-tdep.c
@@ -79,7 +79,7 @@ static void
 s390_write_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
 
@@ -269,7 +269,7 @@ s390_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				   void *cb_data,
 				   const struct regcache *regcache)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   const int gregset_size = (tdep->abi == ABI_LINUX_S390 ?
 			    s390_sizeof_gregset : s390x_sizeof_gregset);
 
@@ -390,7 +390,7 @@ s390_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
 				  void **this_prologue_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   int word_size = gdbarch_ptr_bit (gdbarch) / 8;
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct s390_sigtramp_unwind_cache *info;
@@ -561,7 +561,7 @@ s390_linux_get_syscall_number (struct gdbarch *gdbarch,
 			       thread_info *thread)
 {
   struct regcache *regs = get_thread_regcache (thread);
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   ULONGEST pc;
   ULONGEST svc_number = -1;
@@ -594,7 +594,7 @@ static int
 s390_all_but_pc_registers_record (struct regcache *regcache)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   int i;
 
   for (i = 0; i < 16; i++)
@@ -802,7 +802,7 @@ static int
 s390_linux_syscall_record (struct regcache *regcache, LONGEST syscall_native)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   int ret;
   enum gdb_syscall syscall_gdb;
 
@@ -853,7 +853,7 @@ static int
 s390_linux_record_signal (struct gdbarch *gdbarch, struct regcache *regcache,
 			  enum gdb_signal signal)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   /* There are two kinds of signal frames on s390. rt_sigframe is always
      the larger one, so don't even bother with sigframe.  */
   const int sizeof_rt_sigframe = (tdep->abi == ABI_LINUX_ZSERIES ?
@@ -1117,7 +1117,7 @@ s390_init_linux_record_tdep (struct linux_record_tdep *record_tdep,
 static void
 s390_linux_init_abi_any (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   tdep->s390_syscall_record = s390_linux_syscall_record;
 
@@ -1152,7 +1152,7 @@ s390_linux_init_abi_any (struct gdbarch_info info, struct gdbarch *gdbarch)
 static void
 s390_linux_init_abi_31 (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   tdep->abi = ABI_LINUX_S390;
 
@@ -1168,7 +1168,7 @@ s390_linux_init_abi_31 (struct gdbarch_info info, struct gdbarch *gdbarch)
 static void
 s390_linux_init_abi_64 (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   tdep->abi = ABI_LINUX_ZSERIES;
 
diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c
index 14b03a167d7..2aeb3a14637 100644
--- a/gdb/s390-tdep.c
+++ b/gdb/s390-tdep.c
@@ -1045,7 +1045,7 @@ s390_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
 static int
 s390_register_call_saved (struct gdbarch *gdbarch, int regnum)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   switch (tdep->abi)
     {
@@ -1076,7 +1076,7 @@ s390_guess_tracepoint_registers (struct gdbarch *gdbarch,
 				 struct regcache *regcache,
 				 CORE_ADDR addr)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   int sz = register_size (gdbarch, S390_PSWA_REGNUM);
   gdb_byte *reg = (gdb_byte *) alloca (sz);
   ULONGEST pswm, pswa;
@@ -1172,7 +1172,7 @@ enum { s390_dwarf_reg_r0l = ARRAY_SIZE (s390_dwarf_regmap) - 16 };
 static int
 s390_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   int gdb_reg = -1;
 
   /* In a 32-on-64 debug scenario, debug info refers to the full
@@ -1231,7 +1231,7 @@ static struct value *
 s390_value_from_register (struct gdbarch *gdbarch, struct type *type,
 			  int regnum, struct frame_id frame_id)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   struct value *value = default_value_from_register (gdbarch, type,
 						     regnum, frame_id);
   check_typedef (type);
@@ -1250,7 +1250,7 @@ s390_value_from_register (struct gdbarch *gdbarch, struct type *type,
 static const char *
 s390_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   if (regnum == tdep->pc_regnum)
     return "pc";
@@ -1284,7 +1284,7 @@ s390_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 static struct type *
 s390_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   if (regnum == tdep->pc_regnum)
     return builtin_type (gdbarch)->builtin_func_ptr;
@@ -1308,7 +1308,7 @@ static enum register_status
 s390_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int regnum, gdb_byte *buf)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int regsize = register_size (gdbarch, regnum);
   ULONGEST val;
@@ -1383,7 +1383,7 @@ static void
 s390_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
 			    int regnum, const gdb_byte *buf)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int regsize = register_size (gdbarch, regnum);
   ULONGEST val, psw;
@@ -1442,7 +1442,7 @@ static int
 s390_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 				 const struct reggroup *group)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   /* We usually save/restore the whole PSW, which includes PC and CC.
      However, some older gdbservers may not support saving/restoring
@@ -1470,7 +1470,7 @@ static int
 s390_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				 struct agent_expr *ax, int regnum)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   if (regnum == tdep->pc_regnum)
     {
       ax_reg_mask (ax, S390_PSWA_REGNUM);
@@ -1504,7 +1504,7 @@ static int
 s390_ax_pseudo_register_push_stack (struct gdbarch *gdbarch,
 				    struct agent_expr *ax, int regnum)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   if (regnum == tdep->pc_regnum)
     {
       ax_reg (ax, S390_PSWA_REGNUM);
@@ -1905,7 +1905,7 @@ s390_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 		      function_call_return_method return_method,
 		      CORE_ADDR struct_addr)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   int word_size = gdbarch_ptr_bit (gdbarch) / 8;
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int i;
@@ -2084,7 +2084,7 @@ s390_return_value (struct gdbarch *gdbarch, struct value *function,
       break;
     case TYPE_CODE_ARRAY:
       {
-	s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 	rvc = (tdep->vector_abi == S390_VECTOR_ABI_128
 	       && TYPE_LENGTH (type) <= 16 && type->is_vector ())
 	  ? RETURN_VALUE_REGISTER_CONVENTION
@@ -2168,7 +2168,7 @@ s390_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
 static CORE_ADDR
 s390_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   ULONGEST pc;
   pc = frame_unwind_register_unsigned (next_frame, tdep->pc_regnum);
   return gdbarch_addr_bits_remove (gdbarch, pc);
@@ -2190,7 +2190,7 @@ static struct value *
 s390_unwind_pseudo_register (struct frame_info *this_frame, int regnum)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   struct type *type = register_type (gdbarch, regnum);
 
   /* Unwind PC via PSW address.  */
@@ -2775,7 +2775,7 @@ static CORE_ADDR
 s390_record_address_mask (struct gdbarch *gdbarch, struct regcache *regcache,
 			  CORE_ADDR val)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   ULONGEST pswm, pswa;
   int am;
   if (tdep->abi == ABI_LINUX_S390)
@@ -2842,7 +2842,7 @@ s390_record_calc_disp_vsce (struct gdbarch *gdbarch, struct regcache *regcache,
 			    uint8_t vx, uint8_t el, uint8_t es, uint16_t bd,
 			    int8_t dh, CORE_ADDR *res)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   ULONGEST x;
   gdb_byte buf[16];
@@ -2885,7 +2885,7 @@ static int s390_popcnt (unsigned int x) {
 static int
 s390_record_gpr_g (struct gdbarch *gdbarch, struct regcache *regcache, int i)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + i))
     return -1;
   if (tdep->abi == ABI_LINUX_S390)
@@ -2899,7 +2899,7 @@ s390_record_gpr_g (struct gdbarch *gdbarch, struct regcache *regcache, int i)
 static int
 s390_record_gpr_h (struct gdbarch *gdbarch, struct regcache *regcache, int i)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   if (tdep->abi == ABI_LINUX_S390)
     {
       if (record_full_arch_list_add_reg (regcache, S390_R0_UPPER_REGNUM + i))
@@ -2939,7 +2939,7 @@ static int
 s390_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
 		     CORE_ADDR addr)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   uint16_t insn[3] = {0};
   /* Instruction as bytes.  */
   uint8_t ibyte[6];
@@ -7178,7 +7178,7 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       s390_gdbarch_tdep *tmp
-	= (s390_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<s390_gdbarch_tdep> (arches->gdbarch);
 
       if (!tmp)
 	continue;
diff --git a/gdb/sh-linux-tdep.c b/gdb/sh-linux-tdep.c
index 2975a8f5d3d..f146f023add 100644
--- a/gdb/sh-linux-tdep.c
+++ b/gdb/sh-linux-tdep.c
@@ -195,7 +195,7 @@ sh_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   set_gdbarch_fetch_tls_load_module_address (gdbarch,
 					     svr4_fetch_objfile_link_map);
 
-  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
 
   /* Remember regset characteristics.  The sizes should match
      elf_gregset_t and elf_fpregset_t from Linux.  */
diff --git a/gdb/sh-netbsd-tdep.c b/gdb/sh-netbsd-tdep.c
index 4fbb53b49ff..49760337c4b 100644
--- a/gdb/sh-netbsd-tdep.c
+++ b/gdb/sh-netbsd-tdep.c
@@ -63,7 +63,7 @@ static void
 shnbsd_init_abi (struct gdbarch_info info,
 		  struct gdbarch *gdbarch)
 {
-  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
   nbsd_init_abi (info, gdbarch);
 
   tdep->core_gregmap = (struct sh_corefile_regmap *)regmap;
diff --git a/gdb/sh-tdep.c b/gdb/sh-tdep.c
index 2341a9beef6..062df860c81 100644
--- a/gdb/sh-tdep.c
+++ b/gdb/sh-tdep.c
@@ -1554,7 +1554,7 @@ sh_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 static struct type *
 sh_littlebyte_bigword_type (struct gdbarch *gdbarch)
 {
-  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
 
   if (tdep->sh_littlebyte_bigword_type == NULL)
     tdep->sh_littlebyte_bigword_type
@@ -2146,7 +2146,7 @@ sh_corefile_supply_regset (const struct regset *regset,
 			   int regnum, const void *regs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
   const struct sh_corefile_regmap *regmap = (regset == &sh_corefile_gregset
 					     ? tdep->core_gregmap
 					     : tdep->core_fpregmap);
@@ -2172,7 +2172,7 @@ sh_corefile_collect_regset (const struct regset *regset,
 			    int regnum, void *regs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
   const struct sh_corefile_regmap *regmap = (regset == &sh_corefile_gregset
 					     ? tdep->core_gregmap
 					     : tdep->core_fpregmap);
@@ -2210,7 +2210,7 @@ sh_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				 void *cb_data,
 				 const struct regcache *regcache)
 {
-  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
 
   if (tdep->core_gregmap != NULL)
     cb (".reg", tdep->sizeof_gregset, tdep->sizeof_gregset,
diff --git a/gdb/sparc-linux-tdep.c b/gdb/sparc-linux-tdep.c
index 18196b2f075..66481ea7b8a 100644
--- a/gdb/sparc-linux-tdep.c
+++ b/gdb/sparc-linux-tdep.c
@@ -254,7 +254,7 @@ static void
 sparc_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   gdbarch *arch = regcache->arch ();
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
   ULONGEST psr;
 
   regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
@@ -421,7 +421,7 @@ static const struct regset sparc32_linux_fpregset =
 static void
 sparc32_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/sparc-netbsd-tdep.c b/gdb/sparc-netbsd-tdep.c
index a97a772dba2..57c178511fa 100644
--- a/gdb/sparc-netbsd-tdep.c
+++ b/gdb/sparc-netbsd-tdep.c
@@ -295,7 +295,7 @@ static const struct regset sparc32nbsd_fpregset =
 void
 sparc32nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   nbsd_init_abi (info, gdbarch);
 
diff --git a/gdb/sparc-sol2-tdep.c b/gdb/sparc-sol2-tdep.c
index 28eb6f67601..a92e95ce71b 100644
--- a/gdb/sparc-sol2-tdep.c
+++ b/gdb/sparc-sol2-tdep.c
@@ -196,7 +196,7 @@ static const struct frame_unwind sparc32_sol2_sigtramp_frame_unwind =
 static void
 sparc32_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   tdep->gregset = &sparc32_sol2_gregset;
   tdep->sizeof_gregset = 152;
diff --git a/gdb/sparc-tdep.c b/gdb/sparc-tdep.c
index e540263a2fe..397f5489550 100644
--- a/gdb/sparc-tdep.c
+++ b/gdb/sparc-tdep.c
@@ -425,7 +425,7 @@ sparc32_register_name (struct gdbarch *gdbarch, int regnum)
 static struct type *
 sparc_psr_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->sparc_psr_type)
     {
@@ -447,7 +447,7 @@ sparc_psr_type (struct gdbarch *gdbarch)
 static struct type *
 sparc_fsr_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->sparc_fsr_type)
     {
@@ -988,7 +988,7 @@ CORE_ADDR
 sparc_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
 			CORE_ADDR current_pc, struct sparc_frame_cache *cache)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
   unsigned long insn;
   int offset = 0;
   int dest = -1;
@@ -1680,7 +1680,7 @@ sparc_analyze_control_transfer (struct regcache *regcache,
 
       /* Trap instruction (TRAP).  */
       gdbarch *arch = regcache->arch ();
-      sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
+      sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
       return tdep->step_trap (frame, insn);
     }
 
@@ -1731,7 +1731,7 @@ static std::vector<CORE_ADDR>
 sparc_software_single_step (struct regcache *regcache)
 {
   struct gdbarch *arch = regcache->arch ();
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
   CORE_ADDR npc, nnpc;
 
   CORE_ADDR pc, orig_npc;
@@ -1761,7 +1761,7 @@ static void
 sparc_write_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   gdbarch *arch = regcache->arch ();
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
 
   regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
   regcache_cooked_write_unsigned (regcache, tdep->npc_regnum, pc + 4);
@@ -1776,7 +1776,7 @@ sparc_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				    void *cb_data,
 				    const struct regcache *regcache)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   cb (".reg", tdep->sizeof_gregset, tdep->sizeof_gregset, tdep->gregset, NULL,
       cb_data);
diff --git a/gdb/sparc64-fbsd-tdep.c b/gdb/sparc64-fbsd-tdep.c
index 8a288282772..76c682fd521 100644
--- a/gdb/sparc64-fbsd-tdep.c
+++ b/gdb/sparc64-fbsd-tdep.c
@@ -222,7 +222,7 @@ static const struct regset sparc64fbsd_fpregset =
 static void
 sparc64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support. */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/sparc64-linux-tdep.c b/gdb/sparc64-linux-tdep.c
index 9ea72331e93..f5940cfcdee 100644
--- a/gdb/sparc64-linux-tdep.c
+++ b/gdb/sparc64-linux-tdep.c
@@ -262,7 +262,7 @@ static void
 sparc64_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   gdbarch *arch = regcache->arch ();
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
   ULONGEST state;
 
   regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
@@ -364,7 +364,7 @@ static const struct regset sparc64_linux_fpregset =
 static void
 sparc64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/sparc64-netbsd-tdep.c b/gdb/sparc64-netbsd-tdep.c
index 29cd3b6f3ba..db368118f23 100644
--- a/gdb/sparc64-netbsd-tdep.c
+++ b/gdb/sparc64-netbsd-tdep.c
@@ -248,7 +248,7 @@ static const struct regset sparc64nbsd_fpregset =
 static void
 sparc64nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   nbsd_init_abi (info, gdbarch);
 
diff --git a/gdb/sparc64-obsd-tdep.c b/gdb/sparc64-obsd-tdep.c
index 05ebbd2e84a..d6470a51b65 100644
--- a/gdb/sparc64-obsd-tdep.c
+++ b/gdb/sparc64-obsd-tdep.c
@@ -423,7 +423,7 @@ static const struct regset sparc64obsd_fpregset =
 static void
 sparc64obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   tdep->gregset = &sparc64obsd_gregset;
   tdep->sizeof_gregset = 288;
diff --git a/gdb/sparc64-sol2-tdep.c b/gdb/sparc64-sol2-tdep.c
index 458f0320582..e656c359efa 100644
--- a/gdb/sparc64-sol2-tdep.c
+++ b/gdb/sparc64-sol2-tdep.c
@@ -199,7 +199,7 @@ static const struct frame_unwind sparc64_sol2_sigtramp_frame_unwind =
 static void
 sparc64_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   tdep->gregset = &sparc64_sol2_gregset;
   tdep->sizeof_gregset = 304;
diff --git a/gdb/sparc64-tdep.c b/gdb/sparc64-tdep.c
index 95496d33ad4..5ca5f2dca8c 100644
--- a/gdb/sparc64-tdep.c
+++ b/gdb/sparc64-tdep.c
@@ -648,7 +648,7 @@ sparc64_structure_or_union_p (const struct type *type)
 static struct type *
 sparc64_pstate_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->sparc64_pstate_type)
     {
@@ -675,7 +675,7 @@ sparc64_pstate_type (struct gdbarch *gdbarch)
 static struct type *
 sparc64_ccr_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   if (tdep->sparc64_ccr_type == NULL)
     {
@@ -700,7 +700,7 @@ sparc64_ccr_type (struct gdbarch *gdbarch)
 static struct type *
 sparc64_fsr_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->sparc64_fsr_type)
     {
@@ -733,7 +733,7 @@ sparc64_fsr_type (struct gdbarch *gdbarch)
 static struct type *
 sparc64_fprs_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->sparc64_fprs_type)
     {
@@ -1806,7 +1806,7 @@ sparc64_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr)
 void
 sparc64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   tdep->pc_regnum = SPARC64_PC_REGNUM;
   tdep->npc_regnum = SPARC64_NPC_REGNUM;
diff --git a/gdb/tic6x-linux-tdep.c b/gdb/tic6x-linux-tdep.c
index 5a93294361a..b2422d1ccc0 100644
--- a/gdb/tic6x-linux-tdep.c
+++ b/gdb/tic6x-linux-tdep.c
@@ -45,7 +45,7 @@ static const gdb_byte tic6x_bkpt_bnop_le[] = { 0x22, 0xa1, 0x00, 0x00 };
 static unsigned int
 tic6x_register_sigcontext_offset (unsigned int regnum, struct gdbarch *gdbarch)
 {
-  tic6x_gdbarch_tdep *tdep = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  tic6x_gdbarch_tdep *tdep = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
 
   if (regnum == TIC6X_A4_REGNUM || regnum == TIC6X_A4_REGNUM + 2
       || regnum == TIC6X_A4_REGNUM + 4)
@@ -92,7 +92,7 @@ tic6x_linux_rt_sigreturn_init (const struct tramp_frame *self,
 		    + TIC6X_SIGINFO_SIZE
 		    + 4 + 4 /* uc_flags and *uc_link in struct ucontext.  */
 		    + TIC6X_STACK_T_SIZE);
-  tic6x_gdbarch_tdep *tdep = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  tic6x_gdbarch_tdep *tdep = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
   unsigned int reg_offset;
   unsigned int i;
 
@@ -165,7 +165,7 @@ extern struct target_so_ops dsbt_so_ops;
 static void
 tic6x_uclinux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  tic6x_gdbarch_tdep *tdep = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  tic6x_gdbarch_tdep *tdep = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/tic6x-tdep.c b/gdb/tic6x-tdep.c
index 3e49030ab14..b7efcf18576 100644
--- a/gdb/tic6x-tdep.c
+++ b/gdb/tic6x-tdep.c
@@ -325,7 +325,7 @@ tic6x_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 static const gdb_byte *
 tic6x_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
-  tic6x_gdbarch_tdep *tdep = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  tic6x_gdbarch_tdep *tdep = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
 
   *size = kind;
 
@@ -599,7 +599,7 @@ tic6x_get_next_pc (struct regcache *regcache, CORE_ADDR pc)
       if (inst == TIC6X_INST_SWE)
 	{
 	  tic6x_gdbarch_tdep *tdep
-	    = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	    = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
 
 	  if (tdep->syscall_next_pc != NULL)
 	    return tdep->syscall_next_pc (get_current_frame ());
@@ -1217,7 +1217,7 @@ tic6x_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       tic6x_gdbarch_tdep *tdep
-	= (tic6x_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<tic6x_gdbarch_tdep> (arches->gdbarch);
 
       if (has_gp != tdep->has_gp)
 	continue;
diff --git a/gdb/v850-tdep.c b/gdb/v850-tdep.c
index a67310a2440..4de5faa6a47 100644
--- a/gdb/v850-tdep.c
+++ b/gdb/v850-tdep.c
@@ -511,7 +511,7 @@ v850_use_struct_convention (struct gdbarch *gdbarch, struct type *type)
 {
   int i;
   struct type *fld_type, *tgt_type;
-  v850_gdbarch_tdep *tdep = (v850_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  v850_gdbarch_tdep *tdep = gdbarch_tdep<v850_gdbarch_tdep> (gdbarch);
 
   if (tdep->abi == V850_ABI_RH850)
     {
@@ -1023,7 +1023,7 @@ v850_push_dummy_call (struct gdbarch *gdbarch,
   int argnum;
   int arg_space = 0;
   int stack_offset;
-  v850_gdbarch_tdep *tdep = (v850_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  v850_gdbarch_tdep *tdep = gdbarch_tdep<v850_gdbarch_tdep> (gdbarch);
 
   if (tdep->abi == V850_ABI_RH850)
     stack_offset = 0;
@@ -1374,7 +1374,7 @@ v850_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       v850_gdbarch_tdep *tdep
-	= (v850_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<v850_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->e_flags != e_flags || tdep->e_machine != e_machine)
 	continue;
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 277507ddf09..9e7335acec3 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -488,7 +488,7 @@ windows_fetch_one_register (struct regcache *regcache,
 
   char *context_offset = context_ptr + windows_process.mappings[r];
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   gdb_assert (!gdbarch_read_pc_p (gdbarch));
   gdb_assert (gdbarch_pc_regnum (gdbarch) >= 0);
diff --git a/gdb/xtensa-linux-nat.c b/gdb/xtensa-linux-nat.c
index 5a08824a680..d005c9d8f78 100644
--- a/gdb/xtensa-linux-nat.c
+++ b/gdb/xtensa-linux-nat.c
@@ -62,7 +62,7 @@ fill_gregset (const struct regcache *regcache,
   int i;
   xtensa_elf_gregset_t *regs = (xtensa_elf_gregset_t *) gregsetp;
   struct gdbarch *gdbarch = regcache->arch ();
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   if (regnum == gdbarch_pc_regnum (gdbarch) || regnum == -1)
     regcache->raw_collect (gdbarch_pc_regnum (gdbarch), &regs->pc);
@@ -124,7 +124,7 @@ supply_gregset_reg (struct regcache *regcache,
   xtensa_elf_gregset_t *regs = (xtensa_elf_gregset_t *) gregsetp;
 
   struct gdbarch *gdbarch = regcache->arch ();
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   if (regnum == gdbarch_pc_regnum (gdbarch) || regnum == -1)
     regcache->raw_supply (gdbarch_pc_regnum (gdbarch), &regs->pc);
diff --git a/gdb/xtensa-linux-tdep.c b/gdb/xtensa-linux-tdep.c
index ef55319fd09..600b59b8894 100644
--- a/gdb/xtensa-linux-tdep.c
+++ b/gdb/xtensa-linux-tdep.c
@@ -99,7 +99,7 @@ xtensa_linux_gdb_signal_to_target (struct gdbarch *gdbarch,
 static void
 xtensa_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   if (tdep->num_nopriv_regs < tdep->num_regs)
     {
diff --git a/gdb/xtensa-tdep.c b/gdb/xtensa-tdep.c
index b6558838e44..f881870e244 100644
--- a/gdb/xtensa-tdep.c
+++ b/gdb/xtensa-tdep.c
@@ -116,7 +116,7 @@ static unsigned int xtensa_debug_level = 0;
 static int
 windowing_enabled (struct gdbarch *gdbarch, unsigned int ps)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   /* If we know CALL0 ABI is set explicitly,  say it is Call0.  */
   if (tdep->call_abi == CallAbiCall0Only)
@@ -130,7 +130,7 @@ windowing_enabled (struct gdbarch *gdbarch, unsigned int ps)
 static int
 arreg_number (struct gdbarch *gdbarch, int a_regnum, ULONGEST wb)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   int arreg;
 
   arreg = a_regnum - tdep->a0_base;
@@ -145,7 +145,7 @@ arreg_number (struct gdbarch *gdbarch, int a_regnum, ULONGEST wb)
 static int
 areg_number (struct gdbarch *gdbarch, int ar_regnum, unsigned int wb)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   int areg;
 
   areg = ar_regnum - tdep->ar_base;
@@ -226,7 +226,7 @@ static int
 xtensa_find_register_by_name (struct gdbarch *gdbarch, const char *name)
 {
   int i;
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   for (i = 0; i < gdbarch_num_cooked_regs (gdbarch); i++)
     if (strcasecmp (tdep->regmap[i].name, name) == 0)
@@ -239,7 +239,7 @@ xtensa_find_register_by_name (struct gdbarch *gdbarch, const char *name)
 static const char *
 xtensa_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   /* Return the name stored in the register map.  */
   if (regnum >= 0 && regnum < gdbarch_num_cooked_regs (gdbarch))
@@ -254,7 +254,7 @@ xtensa_register_name (struct gdbarch *gdbarch, int regnum)
 static struct type *
 xtensa_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   /* Return signed integer for ARx and Ax registers.  */
   if ((regnum >= tdep->ar_base
@@ -339,7 +339,7 @@ static int
 xtensa_reg_to_regnum (struct gdbarch *gdbarch, int regnum)
 {
   int i;
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   if (regnum >= 0 && regnum < 16)
     return tdep->a0_base + regnum;
@@ -542,7 +542,7 @@ xtensa_pseudo_register_read (struct gdbarch *gdbarch,
 {
   DEBUGTRACE ("xtensa_pseudo_register_read (... regnum = %d (%s) ...)\n",
 	      regnum, xtensa_register_name (gdbarch, regnum));
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   /* Read aliases a0..a15, if this is a Windowed ABI.  */
   if (tdep->isa_use_windowed_registers
@@ -634,7 +634,7 @@ xtensa_pseudo_register_write (struct gdbarch *gdbarch,
 {
   DEBUGTRACE ("xtensa_pseudo_register_write (... regnum = %d (%s) ...)\n",
 	      regnum, xtensa_register_name (gdbarch, regnum));
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   /* Renumber register, if aliases a0..a15 on Windowed ABI.  */
   if (tdep->isa_use_windowed_registers
@@ -767,7 +767,7 @@ xtensa_register_reggroup_p (struct gdbarch *gdbarch,
 			    int regnum,
 			    const struct reggroup *group)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   xtensa_register_t* reg = &tdep->regmap[regnum];
   xtensa_register_type_t type = reg->type;
   xtensa_register_group_t rg = reg->group;
@@ -821,7 +821,7 @@ xtensa_supply_gregset (const struct regset *regset,
 {
   const xtensa_elf_gregset_t *regs = (const xtensa_elf_gregset_t *) gregs;
   struct gdbarch *gdbarch = rc->arch ();
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   int i;
 
   DEBUGTRACE ("xtensa_supply_gregset (..., regnum==%d, ...)\n", regnum);
@@ -1050,7 +1050,7 @@ static struct frame_id
 xtensa_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
 {
   CORE_ADDR pc, fp;
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   /* THIS-FRAME is a dummy frame.  Return a frame ID of that frame.  */
 
@@ -1105,7 +1105,7 @@ xtensa_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR current_pc)
 {
 #define RETURN_FP goto done
 
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   unsigned int fp_regnum = tdep->a0_base + 1;
   CORE_ADDR start_addr;
   xtensa_isa isa;
@@ -1255,7 +1255,7 @@ xtensa_frame_cache (struct frame_info *this_frame, void **this_cache)
   if (windowed)
     {
       LONGEST op1;
-      xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
       /* Get WINDOWBASE, WINDOWSTART, and PS registers.  */
       wb = get_frame_register_unsigned (this_frame, 
@@ -1417,7 +1417,7 @@ xtensa_frame_prev_register (struct frame_info *this_frame,
   struct xtensa_frame_cache *cache;
   ULONGEST saved_reg = 0;
   int done = 1;
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   if (*this_cache == NULL)
     *this_cache = xtensa_frame_cache (this_frame, this_cache);
@@ -1546,7 +1546,7 @@ xtensa_extract_return_value (struct type *type,
 
   gdb_assert(len > 0);
 
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   if (tdep->call_abi != CallAbiCall0Only)
     {
       /* First, we have to find the caller window in the register file.  */
@@ -1602,7 +1602,7 @@ xtensa_store_return_value (struct type *type,
 
   DEBUGTRACE ("xtensa_store_return_value (...)\n");
 
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   if (tdep->call_abi != CallAbiCall0Only)
     {
       regcache_raw_read_unsigned 
@@ -1686,7 +1686,7 @@ xtensa_push_dummy_call (struct gdbarch *gdbarch,
 			CORE_ADDR struct_addr)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   int size, onstack_size;
   gdb_byte *buf = (gdb_byte *) alloca (16);
   CORE_ADDR ra, ps;
@@ -1935,7 +1935,7 @@ xtensa_push_dummy_call (struct gdbarch *gdbarch,
 static int
 xtensa_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   if (tdep->isa_use_density_instructions)
     return 2;
@@ -2182,7 +2182,7 @@ call0_track_op (struct gdbarch *gdbarch, xtensa_c0reg_t dst[], xtensa_c0reg_t sr
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   unsigned litbase, litaddr, litval;
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   switch (opclass)
     {
@@ -2557,7 +2557,7 @@ call0_frame_cache (struct frame_info *this_frame,
   CORE_ADDR body_pc=UINT_MAX;	/* PC, where prologue analysis stopped.  */
   CORE_ADDR sp, fp, ra;
   int fp_regnum = C0_SP, c0_hasfp = 0, c0_frmsz = 0, prev_sp = 0, to_stk;
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
  
   sp = get_frame_register_unsigned
     (this_frame, tdep->a0_base + 1);
@@ -2710,7 +2710,7 @@ static int a11_was_saved;
 static void
 execute_l32e (struct gdbarch *gdbarch, int at, int as, int offset, CORE_ADDR wb)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   int atreg = arreg_number (gdbarch, tdep->a0_base + at, wb);
   int asreg = arreg_number (gdbarch, tdep->a0_base + as, wb);
   CORE_ADDR addr = xtensa_read_register (asreg) + offset;
@@ -2740,7 +2740,7 @@ execute_l32e (struct gdbarch *gdbarch, int at, int as, int offset, CORE_ADDR wb)
 static void
 execute_s32e (struct gdbarch *gdbarch, int at, int as, int offset, CORE_ADDR wb)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   int atreg = arreg_number (gdbarch, tdep->a0_base + at, wb);
   int asreg = arreg_number (gdbarch, tdep->a0_base + as, wb);
   CORE_ADDR addr = xtensa_read_register (asreg) + offset;
@@ -2774,7 +2774,7 @@ execute_code (struct gdbarch *gdbarch, CORE_ADDR current_pc, CORE_ADDR wb)
   xtensa_opcode opc;
   int insn_num = 0;
   void (*func) (struct gdbarch *, int, int, int, CORE_ADDR);
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   uint32_t at, as, offset;
 
@@ -2905,7 +2905,7 @@ xtensa_window_interrupt_frame_cache (struct frame_info *this_frame,
   CORE_ADDR ps, wb, ws, ra;
   int epc1_regnum, i, regnum;
   xtensa_exception_handler_t eh_type;
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   /* Read PS, WB, and WS from the hardware. Note that PS register
      must be present, if Windowed ABI is supported.  */
@@ -3019,7 +3019,7 @@ xtensa_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
 
       CORE_ADDR end_func;
 
-      xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
       if ((tdep->call_abi == CallAbiCall0Only)
 	  && call0_ret (start_pc, prologue_sal.end))
 	return start_pc;
@@ -3041,7 +3041,7 @@ xtensa_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
 static void
 xtensa_verify_config (struct gdbarch *gdbarch)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   string_file log;
 
   /* Verify that we got a reasonable number of AREGS.  */
diff --git a/gdb/z80-tdep.c b/gdb/z80-tdep.c
index d27e567c358..6a11883e7b4 100644
--- a/gdb/z80-tdep.c
+++ b/gdb/z80-tdep.c
@@ -308,7 +308,7 @@ z80_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR pc_beg, CORE_ADDR pc_end,
 		   struct z80_unwind_cache *info)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  z80_gdbarch_tdep *tdep = (z80_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  z80_gdbarch_tdep *tdep = gdbarch_tdep<z80_gdbarch_tdep> (gdbarch);
   int addr_len = tdep->addr_length;
   gdb_byte prologue[32]; /* max prologue is 24 bytes: __interrupt with local array */
   int pos = 0;
@@ -564,7 +564,7 @@ z80_frame_unwind_cache (struct frame_info *this_frame,
   gdb_byte buf[sizeof(void*)];
   struct z80_unwind_cache *info;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  z80_gdbarch_tdep *tdep = (z80_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  z80_gdbarch_tdep *tdep = gdbarch_tdep<z80_gdbarch_tdep> (gdbarch);
   int addr_len = tdep->addr_length;
 
   if (*this_prologue_cache)
@@ -697,7 +697,7 @@ z80_frame_prev_register (struct frame_info *this_frame,
 	  ULONGEST pc;
 	  gdb_byte buf[3];
 	  struct gdbarch *gdbarch = get_frame_arch (this_frame);
-	  z80_gdbarch_tdep *tdep = (z80_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	  z80_gdbarch_tdep *tdep = gdbarch_tdep<z80_gdbarch_tdep> (gdbarch);
 	  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
 	  read_memory (info->saved_regs[Z80_PC_REGNUM].addr (),
@@ -750,7 +750,7 @@ z80_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
     }
   else /* kind is non-RST address, use CALL instead, but it is dungerous */
     {
-      z80_gdbarch_tdep *tdep = (z80_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      z80_gdbarch_tdep *tdep = gdbarch_tdep<z80_gdbarch_tdep> (gdbarch);
       gdb_byte *p = break_insn;
       *p++ = 0xcd;
       *p++ = (kind >> 0) & 0xff;
-- 
2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCHv2 5/6] gdb: ensure the cast in gdbarch_tdep is valid
  2022-06-10 13:08 ` [PATCHv2 0/6] Handle trying to use a native target with the wrong binary Andrew Burgess
                     ` (3 preceding siblings ...)
  2022-06-10 13:08   ` [PATCHv2 4/6] gdb: move the type cast into gdbarch_tdep Andrew Burgess
@ 2022-06-10 13:08   ` Andrew Burgess
  2022-06-10 13:08   ` [PATCHv2 6/6] gdb: native target invalid architecture detection Andrew Burgess
  2022-06-13 16:15   ` [PATCHv3 0/6] Handle trying to use a native target with the wrong binary Andrew Burgess
  6 siblings, 0 replies; 83+ messages in thread
From: Andrew Burgess @ 2022-06-10 13:08 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

This commit builds on the previous commit and modifies the
gdbarch_tdep function to ensure that the cast being performed is
valid.

To do this I make use of dynamic_cast to ensure that the generic
gdbarch_tdep pointer that we have is of the correct type.

The only problem with this approach is that, in order to use
dynamic_cast, we need RTTI information, which requires the class to
have a vtable, which currently, is not something the various tdep
classes have.

And so, in this commit, I add a virtual destructor to the gdbarch_tdep
class.

With this change I can now add an assert in the gdbarch_tdep function.

Obviously, this change comes at a cost, creation of the tdep classes
is now slightly more expensive (due to vtable initialisation),
however, this only happens when a new gdbarch is created, which is not
that frequent, so I don't see that as a huge concern.

Then, there is an increased cost each time the tdep is accessed.  This
is much more frequent, but I don't believe the cost is excessive (a
vtable pointer comparison), at least, no worse than many of our other
asserts.

If we consider the motivating example that was discussed in the
previous commit; build GDB for all targets on an x86-64 GNU/Linux
system, and then attempt to "run" a RISC-V binary using the native
x86-64 Linux target.  Previously this would trigger an assert while
accessing fields within a i386_gdbarch_tdep, like this:

  ../../src/gdb/i387-tdep.c:596: internal-error: i387_supply_fxsave: Assertion `tdep->st0_regnum >= I386_ST0_REGNUM' failed.

But with the changes from this commit in place, we now see an
assertion failure like this:

  ../../src/gdb/gdbarch.h:166: internal-error: gdbarch_tdep: Assertion `dynamic_cast<TDepType *> (tdep) != nullptr' failed.

On the face of it, this might not seem like much of an improvement,
but I think it is.

The previous assert was triggered by undefined behaviour.  There's no
guarantee that we would see an assertion at all, a different
combination of native target and binary format might not trigger an
assert (and just do the wrong thing), or might crash GDB completely.

In contrast, the new assert is based on defined behaviour, we'll
always assert if GDB goes wrong, and we assert early, at the point the
mistake is being made (casting the result of gdbarch_tdep to the wrong
type), rather than at some later point after the incorrect cast has
completed.

Obviously, when we consider the original example, trying to run a
binary of the wrong architecture on a native target, having GDB fail
with an assertion is not a real solution.  No user action should be
able to trigger an assertion failure.  In a later commit I will offer
a real solution to this architecture mismatch problem.
---
 gdb/gdbarch.h | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index b2c91db0c4f..a47aa8cc8fa 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -58,7 +58,13 @@ struct inferior;
 
 #include "regcache.h"
 
-struct gdbarch_tdep {};
+/* The base class for every architecture's tdep sub-class.  We include a
+   virtual destructor so that sub-classes will have RTTI information.  */
+
+struct gdbarch_tdep
+{
+  virtual ~gdbarch_tdep() = default;
+};
 
 /* The architecture associated with the inferior through the
    connection to the target.
@@ -156,8 +162,9 @@ template<typename TDepType>
 static inline TDepType *
 gdbarch_tdep (struct gdbarch *gdbarch)
 {
-  struct gdbarch_tdep *tdep = gdbarch_tdep_1 (gdbarch);
-  return static_cast<TDepType *> (tdep);
+  TDepType *tdep = dynamic_cast<TDepType *> (gdbarch_tdep_1 (gdbarch));
+  gdb_assert (tdep != nullptr);
+  return tdep;
 }
 
 /* Mechanism for co-ordinating the selection of a specific
-- 
2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCHv2 6/6] gdb: native target invalid architecture detection
  2022-06-10 13:08 ` [PATCHv2 0/6] Handle trying to use a native target with the wrong binary Andrew Burgess
                     ` (4 preceding siblings ...)
  2022-06-10 13:08   ` [PATCHv2 5/6] gdb: ensure the cast in gdbarch_tdep is valid Andrew Burgess
@ 2022-06-10 13:08   ` Andrew Burgess
  2022-06-10 16:20     ` John Baldwin
  2022-06-10 16:31     ` Luis Machado
  2022-06-13 16:15   ` [PATCHv3 0/6] Handle trying to use a native target with the wrong binary Andrew Burgess
  6 siblings, 2 replies; 83+ messages in thread
From: Andrew Burgess @ 2022-06-10 13:08 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

If GDB is asked to start a new inferior, or attach to an existing
process, using a binary file for an architecture that does not match
the current native target, then, currently, GDB will assert.  Here's
an example session using current HEAD of master with GDB built for an
x86-64 GNU/Linux native target, the binary being used is a RISC-V ELF:

  $ ./gdb/gdb -q --data-directory ./gdb/data-directory/
  (gdb) file /tmp/hello.rv32imc.x
  Reading symbols from /tmp/hello.rv32imc.x...
  (gdb) start
  Temporary breakpoint 1 at 0x101b2: file hello.rv32.c, line 23.
  Starting program: /tmp/hello.rv32imc.x
  ../../src/gdb/gdbarch.h:166: internal-error: gdbarch_tdep: Assertion `dynamic_cast<TDepType *> (tdep) != nullptr' failed.
  A problem internal to GDB has been detected,
  further debugging may prove unreliable.

The same error is encountered if, instead of starting a new inferior,
the user tries to attach to an x86-64 process with a RISC-V binary set
as the current executable.

These errors are not specific to the x86-64/RISC-V pairing I'm using
here, any attempt to use a binary for one architecture with a native
target of a different architecture will result in a similar error.

Clearly, attempting to use this cross-architecture combination is a
user error, but I think GDB should do better than an assert; ideally a
nice error should be printed.

The problem we run into is that, when the user starts a new inferior,
or attaches to an inferior, the inferior stops.  At this point GDB
attempts to handle the stop, and this involves reading registers from
the inferior.

These register reads end up being done through the native target, so
in the example above, we end up in the amd64_supply_fxsave function.
However, these functions need a gdbarch.  The gdbarch is fetched from
the register set, which was constructed using the gdbarch from the
binary currently in use.  And so we end up in amd64_supply_fxsave
using a RISC-V gdbarch.

When we call:

  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);

this will assert as the gdbarch_tdep data within the RISC-V gdbarch is
of the type riscv_gdbarch_tdep not i386_gdbarch_tdep.

The solution I propose in this commit is to add a new target_ops
method supports_architecture_p.  This method will return true if a
target can safely be used with a specific architecture, otherwise, the
method returns false.

I imagine that a result of true from this method doesn't guarantee
that GDB can start an inferior of a given architecture, it just means
that GDB will not crash if such an attempt is made.  A result of false
is a hard stop; attempting to use this target with this architecture
is not supported, and may cause GDB to crash.

This distinction is important I think for things like remote targets,
and possibly simulator targets.  We might imagine that GDB can ask a
remote (or simulator) to start with a particular executable, and the
target might still refuse for some reason.  But my thinking is that
these refusals should be well handled (i.e. GDB should give a user
friendly error), rather than crashing, as is the case with the native
targets.

For example, if I start gdbserver on an x86-64 machine like this:

  gdbserver --multi :54321

Then use GDB to try and load a RISC-V binary, like this:

  $ ./gdb/gdb -q --data-directory ./gdb/data-directory/
  (gdb) file /tmp/hello.rv32imc.x
  Reading symbols from /tmp/hello.rv32imc.x...
  (gdb) target extended-remote :54321
  Remote debugging using :54321
  (gdb) run
  Starting program: /tmp/hello.rv32imc.x
  Running the default executable on the remote target failed; try "set remote exec-file"?
  (gdb)

Though the error is not very helpful in diagnosing the problem, we can
see that GDB has not crashed, but has given the user an error.

And so, the supports_architecture_p method is created to return true
by default, then I override this in inf_child_target, where I compare
the architecture in question with the default_bfd_arch.

Finally, I've added calls to supports_architecture_p for the
run (which covers run, start, starti) and attach commands.

This leaves just one question, what about native targets that support
multiple architectures?

These targets can be split into two groups.  First, we have targets
like x86-64, which also supports i386 binaries.  This case is easy to
handle, as far as BFD is concerned there is only one architecture,
bfd_arch_i386, and we then use machine types to split this
architecture into x86-64 and i386 (and others).  As the new
supports_architecture_p function only checks the bfd architecture,
then there is nothing additional needed for this case.

The second group of multi-architecture targets requires more work.
The only targets that I'm aware of that fall into this group are the
rs6000-aix-nat.c, ppc-*-nat.c targets, and the aarch64-linux-nat.c
target.

The first group (rs600/ppc) support bfd_arch_rs6000 and
bfd_arch_powerpc, while the second (aarch64) supports bfd_arch_arm and
bfd_arch_aarch64.

To deal with these targets I have overridden the
supports_architecture_p function in each of the separate target files,
these overrides check both of the supported architectures.

One final note, in the rs6000/ppc case, the FreeBSD target supports
both architectures, and so we override supports_architecture_p.  In
contrast, the aarch64_fbsd_nat_target target does not (yet) support
bfd_arch_arm, and so there is no supports_architecture_p here.  This
can always be added later if/when support is added.

You will notice a lack of tests for this change.  I'm not sure of a
good way that I can build a binary for a different architecture as
part of a test, but if anyone has any ideas then I'll be happy to add
a test here.  The gdb.base/multi-arch.exp test exists, which for
AArch64 will test compiling and running something as both AArch64 and
ARM, but this doesn't cover the error case, just that the overridden
supports_architecture_p works in that case.
---
 gdb/aarch64-linux-nat.c |  8 ++++++++
 gdb/arch-utils.c        |  8 ++++++++
 gdb/arch-utils.h        |  5 +++++
 gdb/inf-child.c         | 19 +++++++++++++++++++
 gdb/inf-child.h         |  2 ++
 gdb/infcmd.c            |  8 ++++++++
 gdb/ppc-fbsd-nat.c      |  8 ++++++++
 gdb/ppc-linux-nat.c     |  8 ++++++++
 gdb/ppc-obsd-nat.c      |  8 ++++++++
 gdb/rs6000-aix-nat.c    |  8 ++++++++
 gdb/target-delegates.c  | 28 ++++++++++++++++++++++++++++
 gdb/target.h            | 13 ++++++++++++-
 12 files changed, 122 insertions(+), 1 deletion(-)

diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c
index a457fcd48ad..6114c4c6638 100644
--- a/gdb/aarch64-linux-nat.c
+++ b/gdb/aarch64-linux-nat.c
@@ -108,6 +108,14 @@ class aarch64_linux_nat_target final
   /* Write allocation tags to memory via PTRACE.  */
   bool store_memtags (CORE_ADDR address, size_t len,
 		      const gdb::byte_vector &tags, int type) override;
+
+  /* This target supports two architectures, check for them both here.  */
+
+  bool supports_architecture_p (struct gdbarch *gdbarch) override
+  {
+    bfd_architecture the_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
+    return (the_arch == bfd_arch_aarch64 || the_arch == bfd_arch_arm);
+  }
 };
 
 static aarch64_linux_nat_target the_aarch64_linux_nat_target;
diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index 360b8d694be..efba17e1d5d 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -1570,6 +1570,14 @@ target_gdbarch (void)
   return current_inferior ()->gdbarch;
 }
 
+/* See arch-utils.h.  */
+
+bool
+gdbarch_matches_default_arch (struct gdbarch *gdbarch)
+{
+  return gdbarch_bfd_arch_info (gdbarch)->arch == default_bfd_arch->arch;
+}
+
 void _initialize_gdbarch_utils ();
 void
 _initialize_gdbarch_utils ()
diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h
index f850e5fd6e7..5d61be36c26 100644
--- a/gdb/arch-utils.h
+++ b/gdb/arch-utils.h
@@ -300,4 +300,9 @@ extern void default_read_core_file_mappings
    struct bfd *cbfd,
    read_core_file_mappings_pre_loop_ftype pre_loop_cb,
    read_core_file_mappings_loop_ftype loop_cb);
+
+/* Return true if the bfd architecture of GDBARCH matches the default bfd
+   architecture.  */
+
+extern bool gdbarch_matches_default_arch (struct gdbarch *gdbarch);
 #endif /* ARCH_UTILS_H */
diff --git a/gdb/inf-child.c b/gdb/inf-child.c
index 56ebd2a5549..0c47a367c68 100644
--- a/gdb/inf-child.c
+++ b/gdb/inf-child.c
@@ -30,6 +30,8 @@
 #include "inferior.h"
 #include <sys/stat.h>
 #include "inf-child.h"
+#include "gdbarch.h"
+#include "arch-utils.h"
 #include "gdbsupport/fileio.h"
 #include "gdbsupport/agent.h"
 #include "gdbsupport/gdb_wait.h"
@@ -412,6 +414,23 @@ inf_child_target::follow_exec (inferior *follow_inf, ptid_t ptid,
     }
 }
 
+/* The inf_child_target represents the native target built into GDB, of
+   which there is only ever one.  If we attempt to start a native inferior
+   using a binary for an architecture not matching the native target then,
+   when we handle the first stop, we will end up trying to read registers
+   using the gdbarch functions from the native target, but passing in a
+   gdbarch object based on the architecture of the binary file.  This will
+   result in errors.
+
+   This check prevents this so long as everywhere user command that might
+   cause a new inferior to be created calls this function.  */
+
+bool
+inf_child_target::supports_architecture_p (struct gdbarch *gdbarch)
+{
+  return gdbarch_matches_default_arch (gdbarch);
+}
+
 /* See inf-child.h.  */
 
 void
diff --git a/gdb/inf-child.h b/gdb/inf-child.h
index ae5ace46f30..01a8164b0c2 100644
--- a/gdb/inf-child.h
+++ b/gdb/inf-child.h
@@ -92,6 +92,8 @@ class inf_child_target
 
   bool can_use_agent () override;
 
+  bool supports_architecture_p (struct gdbarch *gdbarch) override;
+
 protected:
   /* Unpush the target if it wasn't explicitly open with "target native"
      and there are no live inferiors left.  Note: if calling this as a
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index e909d4d4c81..b8acf858b3a 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -413,6 +413,10 @@ run_command_1 (const char *args, int from_tty, enum run_how run_how)
   if (non_stop && !run_target->supports_non_stop ())
     error (_("The target does not support running in non-stop mode."));
 
+  if (!run_target->supports_architecture_p (get_current_arch ()))
+    error (_("The target does not support architecture \"%s\"."),
+	   gdbarch_bfd_arch_info (get_current_arch ())->printable_name);
+
   /* Done.  Can now set breakpoints, change inferior args, etc.  */
 
   /* Insert temporary breakpoint in main function if requested.  */
@@ -2590,6 +2594,10 @@ attach_command (const char *args, int from_tty)
   if (non_stop && !attach_target->supports_non_stop ())
     error (_("Cannot attach to this target in non-stop mode"));
 
+  if (!attach_target->supports_architecture_p (get_current_arch ()))
+    error (_("The target does not support architecture \"%s\"."),
+	   gdbarch_bfd_arch_info (get_current_arch ())->printable_name);
+
   attach_target->attach (args, from_tty);
   /* to_attach should push the target, so after this point we
      shouldn't refer to attach_target again.  */
diff --git a/gdb/ppc-fbsd-nat.c b/gdb/ppc-fbsd-nat.c
index d0a5778e2d3..f7c36c33958 100644
--- a/gdb/ppc-fbsd-nat.c
+++ b/gdb/ppc-fbsd-nat.c
@@ -41,6 +41,14 @@ struct ppc_fbsd_nat_target final : public fbsd_nat_target
 {
   void fetch_registers (struct regcache *, int) override;
   void store_registers (struct regcache *, int) override;
+
+  /* This target supports two architectures, check for them both here.  */
+
+  bool supports_architecture_p (struct gdbarch *gdbarch) override
+  {
+    bfd_architecture the_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
+    return (the_arch == bfd_arch_rs6000 || the_arch == bfd_arch_powerpc);
+  }
 };
 
 static ppc_fbsd_nat_target the_ppc_fbsd_nat_target;
diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c
index de4158c411a..e302b15925a 100644
--- a/gdb/ppc-linux-nat.c
+++ b/gdb/ppc-linux-nat.c
@@ -551,6 +551,14 @@ struct ppc_linux_nat_target final : public linux_nat_target
 
   void low_prepare_to_resume (struct lwp_info *) override;
 
+  /* This target supports two architectures, check for them both here.  */
+
+  bool supports_architecture_p (struct gdbarch *gdbarch) override
+  {
+    bfd_architecture the_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
+    return (the_arch == bfd_arch_rs6000 || the_arch == bfd_arch_powerpc);
+  }
+
 private:
 
   void copy_thread_dreg_state (const ptid_t &parent_ptid,
diff --git a/gdb/ppc-obsd-nat.c b/gdb/ppc-obsd-nat.c
index e480f19dc73..2fdccc3085d 100644
--- a/gdb/ppc-obsd-nat.c
+++ b/gdb/ppc-obsd-nat.c
@@ -39,6 +39,14 @@ struct ppc_obsd_nat_target final : public obsd_nat_target
 {
   void fetch_registers (struct regcache *, int) override;
   void store_registers (struct regcache *, int) override;
+
+  /* This target supports two architectures, check for them both here.  */
+
+  bool supports_architecture_p (struct gdbarch *gdbarch) override
+  {
+    bfd_architecture the_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
+    return (the_arch == bfd_arch_rs6000 || the_arch == bfd_arch_powerpc);
+  }
 };
 
 static ppc_obsd_nat_target the_ppc_obsd_nat_target;
diff --git a/gdb/rs6000-aix-nat.c b/gdb/rs6000-aix-nat.c
index 8697d27b4ed..603caa8fb1e 100644
--- a/gdb/rs6000-aix-nat.c
+++ b/gdb/rs6000-aix-nat.c
@@ -91,6 +91,14 @@ class rs6000_nat_target final : public inf_ptrace_target
 
   ptid_t wait (ptid_t, struct target_waitstatus *, target_wait_flags) override;
 
+  /* This target supports two architectures, check for them both here.  */
+
+  bool supports_architecture_p (struct gdbarch *gdbarch) override
+  {
+    bfd_architecture the_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
+    return (the_arch == bfd_arch_rs6000 || the_arch == bfd_arch_powerpc);
+  }
+
 protected:
 
   void post_startup_inferior (ptid_t ptid) override
diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c
index 8a9986454dd..cb7bb1f2062 100644
--- a/gdb/target-delegates.c
+++ b/gdb/target-delegates.c
@@ -196,6 +196,7 @@ struct dummy_target : public target_ops
   bool supports_memory_tagging () override;
   bool fetch_memtags (CORE_ADDR arg0, size_t arg1, gdb::byte_vector &arg2, int arg3) override;
   bool store_memtags (CORE_ADDR arg0, size_t arg1, const gdb::byte_vector &arg2, int arg3) override;
+  bool supports_architecture_p (struct gdbarch *arg0) override;
 };
 
 struct debug_target : public target_ops
@@ -370,6 +371,7 @@ struct debug_target : public target_ops
   bool supports_memory_tagging () override;
   bool fetch_memtags (CORE_ADDR arg0, size_t arg1, gdb::byte_vector &arg2, int arg3) override;
   bool store_memtags (CORE_ADDR arg0, size_t arg1, const gdb::byte_vector &arg2, int arg3) override;
+  bool supports_architecture_p (struct gdbarch *arg0) override;
 };
 
 void
@@ -4536,3 +4538,29 @@ debug_target::store_memtags (CORE_ADDR arg0, size_t arg1, const gdb::byte_vector
   return result;
 }
 
+bool
+target_ops::supports_architecture_p (struct gdbarch *arg0)
+{
+  return this->beneath ()->supports_architecture_p (arg0);
+}
+
+bool
+dummy_target::supports_architecture_p (struct gdbarch *arg0)
+{
+  return true;
+}
+
+bool
+debug_target::supports_architecture_p (struct gdbarch *arg0)
+{
+  bool result;
+  gdb_printf (gdb_stdlog, "-> %s->supports_architecture_p (...)\n", this->beneath ()->shortname ());
+  result = this->beneath ()->supports_architecture_p (arg0);
+  gdb_printf (gdb_stdlog, "<- %s->supports_architecture_p (", this->beneath ()->shortname ());
+  target_debug_print_struct_gdbarch_p (arg0);
+  gdb_puts (") = ", gdb_stdlog);
+  target_debug_print_bool (result);
+  gdb_puts ("\n", gdb_stdlog);
+  return result;
+}
+
diff --git a/gdb/target.h b/gdb/target.h
index 18559feef89..5f3ae77f559 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -1320,7 +1320,18 @@ struct target_ops
     virtual bool store_memtags (CORE_ADDR address, size_t len,
 				const gdb::byte_vector &tags, int type)
       TARGET_DEFAULT_NORETURN (tcomplain ());
-  };
+
+    /* Return false if the target does not support GDBARCH, otherwise,
+       return true.
+
+       The default reply of true does not guarantee that debugging an
+       inferior with architecture GDBARCH will succeed, other errors might
+       be thrown later on, but a return value of false is a clear
+       indication that we should not proceed attempting to use this
+       architecture with this target.  */
+    virtual bool supports_architecture_p (struct gdbarch *gdbarch)
+      TARGET_DEFAULT_RETURN (true);
+};
 
 /* Deleter for std::unique_ptr.  See comments in
    target_ops::~target_ops and target_ops::close about heap-allocated
-- 
2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCHv2 3/6] gdb/arm: avoid undefined behaviour in arm_frame_is_thumb
  2022-06-10 13:08   ` [PATCHv2 3/6] gdb/arm: avoid undefined behaviour in arm_frame_is_thumb Andrew Burgess
@ 2022-06-10 15:21     ` Luis Machado
  2022-06-10 15:49       ` Andrew Burgess
  0 siblings, 1 reply; 83+ messages in thread
From: Luis Machado @ 2022-06-10 15:21 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

On 6/10/22 14:08, Andrew Burgess via Gdb-patches wrote:
> This commit fixes real undefined behaviour in GDB which I spotted when
> working on a later patch in this series.  The later patch in this
> series detects when the result of gdbarch_tdep() is cast to the wrong
> type.
> 
> The issue is revealed by the gdb.multi/multi-arch.exp test.
> 
> In this test we setup two inferiors, an AArch64 process, and an ARM
> process, then at one point we have inferior 1 selected (the AArch64
> inferior), and we place a breakpoint on a symbol present in the other
> inferior (the ARM inferior).
> 
> During the process of creating the breakpoint we call arm_pc_is_thumb,
> the GDBARCH passed into this function is correct, that is, represents
> the ARM process.
> 
> For whatever reason we are unable to figure out if the address in
> question is thumb or not throughout most of arm_pc_is_thumb, and so we
> get to this code at the end of the function:
> 
>    /* If we couldn't find any symbol, but we're talking to a running
>       target, then trust the current value of $cpsr.  This lets
>       "display/i $pc" always show the correct mode (though if there is
>       a symbol table we will not reach here, so it still may not be
>       displayed in the mode it will be executed).  */
>    if (target_has_registers ())
>      return arm_frame_is_thumb (get_current_frame ());
> 
> Which I guess is a last attempt to figure out the thumb status of an
> address.  However, remember, we the AArch64 inferior is current at
> this time, so the current frame is an AArch64 frame.

If we're trying to insert a breakpoint into a 32-bit inferior,
we should really have the 32-bit arm gdbarch at hand, not the AArch64 gdbarch.

I think the bug is somewhere else, in whoever passed the current inferior's gdbarch
as opposed to the gdbarch of the inferior that contains the symbol we've found.

I think this should be an assertion instead, as it is clearly wrong.

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCHv2 3/6] gdb/arm: avoid undefined behaviour in arm_frame_is_thumb
  2022-06-10 15:21     ` Luis Machado
@ 2022-06-10 15:49       ` Andrew Burgess
  2022-06-10 16:29         ` Luis Machado
  0 siblings, 1 reply; 83+ messages in thread
From: Andrew Burgess @ 2022-06-10 15:49 UTC (permalink / raw)
  To: Luis Machado, gdb-patches

Luis Machado via Gdb-patches <gdb-patches@sourceware.org> writes:

> On 6/10/22 14:08, Andrew Burgess via Gdb-patches wrote:
>> This commit fixes real undefined behaviour in GDB which I spotted when
>> working on a later patch in this series.  The later patch in this
>> series detects when the result of gdbarch_tdep() is cast to the wrong
>> type.
>> 
>> The issue is revealed by the gdb.multi/multi-arch.exp test.
>> 
>> In this test we setup two inferiors, an AArch64 process, and an ARM
>> process, then at one point we have inferior 1 selected (the AArch64
>> inferior), and we place a breakpoint on a symbol present in the other
>> inferior (the ARM inferior).
>> 
>> During the process of creating the breakpoint we call arm_pc_is_thumb,
>> the GDBARCH passed into this function is correct, that is, represents
>> the ARM process.
>> 
>> For whatever reason we are unable to figure out if the address in
>> question is thumb or not throughout most of arm_pc_is_thumb, and so we
>> get to this code at the end of the function:
>> 
>>    /* If we couldn't find any symbol, but we're talking to a running
>>       target, then trust the current value of $cpsr.  This lets
>>       "display/i $pc" always show the correct mode (though if there is
>>       a symbol table we will not reach here, so it still may not be
>>       displayed in the mode it will be executed).  */
>>    if (target_has_registers ())
>>      return arm_frame_is_thumb (get_current_frame ());
>> 
>> Which I guess is a last attempt to figure out the thumb status of an
>> address.  However, remember, we the AArch64 inferior is current at
>> this time, so the current frame is an AArch64 frame.
>
> If we're trying to insert a breakpoint into a 32-bit inferior,
> we should really have the 32-bit arm gdbarch at hand, not the AArch64
> gdbarch.

We do.

>
> I think the bug is somewhere else, in whoever passed the current inferior's gdbarch
> as opposed to the gdbarch of the inferior that contains the symbol
> we've found.

We do pass in the gdbarch of the inferior containing the breakpoint location.

If I change the condition to an assert, then run
gdb.multi/multi-arch.exp and catch the assertion, the stack looks like
this:

  #0  internal_error (file=0x55834840c8 "../../src/gdb/arm-tdep.c", line=551, 
      fmt=0x5583483d70 "%s: Assertion `%s' failed.") at ../../src/gdbsupport/errors.cc:51
  #1  0x0000005582b0e6a4 in arm_frame_is_thumb (frame=0x55c0849a00) at ../../src/gdb/arm-tdep.c:551
  #2  0x0000005582b0eb70 in arm_pc_is_thumb (gdbarch=0x55c0937080, memaddr=4195692) at ../../src/gdb/arm-tdep.c:687
  #3  0x0000005582b17e70 in arm_adjust_breakpoint_address (gdbarch=0x55c0937080, bpaddr=4195692)
      at ../../src/gdb/arm-tdep.c:4925
  #4  0x0000005582af0a60 in gdbarch_adjust_breakpoint_address (gdbarch=0x55c0937080, bpaddr=4195692)
      at ../../src/gdb/gdbarch.c:2840
  #5  0x0000005582b73c90 in adjust_breakpoint_address (gdbarch=0x55c0937080, bpaddr=4195692, bptype=bp_breakpoint)
      at ../../src/gdb/breakpoint.c:7147
  #6  0x0000005582b76854 in code_breakpoint::add_location (this=0x55c088e340, sal=...)
      at ../../src/gdb/breakpoint.c:8100
  #7  0x0000005582b773b8 in code_breakpoint::code_breakpoint (this=0x55c088e340, gdbarch_=0x55c089c050, 
      type_=bp_breakpoint, sals=..., location_=..., filter_=std::unique_ptr<char> = {...}, 
      cond_string_=std::unique_ptr<char> = {...}, extra_string_=std::unique_ptr<char> = {...}, 
      disposition_=disp_donttouch, thread_=-1, task_=0, ignore_count_=0, from_tty=1, enabled_=1, flags=0, 
      display_canonical_=0) at ../../src/gdb/breakpoint.c:8329
  #8  0x0000005582b90c00 in ordinary_breakpoint::code_breakpoint (this=0x55c088e340) at ../../src/gdb/breakpoint.c:266
  #9  0x0000005582b88758 in new_breakpoint_from_type<gdb::array_view<symtab_and_line const>&, std::unique_ptr<event_location, event_location_deleter>, std::unique_ptr<char, gdb::xfree_deleter<char> >, std::unique_ptr<char, gdb::xfree_deleter<char> >, std::unique_ptr<char, gdb::xfree_deleter<char> >, bpdisp&, int&, int&, int&, int&, int&, unsigned int&, int&> (gdbarch=0x55c089c050, type=bp_breakpoint) at ../../src/gdb/breakpoint.c:1303
  #10 0x0000005582b77710 in create_breakpoint_sal (gdbarch=0x55c089c050, sals=..., location=..., 
      filter=std::unique_ptr<char> = {...}, cond_string=std::unique_ptr<char> = {...}, 
      extra_string=std::unique_ptr<char> = {...}, type=bp_breakpoint, disposition=disp_donttouch, thread=-1, task=0, 
      ignore_count=0, from_tty=1, enabled=1, internal=0, flags=0, display_canonical=0)
      at ../../src/gdb/breakpoint.c:8395
  #11 0x0000005582b779d8 in create_breakpoints_sal (gdbarch=0x55c089c050, canonical=0x7fd8d196c0, 
      cond_string=std::unique_ptr<char> = {...}, extra_string=std::unique_ptr<char> = {...}, type=bp_breakpoint, 
      disposition=disp_donttouch, thread=-1, task=0, ignore_count=0, from_tty=1, enabled=1, internal=0, flags=0)
      at ../../src/gdb/breakpoint.c:8438
  #12 0x0000005582b78d94 in create_breakpoint (gdbarch=0x55c089c050, location=0x55c0979750, cond_string=0x0, thread=-1, 
      extra_string=0x0, force_condition=false, parse_extra=1, tempflag=0, type_wanted=bp_breakpoint, ignore_count=0, 
      pending_break_support=AUTO_BOOLEAN_AUTO, ops=0x558389c650 <code_breakpoint_ops>, from_tty=1, enabled=1, 
      internal=0, flags=0) at ../../src/gdb/breakpoint.c:8923
  #13 0x0000005582b792d8 in break_command_1 (arg=0x55c0732fc2 "", flag=0, from_tty=1) at ../../src/gdb/breakpoint.c:8994
  #14 0x0000005582b79578 in break_command (arg=0x55c0732fb6 "hangout_loop", from_tty=1)
      at ../../src/gdb/breakpoint.c:9065

In frame #6 we select a gdbarch based on the location of the breakpoint,
its at this point that we select the bfd_arch_arm gdbarch.

For frames #5, #4, #3, and #2 we are passing in a bfd_arch_arm gdbarch,
which is correct, and what you are asking for.

The problem is that in frame #2 we fail to find any of the special hints
that indicate if the code is thumb or not.  Now, _maybe_ you could argue
that one of the conditions in arm_pc_is_thumb should trigger, but, for
me, the very fact that there is a "catch all" case at the end of the
function means we have to be open to the possibility that non of the
special symbols, or bottom bit of the address set cases might trigger.

And so, we get to this code in arm_pc_is_thumb:

  if (target_has_registers ())
    return arm_frame_is_thumb (get_current_frame ());

At this point GDBARCH _is_ a bfd_arch_arm architecture.

But, the current frame is bfd_arch_aarch64.

And so, we enter frame #1, arm_frame_is_thumb, passing in a frame that
is not bfd_arch_arm.

So, are you are suggesting we should switch frames as part of the
breakpoint setting process?  Because I'm not sure how you'd pick even a
suitable inferior, multiple ARM inferiors might share a single program
space, so we could have a single gdbarch, but multiple inferiors, each
with multiple threads, and each thread with multiple frames...

I guess we could push the architecture check out of arm_frame_is_thumb
back to arm_pc_is_thumb, and only call arm_frame_is_thumb for the case
where the architecture is ARM... that doesn't make sense to me, but
maybe, I guess...

Anyway, let me know if the above makes any more sense.  If it does I can
update the commit message.

Thanks,
Andrew


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCHv2 6/6] gdb: native target invalid architecture detection
  2022-06-10 13:08   ` [PATCHv2 6/6] gdb: native target invalid architecture detection Andrew Burgess
@ 2022-06-10 16:20     ` John Baldwin
  2022-06-10 16:31     ` Luis Machado
  1 sibling, 0 replies; 83+ messages in thread
From: John Baldwin @ 2022-06-10 16:20 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

On 6/10/22 6:08 AM, Andrew Burgess via Gdb-patches wrote:
> If GDB is asked to start a new inferior, or attach to an existing
> process, using a binary file for an architecture that does not match
> the current native target, then, currently, GDB will assert.  Here's
> an example session using current HEAD of master with GDB built for an
> x86-64 GNU/Linux native target, the binary being used is a RISC-V ELF:
> 
>    $ ./gdb/gdb -q --data-directory ./gdb/data-directory/
>    (gdb) file /tmp/hello.rv32imc.x
>    Reading symbols from /tmp/hello.rv32imc.x...
>    (gdb) start
>    Temporary breakpoint 1 at 0x101b2: file hello.rv32.c, line 23.
>    Starting program: /tmp/hello.rv32imc.x
>    ../../src/gdb/gdbarch.h:166: internal-error: gdbarch_tdep: Assertion `dynamic_cast<TDepType *> (tdep) != nullptr' failed.
>    A problem internal to GDB has been detected,
>    further debugging may prove unreliable.
> 
> The same error is encountered if, instead of starting a new inferior,
> the user tries to attach to an x86-64 process with a RISC-V binary set
> as the current executable.
> 
> These errors are not specific to the x86-64/RISC-V pairing I'm using
> here, any attempt to use a binary for one architecture with a native
> target of a different architecture will result in a similar error.
> 
> Clearly, attempting to use this cross-architecture combination is a
> user error, but I think GDB should do better than an assert; ideally a
> nice error should be printed.
> 
> The problem we run into is that, when the user starts a new inferior,
> or attaches to an inferior, the inferior stops.  At this point GDB
> attempts to handle the stop, and this involves reading registers from
> the inferior.
> 
> These register reads end up being done through the native target, so
> in the example above, we end up in the amd64_supply_fxsave function.
> However, these functions need a gdbarch.  The gdbarch is fetched from
> the register set, which was constructed using the gdbarch from the
> binary currently in use.  And so we end up in amd64_supply_fxsave
> using a RISC-V gdbarch.
> 
> When we call:
> 
>    i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
> 
> this will assert as the gdbarch_tdep data within the RISC-V gdbarch is
> of the type riscv_gdbarch_tdep not i386_gdbarch_tdep.
> 
> The solution I propose in this commit is to add a new target_ops
> method supports_architecture_p.  This method will return true if a
> target can safely be used with a specific architecture, otherwise, the
> method returns false.
> 
> I imagine that a result of true from this method doesn't guarantee
> that GDB can start an inferior of a given architecture, it just means
> that GDB will not crash if such an attempt is made.  A result of false
> is a hard stop; attempting to use this target with this architecture
> is not supported, and may cause GDB to crash.
> 
> This distinction is important I think for things like remote targets,
> and possibly simulator targets.  We might imagine that GDB can ask a
> remote (or simulator) to start with a particular executable, and the
> target might still refuse for some reason.  But my thinking is that
> these refusals should be well handled (i.e. GDB should give a user
> friendly error), rather than crashing, as is the case with the native
> targets.
> 
> For example, if I start gdbserver on an x86-64 machine like this:
> 
>    gdbserver --multi :54321
> 
> Then use GDB to try and load a RISC-V binary, like this:
> 
>    $ ./gdb/gdb -q --data-directory ./gdb/data-directory/
>    (gdb) file /tmp/hello.rv32imc.x
>    Reading symbols from /tmp/hello.rv32imc.x...
>    (gdb) target extended-remote :54321
>    Remote debugging using :54321
>    (gdb) run
>    Starting program: /tmp/hello.rv32imc.x
>    Running the default executable on the remote target failed; try "set remote exec-file"?
>    (gdb)
> 
> Though the error is not very helpful in diagnosing the problem, we can
> see that GDB has not crashed, but has given the user an error.
> 
> And so, the supports_architecture_p method is created to return true
> by default, then I override this in inf_child_target, where I compare
> the architecture in question with the default_bfd_arch.
> 
> Finally, I've added calls to supports_architecture_p for the
> run (which covers run, start, starti) and attach commands.
> 
> This leaves just one question, what about native targets that support
> multiple architectures?
> 
> These targets can be split into two groups.  First, we have targets
> like x86-64, which also supports i386 binaries.  This case is easy to
> handle, as far as BFD is concerned there is only one architecture,
> bfd_arch_i386, and we then use machine types to split this
> architecture into x86-64 and i386 (and others).  As the new
> supports_architecture_p function only checks the bfd architecture,
> then there is nothing additional needed for this case.
> 
> The second group of multi-architecture targets requires more work.
> The only targets that I'm aware of that fall into this group are the
> rs6000-aix-nat.c, ppc-*-nat.c targets, and the aarch64-linux-nat.c
> target.
> 
> The first group (rs600/ppc) support bfd_arch_rs6000 and
> bfd_arch_powerpc, while the second (aarch64) supports bfd_arch_arm and
> bfd_arch_aarch64.
> 
> To deal with these targets I have overridden the
> supports_architecture_p function in each of the separate target files,
> these overrides check both of the supported architectures.
> 
> One final note, in the rs6000/ppc case, the FreeBSD target supports
> both architectures, and so we override supports_architecture_p.  In
> contrast, the aarch64_fbsd_nat_target target does not (yet) support
> bfd_arch_arm, and so there is no supports_architecture_p here.  This
> can always be added later if/when support is added.
> 
> You will notice a lack of tests for this change.  I'm not sure of a
> good way that I can build a binary for a different architecture as
> part of a test, but if anyone has any ideas then I'll be happy to add
> a test here.  The gdb.base/multi-arch.exp test exists, which for
> AArch64 will test compiling and running something as both AArch64 and
> ARM, but this doesn't cover the error case, just that the overridden
> supports_architecture_p works in that case.

Thanks, the *BSD changes all look good to me.  At some point I will
probably get around to fixing aarch64-fbsd-nat.c to support 32-bit arm.

-- 
John Baldwin

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCHv2 3/6] gdb/arm: avoid undefined behaviour in arm_frame_is_thumb
  2022-06-10 15:49       ` Andrew Burgess
@ 2022-06-10 16:29         ` Luis Machado
  0 siblings, 0 replies; 83+ messages in thread
From: Luis Machado @ 2022-06-10 16:29 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

On 6/10/22 16:49, Andrew Burgess wrote:
> Luis Machado via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
>> On 6/10/22 14:08, Andrew Burgess via Gdb-patches wrote:
>>> This commit fixes real undefined behaviour in GDB which I spotted when
>>> working on a later patch in this series.  The later patch in this
>>> series detects when the result of gdbarch_tdep() is cast to the wrong
>>> type.
>>>
>>> The issue is revealed by the gdb.multi/multi-arch.exp test.
>>>
>>> In this test we setup two inferiors, an AArch64 process, and an ARM
>>> process, then at one point we have inferior 1 selected (the AArch64
>>> inferior), and we place a breakpoint on a symbol present in the other
>>> inferior (the ARM inferior).
>>>
>>> During the process of creating the breakpoint we call arm_pc_is_thumb,
>>> the GDBARCH passed into this function is correct, that is, represents
>>> the ARM process.
>>>
>>> For whatever reason we are unable to figure out if the address in
>>> question is thumb or not throughout most of arm_pc_is_thumb, and so we
>>> get to this code at the end of the function:
>>>
>>>     /* If we couldn't find any symbol, but we're talking to a running
>>>        target, then trust the current value of $cpsr.  This lets
>>>        "display/i $pc" always show the correct mode (though if there is
>>>        a symbol table we will not reach here, so it still may not be
>>>        displayed in the mode it will be executed).  */
>>>     if (target_has_registers ())
>>>       return arm_frame_is_thumb (get_current_frame ());
>>>
>>> Which I guess is a last attempt to figure out the thumb status of an
>>> address.  However, remember, we the AArch64 inferior is current at
>>> this time, so the current frame is an AArch64 frame.
>>
>> If we're trying to insert a breakpoint into a 32-bit inferior,
>> we should really have the 32-bit arm gdbarch at hand, not the AArch64
>> gdbarch.
> 
> We do.
> 
>>
>> I think the bug is somewhere else, in whoever passed the current inferior's gdbarch
>> as opposed to the gdbarch of the inferior that contains the symbol
>> we've found.
> 
> We do pass in the gdbarch of the inferior containing the breakpoint location.
> 
> If I change the condition to an assert, then run
> gdb.multi/multi-arch.exp and catch the assertion, the stack looks like
> this:
> 
>    #0  internal_error (file=0x55834840c8 "../../src/gdb/arm-tdep.c", line=551,
>        fmt=0x5583483d70 "%s: Assertion `%s' failed.") at ../../src/gdbsupport/errors.cc:51
>    #1  0x0000005582b0e6a4 in arm_frame_is_thumb (frame=0x55c0849a00) at ../../src/gdb/arm-tdep.c:551
>    #2  0x0000005582b0eb70 in arm_pc_is_thumb (gdbarch=0x55c0937080, memaddr=4195692) at ../../src/gdb/arm-tdep.c:687
>    #3  0x0000005582b17e70 in arm_adjust_breakpoint_address (gdbarch=0x55c0937080, bpaddr=4195692)
>        at ../../src/gdb/arm-tdep.c:4925
>    #4  0x0000005582af0a60 in gdbarch_adjust_breakpoint_address (gdbarch=0x55c0937080, bpaddr=4195692)
>        at ../../src/gdb/gdbarch.c:2840
>    #5  0x0000005582b73c90 in adjust_breakpoint_address (gdbarch=0x55c0937080, bpaddr=4195692, bptype=bp_breakpoint)
>        at ../../src/gdb/breakpoint.c:7147
>    #6  0x0000005582b76854 in code_breakpoint::add_location (this=0x55c088e340, sal=...)
>        at ../../src/gdb/breakpoint.c:8100
>    #7  0x0000005582b773b8 in code_breakpoint::code_breakpoint (this=0x55c088e340, gdbarch_=0x55c089c050,
>        type_=bp_breakpoint, sals=..., location_=..., filter_=std::unique_ptr<char> = {...},
>        cond_string_=std::unique_ptr<char> = {...}, extra_string_=std::unique_ptr<char> = {...},
>        disposition_=disp_donttouch, thread_=-1, task_=0, ignore_count_=0, from_tty=1, enabled_=1, flags=0,
>        display_canonical_=0) at ../../src/gdb/breakpoint.c:8329
>    #8  0x0000005582b90c00 in ordinary_breakpoint::code_breakpoint (this=0x55c088e340) at ../../src/gdb/breakpoint.c:266
>    #9  0x0000005582b88758 in new_breakpoint_from_type<gdb::array_view<symtab_and_line const>&, std::unique_ptr<event_location, event_location_deleter>, std::unique_ptr<char, gdb::xfree_deleter<char> >, std::unique_ptr<char, gdb::xfree_deleter<char> >, std::unique_ptr<char, gdb::xfree_deleter<char> >, bpdisp&, int&, int&, int&, int&, int&, unsigned int&, int&> (gdbarch=0x55c089c050, type=bp_breakpoint) at ../../src/gdb/breakpoint.c:1303
>    #10 0x0000005582b77710 in create_breakpoint_sal (gdbarch=0x55c089c050, sals=..., location=...,
>        filter=std::unique_ptr<char> = {...}, cond_string=std::unique_ptr<char> = {...},
>        extra_string=std::unique_ptr<char> = {...}, type=bp_breakpoint, disposition=disp_donttouch, thread=-1, task=0,
>        ignore_count=0, from_tty=1, enabled=1, internal=0, flags=0, display_canonical=0)
>        at ../../src/gdb/breakpoint.c:8395
>    #11 0x0000005582b779d8 in create_breakpoints_sal (gdbarch=0x55c089c050, canonical=0x7fd8d196c0,
>        cond_string=std::unique_ptr<char> = {...}, extra_string=std::unique_ptr<char> = {...}, type=bp_breakpoint,
>        disposition=disp_donttouch, thread=-1, task=0, ignore_count=0, from_tty=1, enabled=1, internal=0, flags=0)
>        at ../../src/gdb/breakpoint.c:8438
>    #12 0x0000005582b78d94 in create_breakpoint (gdbarch=0x55c089c050, location=0x55c0979750, cond_string=0x0, thread=-1,
>        extra_string=0x0, force_condition=false, parse_extra=1, tempflag=0, type_wanted=bp_breakpoint, ignore_count=0,
>        pending_break_support=AUTO_BOOLEAN_AUTO, ops=0x558389c650 <code_breakpoint_ops>, from_tty=1, enabled=1,
>        internal=0, flags=0) at ../../src/gdb/breakpoint.c:8923
>    #13 0x0000005582b792d8 in break_command_1 (arg=0x55c0732fc2 "", flag=0, from_tty=1) at ../../src/gdb/breakpoint.c:8994
>    #14 0x0000005582b79578 in break_command (arg=0x55c0732fb6 "hangout_loop", from_tty=1)
>        at ../../src/gdb/breakpoint.c:9065
> 
> In frame #6 we select a gdbarch based on the location of the breakpoint,
> its at this point that we select the bfd_arch_arm gdbarch.
> 
> For frames #5, #4, #3, and #2 we are passing in a bfd_arch_arm gdbarch,
> which is correct, and what you are asking for.
> 
> The problem is that in frame #2 we fail to find any of the special hints
> that indicate if the code is thumb or not.  Now, _maybe_ you could argue
> that one of the conditions in arm_pc_is_thumb should trigger, but, for
> me, the very fact that there is a "catch all" case at the end of the
> function means we have to be open to the possibility that non of the
> special symbols, or bottom bit of the address set cases might trigger.
> 
> And so, we get to this code in arm_pc_is_thumb:
> 
>    if (target_has_registers ())
>      return arm_frame_is_thumb (get_current_frame ());

Thanks for the above backtrace, that was very helpful. Yeah, this call is making the wrong assumption
that the current frame is arm. This is clearly not always valid on a multi-arch scenario.

> 
> At this point GDBARCH _is_ a bfd_arch_arm architecture.
> 
> But, the current frame is bfd_arch_aarch64.
> 
> And so, we enter frame #1, arm_frame_is_thumb, passing in a frame that
> is not bfd_arch_arm.
> 
> So, are you are suggesting we should switch frames as part of the
> breakpoint setting process?  Because I'm not sure how you'd pick even a
> suitable inferior, multiple ARM inferiors might share a single program
> space, so we could have a single gdbarch, but multiple inferiors, each
> with multiple threads, and each thread with multiple frames...
> 

The correct way to do it is to fetch the frame from the inferior containing the
breakpoint location, but you're right that there isn't a good way to do it here.

Ideally GDB would keep per-inferior frame data, but it doesn't. This looks like a
limitation of GDB. If you have the same bfd for all inferiors, I suppose you could
get away with it.

In this case though, trying to use the aarch64 bfd to do an operation for the arm bfd
is not going to work.

> I guess we could push the architecture check out of arm_frame_is_thumb
> back to arm_pc_is_thumb, and only call arm_frame_is_thumb for the case
> where the architecture is ARM... that doesn't make sense to me, but
> maybe, I guess...

It also doesn't make sense, because then the answer to whether we have thumb or
not is always going to be false for an aarch64 bfd. We might as well return false
and not fetch the frame.

> 
> Anyway, let me know if the above makes any more sense.  If it does I can
> update the commit message
Given this is broken either way, let's go with your patch. But could you
please add a comment in the bfd check stating this is currently incorrect
because fetching the current_frame doesn't reflect the correct inferior?

I'll take a look at this later, but I don't want to block your series.

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCHv2 6/6] gdb: native target invalid architecture detection
  2022-06-10 13:08   ` [PATCHv2 6/6] gdb: native target invalid architecture detection Andrew Burgess
  2022-06-10 16:20     ` John Baldwin
@ 2022-06-10 16:31     ` Luis Machado
  1 sibling, 0 replies; 83+ messages in thread
From: Luis Machado @ 2022-06-10 16:31 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

On 6/10/22 14:08, Andrew Burgess via Gdb-patches wrote:
> If GDB is asked to start a new inferior, or attach to an existing
> process, using a binary file for an architecture that does not match
> the current native target, then, currently, GDB will assert.  Here's
> an example session using current HEAD of master with GDB built for an
> x86-64 GNU/Linux native target, the binary being used is a RISC-V ELF:
> 
>    $ ./gdb/gdb -q --data-directory ./gdb/data-directory/
>    (gdb) file /tmp/hello.rv32imc.x
>    Reading symbols from /tmp/hello.rv32imc.x...
>    (gdb) start
>    Temporary breakpoint 1 at 0x101b2: file hello.rv32.c, line 23.
>    Starting program: /tmp/hello.rv32imc.x
>    ../../src/gdb/gdbarch.h:166: internal-error: gdbarch_tdep: Assertion `dynamic_cast<TDepType *> (tdep) != nullptr' failed.
>    A problem internal to GDB has been detected,
>    further debugging may prove unreliable.
> 
> The same error is encountered if, instead of starting a new inferior,
> the user tries to attach to an x86-64 process with a RISC-V binary set
> as the current executable.
> 
> These errors are not specific to the x86-64/RISC-V pairing I'm using
> here, any attempt to use a binary for one architecture with a native
> target of a different architecture will result in a similar error.
> 
> Clearly, attempting to use this cross-architecture combination is a
> user error, but I think GDB should do better than an assert; ideally a
> nice error should be printed.
> 
> The problem we run into is that, when the user starts a new inferior,
> or attaches to an inferior, the inferior stops.  At this point GDB
> attempts to handle the stop, and this involves reading registers from
> the inferior.
> 
> These register reads end up being done through the native target, so
> in the example above, we end up in the amd64_supply_fxsave function.
> However, these functions need a gdbarch.  The gdbarch is fetched from
> the register set, which was constructed using the gdbarch from the
> binary currently in use.  And so we end up in amd64_supply_fxsave
> using a RISC-V gdbarch.
> 
> When we call:
> 
>    i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
> 
> this will assert as the gdbarch_tdep data within the RISC-V gdbarch is
> of the type riscv_gdbarch_tdep not i386_gdbarch_tdep.
> 
> The solution I propose in this commit is to add a new target_ops
> method supports_architecture_p.  This method will return true if a
> target can safely be used with a specific architecture, otherwise, the
> method returns false.
> 
> I imagine that a result of true from this method doesn't guarantee
> that GDB can start an inferior of a given architecture, it just means
> that GDB will not crash if such an attempt is made.  A result of false
> is a hard stop; attempting to use this target with this architecture
> is not supported, and may cause GDB to crash.
> 
> This distinction is important I think for things like remote targets,
> and possibly simulator targets.  We might imagine that GDB can ask a
> remote (or simulator) to start with a particular executable, and the
> target might still refuse for some reason.  But my thinking is that
> these refusals should be well handled (i.e. GDB should give a user
> friendly error), rather than crashing, as is the case with the native
> targets.
> 
> For example, if I start gdbserver on an x86-64 machine like this:
> 
>    gdbserver --multi :54321
> 
> Then use GDB to try and load a RISC-V binary, like this:
> 
>    $ ./gdb/gdb -q --data-directory ./gdb/data-directory/
>    (gdb) file /tmp/hello.rv32imc.x
>    Reading symbols from /tmp/hello.rv32imc.x...
>    (gdb) target extended-remote :54321
>    Remote debugging using :54321
>    (gdb) run
>    Starting program: /tmp/hello.rv32imc.x
>    Running the default executable on the remote target failed; try "set remote exec-file"?
>    (gdb)
> 
> Though the error is not very helpful in diagnosing the problem, we can
> see that GDB has not crashed, but has given the user an error.
> 
> And so, the supports_architecture_p method is created to return true
> by default, then I override this in inf_child_target, where I compare
> the architecture in question with the default_bfd_arch.
> 
> Finally, I've added calls to supports_architecture_p for the
> run (which covers run, start, starti) and attach commands.
> 
> This leaves just one question, what about native targets that support
> multiple architectures?
> 
> These targets can be split into two groups.  First, we have targets
> like x86-64, which also supports i386 binaries.  This case is easy to
> handle, as far as BFD is concerned there is only one architecture,
> bfd_arch_i386, and we then use machine types to split this
> architecture into x86-64 and i386 (and others).  As the new
> supports_architecture_p function only checks the bfd architecture,
> then there is nothing additional needed for this case.
> 
> The second group of multi-architecture targets requires more work.
> The only targets that I'm aware of that fall into this group are the
> rs6000-aix-nat.c, ppc-*-nat.c targets, and the aarch64-linux-nat.c
> target.
> 
> The first group (rs600/ppc) support bfd_arch_rs6000 and
> bfd_arch_powerpc, while the second (aarch64) supports bfd_arch_arm and
> bfd_arch_aarch64.
> 
> To deal with these targets I have overridden the
> supports_architecture_p function in each of the separate target files,
> these overrides check both of the supported architectures.
> 
> One final note, in the rs6000/ppc case, the FreeBSD target supports
> both architectures, and so we override supports_architecture_p.  In
> contrast, the aarch64_fbsd_nat_target target does not (yet) support
> bfd_arch_arm, and so there is no supports_architecture_p here.  This
> can always be added later if/when support is added.
> 
> You will notice a lack of tests for this change.  I'm not sure of a
> good way that I can build a binary for a different architecture as
> part of a test, but if anyone has any ideas then I'll be happy to add
> a test here.  The gdb.base/multi-arch.exp test exists, which for
> AArch64 will test compiling and running something as both AArch64 and
> ARM, but this doesn't cover the error case, just that the overridden
> supports_architecture_p works in that case.
> ---
>   gdb/aarch64-linux-nat.c |  8 ++++++++
>   gdb/arch-utils.c        |  8 ++++++++
>   gdb/arch-utils.h        |  5 +++++
>   gdb/inf-child.c         | 19 +++++++++++++++++++
>   gdb/inf-child.h         |  2 ++
>   gdb/infcmd.c            |  8 ++++++++
>   gdb/ppc-fbsd-nat.c      |  8 ++++++++
>   gdb/ppc-linux-nat.c     |  8 ++++++++
>   gdb/ppc-obsd-nat.c      |  8 ++++++++
>   gdb/rs6000-aix-nat.c    |  8 ++++++++
>   gdb/target-delegates.c  | 28 ++++++++++++++++++++++++++++
>   gdb/target.h            | 13 ++++++++++++-
>   12 files changed, 122 insertions(+), 1 deletion(-)
> 
> diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c
> index a457fcd48ad..6114c4c6638 100644
> --- a/gdb/aarch64-linux-nat.c
> +++ b/gdb/aarch64-linux-nat.c
> @@ -108,6 +108,14 @@ class aarch64_linux_nat_target final
>     /* Write allocation tags to memory via PTRACE.  */
>     bool store_memtags (CORE_ADDR address, size_t len,
>   		      const gdb::byte_vector &tags, int type) override;
> +
> +  /* This target supports two architectures, check for them both here.  */
> +
> +  bool supports_architecture_p (struct gdbarch *gdbarch) override
> +  {
> +    bfd_architecture the_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
> +    return (the_arch == bfd_arch_aarch64 || the_arch == bfd_arch_arm);
> +  }
>   };
>   
>   static aarch64_linux_nat_target the_aarch64_linux_nat_target;
> diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
> index 360b8d694be..efba17e1d5d 100644
> --- a/gdb/arch-utils.c
> +++ b/gdb/arch-utils.c
> @@ -1570,6 +1570,14 @@ target_gdbarch (void)
>     return current_inferior ()->gdbarch;
>   }
>   
> +/* See arch-utils.h.  */
> +
> +bool
> +gdbarch_matches_default_arch (struct gdbarch *gdbarch)
> +{
> +  return gdbarch_bfd_arch_info (gdbarch)->arch == default_bfd_arch->arch;
> +}
> +
>   void _initialize_gdbarch_utils ();
>   void
>   _initialize_gdbarch_utils ()
> diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h
> index f850e5fd6e7..5d61be36c26 100644
> --- a/gdb/arch-utils.h
> +++ b/gdb/arch-utils.h
> @@ -300,4 +300,9 @@ extern void default_read_core_file_mappings
>      struct bfd *cbfd,
>      read_core_file_mappings_pre_loop_ftype pre_loop_cb,
>      read_core_file_mappings_loop_ftype loop_cb);
> +
> +/* Return true if the bfd architecture of GDBARCH matches the default bfd
> +   architecture.  */
> +
> +extern bool gdbarch_matches_default_arch (struct gdbarch *gdbarch);
>   #endif /* ARCH_UTILS_H */
> diff --git a/gdb/inf-child.c b/gdb/inf-child.c
> index 56ebd2a5549..0c47a367c68 100644
> --- a/gdb/inf-child.c
> +++ b/gdb/inf-child.c
> @@ -30,6 +30,8 @@
>   #include "inferior.h"
>   #include <sys/stat.h>
>   #include "inf-child.h"
> +#include "gdbarch.h"
> +#include "arch-utils.h"
>   #include "gdbsupport/fileio.h"
>   #include "gdbsupport/agent.h"
>   #include "gdbsupport/gdb_wait.h"
> @@ -412,6 +414,23 @@ inf_child_target::follow_exec (inferior *follow_inf, ptid_t ptid,
>       }
>   }
>   
> +/* The inf_child_target represents the native target built into GDB, of
> +   which there is only ever one.  If we attempt to start a native inferior
> +   using a binary for an architecture not matching the native target then,
> +   when we handle the first stop, we will end up trying to read registers
> +   using the gdbarch functions from the native target, but passing in a
> +   gdbarch object based on the architecture of the binary file.  This will
> +   result in errors.
> +
> +   This check prevents this so long as everywhere user command that might
> +   cause a new inferior to be created calls this function.  */
> +
> +bool
> +inf_child_target::supports_architecture_p (struct gdbarch *gdbarch)
> +{
> +  return gdbarch_matches_default_arch (gdbarch);
> +}
> +
>   /* See inf-child.h.  */
>   
>   void
> diff --git a/gdb/inf-child.h b/gdb/inf-child.h
> index ae5ace46f30..01a8164b0c2 100644
> --- a/gdb/inf-child.h
> +++ b/gdb/inf-child.h
> @@ -92,6 +92,8 @@ class inf_child_target
>   
>     bool can_use_agent () override;
>   
> +  bool supports_architecture_p (struct gdbarch *gdbarch) override;
> +
>   protected:
>     /* Unpush the target if it wasn't explicitly open with "target native"
>        and there are no live inferiors left.  Note: if calling this as a
> diff --git a/gdb/infcmd.c b/gdb/infcmd.c
> index e909d4d4c81..b8acf858b3a 100644
> --- a/gdb/infcmd.c
> +++ b/gdb/infcmd.c
> @@ -413,6 +413,10 @@ run_command_1 (const char *args, int from_tty, enum run_how run_how)
>     if (non_stop && !run_target->supports_non_stop ())
>       error (_("The target does not support running in non-stop mode."));
>   
> +  if (!run_target->supports_architecture_p (get_current_arch ()))
> +    error (_("The target does not support architecture \"%s\"."),
> +	   gdbarch_bfd_arch_info (get_current_arch ())->printable_name);
> +
>     /* Done.  Can now set breakpoints, change inferior args, etc.  */
>   
>     /* Insert temporary breakpoint in main function if requested.  */
> @@ -2590,6 +2594,10 @@ attach_command (const char *args, int from_tty)
>     if (non_stop && !attach_target->supports_non_stop ())
>       error (_("Cannot attach to this target in non-stop mode"));
>   
> +  if (!attach_target->supports_architecture_p (get_current_arch ()))
> +    error (_("The target does not support architecture \"%s\"."),
> +	   gdbarch_bfd_arch_info (get_current_arch ())->printable_name);
> +
>     attach_target->attach (args, from_tty);
>     /* to_attach should push the target, so after this point we
>        shouldn't refer to attach_target again.  */
> diff --git a/gdb/ppc-fbsd-nat.c b/gdb/ppc-fbsd-nat.c
> index d0a5778e2d3..f7c36c33958 100644
> --- a/gdb/ppc-fbsd-nat.c
> +++ b/gdb/ppc-fbsd-nat.c
> @@ -41,6 +41,14 @@ struct ppc_fbsd_nat_target final : public fbsd_nat_target
>   {
>     void fetch_registers (struct regcache *, int) override;
>     void store_registers (struct regcache *, int) override;
> +
> +  /* This target supports two architectures, check for them both here.  */
> +
> +  bool supports_architecture_p (struct gdbarch *gdbarch) override
> +  {
> +    bfd_architecture the_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
> +    return (the_arch == bfd_arch_rs6000 || the_arch == bfd_arch_powerpc);
> +  }
>   };
>   
>   static ppc_fbsd_nat_target the_ppc_fbsd_nat_target;
> diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c
> index de4158c411a..e302b15925a 100644
> --- a/gdb/ppc-linux-nat.c
> +++ b/gdb/ppc-linux-nat.c
> @@ -551,6 +551,14 @@ struct ppc_linux_nat_target final : public linux_nat_target
>   
>     void low_prepare_to_resume (struct lwp_info *) override;
>   
> +  /* This target supports two architectures, check for them both here.  */
> +
> +  bool supports_architecture_p (struct gdbarch *gdbarch) override
> +  {
> +    bfd_architecture the_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
> +    return (the_arch == bfd_arch_rs6000 || the_arch == bfd_arch_powerpc);
> +  }
> +
>   private:
>   
>     void copy_thread_dreg_state (const ptid_t &parent_ptid,
> diff --git a/gdb/ppc-obsd-nat.c b/gdb/ppc-obsd-nat.c
> index e480f19dc73..2fdccc3085d 100644
> --- a/gdb/ppc-obsd-nat.c
> +++ b/gdb/ppc-obsd-nat.c
> @@ -39,6 +39,14 @@ struct ppc_obsd_nat_target final : public obsd_nat_target
>   {
>     void fetch_registers (struct regcache *, int) override;
>     void store_registers (struct regcache *, int) override;
> +
> +  /* This target supports two architectures, check for them both here.  */
> +
> +  bool supports_architecture_p (struct gdbarch *gdbarch) override
> +  {
> +    bfd_architecture the_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
> +    return (the_arch == bfd_arch_rs6000 || the_arch == bfd_arch_powerpc);
> +  }
>   };
>   
>   static ppc_obsd_nat_target the_ppc_obsd_nat_target;
> diff --git a/gdb/rs6000-aix-nat.c b/gdb/rs6000-aix-nat.c
> index 8697d27b4ed..603caa8fb1e 100644
> --- a/gdb/rs6000-aix-nat.c
> +++ b/gdb/rs6000-aix-nat.c
> @@ -91,6 +91,14 @@ class rs6000_nat_target final : public inf_ptrace_target
>   
>     ptid_t wait (ptid_t, struct target_waitstatus *, target_wait_flags) override;
>   
> +  /* This target supports two architectures, check for them both here.  */
> +
> +  bool supports_architecture_p (struct gdbarch *gdbarch) override
> +  {
> +    bfd_architecture the_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
> +    return (the_arch == bfd_arch_rs6000 || the_arch == bfd_arch_powerpc);
> +  }
> +
>   protected:
>   
>     void post_startup_inferior (ptid_t ptid) override
> diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c
> index 8a9986454dd..cb7bb1f2062 100644
> --- a/gdb/target-delegates.c
> +++ b/gdb/target-delegates.c
> @@ -196,6 +196,7 @@ struct dummy_target : public target_ops
>     bool supports_memory_tagging () override;
>     bool fetch_memtags (CORE_ADDR arg0, size_t arg1, gdb::byte_vector &arg2, int arg3) override;
>     bool store_memtags (CORE_ADDR arg0, size_t arg1, const gdb::byte_vector &arg2, int arg3) override;
> +  bool supports_architecture_p (struct gdbarch *arg0) override;
>   };
>   
>   struct debug_target : public target_ops
> @@ -370,6 +371,7 @@ struct debug_target : public target_ops
>     bool supports_memory_tagging () override;
>     bool fetch_memtags (CORE_ADDR arg0, size_t arg1, gdb::byte_vector &arg2, int arg3) override;
>     bool store_memtags (CORE_ADDR arg0, size_t arg1, const gdb::byte_vector &arg2, int arg3) override;
> +  bool supports_architecture_p (struct gdbarch *arg0) override;
>   };
>   
>   void
> @@ -4536,3 +4538,29 @@ debug_target::store_memtags (CORE_ADDR arg0, size_t arg1, const gdb::byte_vector
>     return result;
>   }
>   
> +bool
> +target_ops::supports_architecture_p (struct gdbarch *arg0)
> +{
> +  return this->beneath ()->supports_architecture_p (arg0);
> +}
> +
> +bool
> +dummy_target::supports_architecture_p (struct gdbarch *arg0)
> +{
> +  return true;
> +}
> +
> +bool
> +debug_target::supports_architecture_p (struct gdbarch *arg0)
> +{
> +  bool result;
> +  gdb_printf (gdb_stdlog, "-> %s->supports_architecture_p (...)\n", this->beneath ()->shortname ());
> +  result = this->beneath ()->supports_architecture_p (arg0);
> +  gdb_printf (gdb_stdlog, "<- %s->supports_architecture_p (", this->beneath ()->shortname ());
> +  target_debug_print_struct_gdbarch_p (arg0);
> +  gdb_puts (") = ", gdb_stdlog);
> +  target_debug_print_bool (result);
> +  gdb_puts ("\n", gdb_stdlog);
> +  return result;
> +}
> +
> diff --git a/gdb/target.h b/gdb/target.h
> index 18559feef89..5f3ae77f559 100644
> --- a/gdb/target.h
> +++ b/gdb/target.h
> @@ -1320,7 +1320,18 @@ struct target_ops
>       virtual bool store_memtags (CORE_ADDR address, size_t len,
>   				const gdb::byte_vector &tags, int type)
>         TARGET_DEFAULT_NORETURN (tcomplain ());
> -  };
> +
> +    /* Return false if the target does not support GDBARCH, otherwise,
> +       return true.
> +
> +       The default reply of true does not guarantee that debugging an
> +       inferior with architecture GDBARCH will succeed, other errors might
> +       be thrown later on, but a return value of false is a clear
> +       indication that we should not proceed attempting to use this
> +       architecture with this target.  */
> +    virtual bool supports_architecture_p (struct gdbarch *gdbarch)
> +      TARGET_DEFAULT_RETURN (true);
> +};
>   
>   /* Deleter for std::unique_ptr.  See comments in
>      target_ops::~target_ops and target_ops::close about heap-allocated

LGTM from aarch64's side.

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCHv2 4/6] gdb: move the type cast into gdbarch_tdep
  2022-06-10 13:08   ` [PATCHv2 4/6] gdb: move the type cast into gdbarch_tdep Andrew Burgess
@ 2022-06-10 16:35     ` Luis Machado
  0 siblings, 0 replies; 83+ messages in thread
From: Luis Machado @ 2022-06-10 16:35 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

On 6/10/22 14:08, Andrew Burgess via Gdb-patches wrote:
> I built GDB for all targets on a x86-64/GNU-Linux system, and
> then (accidentally) passed GDB a RISC-V binary, and asked GDB to "run"
> the binary on the native target.  I got this error:
> 
>    (gdb) show architecture
>    The target architecture is set to "auto" (currently "i386").
>    (gdb) file /tmp/hello.rv32.exe
>    Reading symbols from /tmp/hello.rv32.exe...
>    (gdb) show architecture
>    The target architecture is set to "auto" (currently "riscv:rv32").
>    (gdb) run
>    Starting program: /tmp/hello.rv32.exe
>    ../../src/gdb/i387-tdep.c:596: internal-error: i387_supply_fxsave: Assertion `tdep->st0_regnum >= I386_ST0_REGNUM' failed.
> 
> What's going on here is this; initially the architecture is i386, this
> is based on the default architecture, which is set based on the native
> target.  After loading the RISC-V executable the architecture of the
> current inferior is updated based on the architecture of the
> executable.
> 
> When we "run", GDB does a fork & exec, with the inferior being
> controlled through ptrace.  GDB sees an initial stop from the inferior
> as soon as the inferior comes to life.  In response to this stop GDB
> ends up calling save_stop_reason (linux-nat.c), which ends up trying
> to read register from the inferior, to do this we end up calling
> target_ops::fetch_registers, which, for the x86-64 native target,
> calls amd64_linux_nat_target::fetch_registers.
> 
> After this I eventually end up in i387_supply_fxsave, different x86
> based targets will end in different functions to fetch registers, but
> it doesn't really matter which function we end up in, the problem is
> this line, which is repeated in many places:
> 
>    i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
> 
> The problem here is that the ARCH in this line comes from the current
> inferior, which, as we discussed above, will be a RISC-V gdbarch, the
> tdep field will actually be of type riscv_gdbarch_tdep, not
> i386_gdbarch_tdep.  After this cast we are relying on undefined
> behaviour, in my case I happen to trigger an assert, but this might
> not always be the case.
> 
> The thing I tried that exposed this problem was of course, trying to
> start an executable of the wrong architecture on a native target.  I
> don't think that the correct solution for this problem is to detect,
> at the point of cast, that the gdbarch_tdep object is of the wrong
> type, but, I did wonder, is there a way that we could protect
> ourselves from incorrectly casting the gdbarch_tdep object?
> 
> I think that there is something we can do here, and this commit is the
> first step in that direction, though no actual check is added by this
> commit.
> 
> This commit can be split into two parts:
> 
>   (1) In gdbarch.h and arch-utils.c.  In these files I have modified
>   gdbarch_tdep (the function) so that it now takes a template argument,
>   like this:
> 
>      template<typename TDepType>
>      static inline TDepType *
>      gdbarch_tdep (struct gdbarch *gdbarch)
>      {
>        struct gdbarch_tdep *tdep = gdbarch_tdep_1 (gdbarch);
>        return static_cast<TDepType *> (tdep);
>      }
> 
>    After this change we are no better protected, but the cast is now
>    done within the gdbarch_tdep function rather than at the call sites,
>    this leads to the second, much larger change in this commit,
> 
>    (2) Everywhere gdbarch_tdep is called, we make changes like this:
> 
>      -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
>      +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
> 
> There should be no functional change after this commit.
> 
> In the next commit I will build on this change to add an assertion in
> gdbarch_tdep that checks we are casting to the correct type.
> ---
>   gdb/aarch64-fbsd-nat.c     |   4 +-
>   gdb/aarch64-fbsd-tdep.c    |   6 +-
>   gdb/aarch64-linux-nat.c    |  20 +++---
>   gdb/aarch64-linux-tdep.c   |  10 +--
>   gdb/aarch64-newlib-tdep.c  |   2 +-
>   gdb/aarch64-tdep.c         |  48 +++++++-------
>   gdb/aix-thread.c           |  28 ++++----
>   gdb/alpha-linux-tdep.c     |   2 +-
>   gdb/alpha-netbsd-tdep.c    |   2 +-
>   gdb/alpha-obsd-tdep.c      |   2 +-
>   gdb/alpha-tdep.c           |  14 ++--
>   gdb/amd64-darwin-tdep.c    |   2 +-
>   gdb/amd64-fbsd-nat.c       |   4 +-
>   gdb/amd64-fbsd-tdep.c      |   4 +-
>   gdb/amd64-linux-tdep.c     |   8 +--
>   gdb/amd64-netbsd-tdep.c    |   2 +-
>   gdb/amd64-obsd-tdep.c      |   2 +-
>   gdb/amd64-sol2-tdep.c      |   2 +-
>   gdb/amd64-tdep.c           |  34 +++++-----
>   gdb/amd64-windows-tdep.c   |   2 +-
>   gdb/arc-linux-tdep.c       |   4 +-
>   gdb/arc-newlib-tdep.c      |   2 +-
>   gdb/arc-tdep.c             |   8 +--
>   gdb/arch-utils.c           |   6 +-
>   gdb/arm-fbsd-nat.c         |   4 +-
>   gdb/arm-fbsd-tdep.c        |   6 +-
>   gdb/arm-linux-nat.c        |   8 +--
>   gdb/arm-linux-tdep.c       |   4 +-
>   gdb/arm-netbsd-nat.c       |   8 +--
>   gdb/arm-netbsd-tdep.c      |   4 +-
>   gdb/arm-none-tdep.c        |   2 +-
>   gdb/arm-obsd-tdep.c        |   2 +-
>   gdb/arm-tdep.c             | 110 +++++++++++++++----------------
>   gdb/arm-wince-tdep.c       |   2 +-
>   gdb/avr-tdep.c             |  12 ++--
>   gdb/bfin-tdep.c            |   4 +-
>   gdb/cris-linux-tdep.c      |   2 +-
>   gdb/cris-tdep.c            |  18 ++---
>   gdb/csky-tdep.c            |   2 +-
>   gdb/frv-tdep.c             |   4 +-
>   gdb/ft32-tdep.c            |   2 +-
>   gdb/gdbarch.h              |  17 ++++-
>   gdb/hppa-bsd-tdep.c        |   2 +-
>   gdb/hppa-linux-tdep.c      |   4 +-
>   gdb/hppa-tdep.c            |  12 ++--
>   gdb/i386-bsd-tdep.c        |   2 +-
>   gdb/i386-darwin-tdep.c     |   4 +-
>   gdb/i386-fbsd-tdep.c       |   4 +-
>   gdb/i386-gnu-tdep.c        |   2 +-
>   gdb/i386-go32-tdep.c       |   2 +-
>   gdb/i386-linux-tdep.c      |   4 +-
>   gdb/i386-netbsd-tdep.c     |   4 +-
>   gdb/i386-nto-tdep.c        |   6 +-
>   gdb/i386-obsd-tdep.c       |   2 +-
>   gdb/i386-sol2-tdep.c       |   2 +-
>   gdb/i386-tdep.c            |  98 +++++++++++++--------------
>   gdb/i386-windows-tdep.c    |   2 +-
>   gdb/i387-tdep.c            |  20 +++---
>   gdb/ia64-linux-tdep.c      |   2 +-
>   gdb/ia64-tdep.c            |  12 ++--
>   gdb/loongarch-linux-nat.c  |   6 +-
>   gdb/loongarch-linux-tdep.c |   8 +--
>   gdb/loongarch-tdep.c       |  10 +--
>   gdb/m32c-tdep.c            |  58 ++++++++--------
>   gdb/m68hc11-tdep.c         |  12 ++--
>   gdb/m68k-bsd-tdep.c        |   2 +-
>   gdb/m68k-linux-tdep.c      |   2 +-
>   gdb/m68k-tdep.c            |  38 +++++------
>   gdb/mep-tdep.c             |   6 +-
>   gdb/mips-linux-tdep.c      |   4 +-
>   gdb/mips-tdep.c            |  50 +++++++-------
>   gdb/mn10300-tdep.c         |   2 +-
>   gdb/mn10300-tdep.h         |   2 +-
>   gdb/msp430-tdep.c          |  12 ++--
>   gdb/nds32-tdep.c           |  20 +++---
>   gdb/nios2-linux-tdep.c     |   2 +-
>   gdb/nios2-tdep.c           |   4 +-
>   gdb/or1k-tdep.c            |   8 +--
>   gdb/ppc-fbsd-nat.c         |   4 +-
>   gdb/ppc-fbsd-tdep.c        |   8 +--
>   gdb/ppc-linux-nat.c        |  22 +++----
>   gdb/ppc-linux-tdep.c       |  18 ++---
>   gdb/ppc-netbsd-nat.c       |   6 +-
>   gdb/ppc-netbsd-tdep.c      |   2 +-
>   gdb/ppc-obsd-nat.c         |   4 +-
>   gdb/ppc-obsd-tdep.c        |   2 +-
>   gdb/ppc-sysv-tdep.c        |  22 +++----
>   gdb/ppc64-tdep.c           |   2 +-
>   gdb/riscv-linux-tdep.c     |   2 +-
>   gdb/riscv-tdep.c           |  26 ++++----
>   gdb/rl78-tdep.c            |   8 +--
>   gdb/rs6000-aix-nat.c       |   6 +-
>   gdb/rs6000-aix-tdep.c      |  16 ++---
>   gdb/rs6000-lynx178-tdep.c  |   4 +-
>   gdb/rs6000-tdep.c          | 132 ++++++++++++++++++-------------------
>   gdb/rx-tdep.c              |   2 +-
>   gdb/s390-linux-tdep.c      |  20 +++---
>   gdb/s390-tdep.c            |  42 ++++++------
>   gdb/sh-linux-tdep.c        |   2 +-
>   gdb/sh-netbsd-tdep.c       |   2 +-
>   gdb/sh-tdep.c              |   8 +--
>   gdb/sparc-linux-tdep.c     |   4 +-
>   gdb/sparc-netbsd-tdep.c    |   2 +-
>   gdb/sparc-sol2-tdep.c      |   2 +-
>   gdb/sparc-tdep.c           |  14 ++--
>   gdb/sparc64-fbsd-tdep.c    |   2 +-
>   gdb/sparc64-linux-tdep.c   |   4 +-
>   gdb/sparc64-netbsd-tdep.c  |   2 +-
>   gdb/sparc64-obsd-tdep.c    |   2 +-
>   gdb/sparc64-sol2-tdep.c    |   2 +-
>   gdb/sparc64-tdep.c         |  10 +--
>   gdb/tic6x-linux-tdep.c     |   6 +-
>   gdb/tic6x-tdep.c           |   6 +-
>   gdb/v850-tdep.c            |   6 +-
>   gdb/windows-nat.c          |   2 +-
>   gdb/xtensa-linux-nat.c     |   4 +-
>   gdb/xtensa-linux-tdep.c    |   2 +-
>   gdb/xtensa-tdep.c          |  54 +++++++--------
>   gdb/z80-tdep.c             |   8 +--
>   119 files changed, 684 insertions(+), 667 deletions(-)
> 
> diff --git a/gdb/aarch64-fbsd-nat.c b/gdb/aarch64-fbsd-nat.c
> index d8cf6227e73..708ddc40d58 100644
> --- a/gdb/aarch64-fbsd-nat.c
> +++ b/gdb/aarch64-fbsd-nat.c
> @@ -90,7 +90,7 @@ aarch64_fbsd_nat_target::fetch_registers (struct regcache *regcache,
>   				    &aarch64_fbsd_fpregset);
>   
>     gdbarch *gdbarch = regcache->arch ();
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>     if (tdep->has_tls ())
>       {
>         const struct regcache_map_entry aarch64_fbsd_tls_regmap[] =
> @@ -123,7 +123,7 @@ aarch64_fbsd_nat_target::store_registers (struct regcache *regcache,
>   				    PT_SETFPREGS, &aarch64_fbsd_fpregset);
>   
>     gdbarch *gdbarch = regcache->arch ();
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>     if (tdep->has_tls ())
>       {
>         const struct regcache_map_entry aarch64_fbsd_tls_regmap[] =
> diff --git a/gdb/aarch64-fbsd-tdep.c b/gdb/aarch64-fbsd-tdep.c
> index 891546b3c64..4a6b4115234 100644
> --- a/gdb/aarch64-fbsd-tdep.c
> +++ b/gdb/aarch64-fbsd-tdep.c
> @@ -143,7 +143,7 @@ aarch64_fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   					   void *cb_data,
>   					   const struct regcache *regcache)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     cb (".reg", AARCH64_FBSD_SIZEOF_GREGSET, AARCH64_FBSD_SIZEOF_GREGSET,
>         &aarch64_fbsd_gregset, NULL, cb_data);
> @@ -190,7 +190,7 @@ static CORE_ADDR
>   aarch64_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
>   				       CORE_ADDR lm_addr, CORE_ADDR offset)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>     struct regcache *regcache;
>   
>     regcache = get_thread_arch_regcache (current_inferior ()->process_target (),
> @@ -213,7 +213,7 @@ aarch64_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
>   static void
>   aarch64_fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     /* Generic FreeBSD support.  */
>     fbsd_init_abi (info, gdbarch);
> diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c
> index d58ad0143a2..a457fcd48ad 100644
> --- a/gdb/aarch64-linux-nat.c
> +++ b/gdb/aarch64-linux-nat.c
> @@ -359,7 +359,7 @@ static void
>   fetch_pauth_masks_from_thread (struct regcache *regcache)
>   {
>     aarch64_gdbarch_tdep *tdep
> -    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
>     int ret;
>     struct iovec iovec;
>     uint64_t pauth_regset[2] = {0, 0};
> @@ -385,7 +385,7 @@ static void
>   fetch_mteregs_from_thread (struct regcache *regcache)
>   {
>     aarch64_gdbarch_tdep *tdep
> -    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
>     int regno = tdep->mte_reg_base;
>   
>     gdb_assert (regno != -1);
> @@ -410,7 +410,7 @@ static void
>   store_mteregs_to_thread (struct regcache *regcache)
>   {
>     aarch64_gdbarch_tdep *tdep
> -    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
>     int regno = tdep->mte_reg_base;
>   
>     gdb_assert (regno != -1);
> @@ -439,7 +439,7 @@ static void
>   fetch_tlsregs_from_thread (struct regcache *regcache)
>   {
>     aarch64_gdbarch_tdep *tdep
> -    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
>     int regno = tdep->tls_regnum;
>   
>     gdb_assert (regno != -1);
> @@ -464,7 +464,7 @@ static void
>   store_tlsregs_to_thread (struct regcache *regcache)
>   {
>     aarch64_gdbarch_tdep *tdep
> -    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
>     int regno = tdep->tls_regnum;
>   
>     gdb_assert (regno != -1);
> @@ -493,7 +493,7 @@ static void
>   aarch64_fetch_registers (struct regcache *regcache, int regno)
>   {
>     aarch64_gdbarch_tdep *tdep
> -    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
>   
>     if (regno == -1)
>       {
> @@ -543,7 +543,7 @@ static void
>   aarch32_fetch_registers (struct regcache *regcache, int regno)
>   {
>     arm_gdbarch_tdep *tdep
> -    = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
>   
>     if (regno == -1)
>       {
> @@ -579,7 +579,7 @@ static void
>   aarch64_store_registers (struct regcache *regcache, int regno)
>   {
>     aarch64_gdbarch_tdep *tdep
> -    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
>   
>     if (regno == -1)
>       {
> @@ -619,7 +619,7 @@ static void
>   aarch32_store_registers (struct regcache *regcache, int regno)
>   {
>     arm_gdbarch_tdep *tdep
> -    = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
>   
>     if (regno == -1)
>       {
> @@ -893,7 +893,7 @@ aarch64_linux_nat_target::thread_architecture (ptid_t ptid)
>   
>     /* Only return it if the current vector length matches the one in the tdep.  */
>     aarch64_gdbarch_tdep *tdep
> -    = (aarch64_gdbarch_tdep *) gdbarch_tdep (inf->gdbarch);
> +    = gdbarch_tdep<aarch64_gdbarch_tdep> (inf->gdbarch);
>     uint64_t vq = aarch64_sve_get_vq (ptid.lwp ());
>     if (vq == tdep->vq)
>       return inf->gdbarch;
> diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c
> index 453692df2f4..4c96662efb3 100644
> --- a/gdb/aarch64-linux-tdep.c
> +++ b/gdb/aarch64-linux-tdep.c
> @@ -286,7 +286,7 @@ aarch64_linux_sigframe_init (const struct tramp_frame *self,
>   {
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>     CORE_ADDR sp = get_frame_register_unsigned (this_frame, AARCH64_SP_REGNUM);
>     CORE_ADDR sigcontext_addr = (sp + AARCH64_RT_SIGFRAME_UCONTEXT_OFFSET
>   			       + AARCH64_UCONTEXT_SIGCONTEXT_OFFSET );
> @@ -640,7 +640,7 @@ aarch64_linux_collect_sve_regset (const struct regset *regset,
>     gdb_byte *header = (gdb_byte *) buf;
>     struct gdbarch *gdbarch = regcache->arch ();
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>     uint64_t vq = tdep->vq;
>   
>     gdb_assert (buf != NULL);
> @@ -676,7 +676,7 @@ aarch64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   					    void *cb_data,
>   					    const struct regcache *regcache)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     cb (".reg", AARCH64_LINUX_SIZEOF_GREGSET, AARCH64_LINUX_SIZEOF_GREGSET,
>         &aarch64_linux_gregset, NULL, cb_data);
> @@ -1743,7 +1743,7 @@ aarch64_linux_report_signal_info (struct gdbarch *gdbarch,
>   				  struct ui_out *uiout,
>   				  enum gdb_signal siggnal)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->has_mte () || siggnal != GDB_SIGNAL_SEGV)
>       return;
> @@ -1812,7 +1812,7 @@ aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   								    NULL };
>     static const char *const stap_register_indirection_suffixes[] = { "]",
>   								    NULL };
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     tdep->lowest_pc = 0x8000;
>   
> diff --git a/gdb/aarch64-newlib-tdep.c b/gdb/aarch64-newlib-tdep.c
> index 507b7fc5a51..c9236b17801 100644
> --- a/gdb/aarch64-newlib-tdep.c
> +++ b/gdb/aarch64-newlib-tdep.c
> @@ -29,7 +29,7 @@
>   static void
>   aarch64_newlib_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     /* Jump buffer - support for longjmp.
>        Offset of original PC in jump buffer (in registers).  */
> diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
> index 15b577c8a00..8670197a888 100644
> --- a/gdb/aarch64-tdep.c
> +++ b/gdb/aarch64-tdep.c
> @@ -502,7 +502,7 @@ aarch64_analyze_prologue (struct gdbarch *gdbarch,
>         else if (inst.opcode->iclass == ic_system)
>   	{
>   	  aarch64_gdbarch_tdep *tdep
> -	    = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +	    = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   	  int ra_state_val = 0;
>   
>   	  if (insn == 0xd503233f /* paciasp.  */
> @@ -640,7 +640,7 @@ aarch64_analyze_prologue_test (void)
>     struct aarch64_prologue_cache cache;
>     cache.saved_regs = trad_frame_alloc_saved_regs (gdbarch);
>   
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     /* Test the simple prologue in which frame pointer is used.  */
>     {
> @@ -1076,7 +1076,7 @@ aarch64_prologue_frame_unwind_stop_reason (struct frame_info *this_frame,
>   
>     /* Halt the backtrace at "_start".  */
>     gdbarch *arch = get_frame_arch (this_frame);
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (arch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (arch);
>     if (cache->prev_pc <= tdep->lowest_pc)
>       return UNWIND_OUTERMOST;
>   
> @@ -1120,7 +1120,7 @@ aarch64_prologue_prev_register (struct frame_info *this_frame,
>         CORE_ADDR lr;
>         struct gdbarch *gdbarch = get_frame_arch (this_frame);
>         aarch64_gdbarch_tdep *tdep
> -	= (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +	= gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>         lr = frame_unwind_register_unsigned (this_frame, AARCH64_LR_REGNUM);
>   
> @@ -1289,7 +1289,7 @@ aarch64_dwarf2_prev_register (struct frame_info *this_frame,
>   			      void **this_cache, int regnum)
>   {
>     gdbarch *arch = get_frame_arch (this_frame);
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (arch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (arch);
>     CORE_ADDR lr;
>   
>     switch (regnum)
> @@ -1315,7 +1315,7 @@ aarch64_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
>   			       struct dwarf2_frame_state_reg *reg,
>   			       struct frame_info *this_frame)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     switch (regnum)
>       {
> @@ -1355,7 +1355,7 @@ static bool
>   aarch64_execute_dwarf_cfa_vendor_op (struct gdbarch *gdbarch, gdb_byte op,
>   				     struct dwarf2_frame_state *fs)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>     struct dwarf2_frame_state_reg *ra_state;
>   
>     if (op == DW_CFA_AARCH64_negate_ra_state)
> @@ -1996,7 +1996,7 @@ aarch64_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
>   static struct type *
>   aarch64_vnq_type (struct gdbarch *gdbarch)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->vnq_type == NULL)
>       {
> @@ -2023,7 +2023,7 @@ aarch64_vnq_type (struct gdbarch *gdbarch)
>   static struct type *
>   aarch64_vnd_type (struct gdbarch *gdbarch)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->vnd_type == NULL)
>       {
> @@ -2053,7 +2053,7 @@ aarch64_vnd_type (struct gdbarch *gdbarch)
>   static struct type *
>   aarch64_vns_type (struct gdbarch *gdbarch)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->vns_type == NULL)
>       {
> @@ -2083,7 +2083,7 @@ aarch64_vns_type (struct gdbarch *gdbarch)
>   static struct type *
>   aarch64_vnh_type (struct gdbarch *gdbarch)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->vnh_type == NULL)
>       {
> @@ -2116,7 +2116,7 @@ aarch64_vnh_type (struct gdbarch *gdbarch)
>   static struct type *
>   aarch64_vnb_type (struct gdbarch *gdbarch)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->vnb_type == NULL)
>       {
> @@ -2143,7 +2143,7 @@ aarch64_vnb_type (struct gdbarch *gdbarch)
>   static struct type *
>   aarch64_vnv_type (struct gdbarch *gdbarch)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->vnv_type == NULL)
>       {
> @@ -2214,7 +2214,7 @@ aarch64_vnv_type (struct gdbarch *gdbarch)
>   static int
>   aarch64_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     if (reg >= AARCH64_DWARF_X0 && reg <= AARCH64_DWARF_X0 + 30)
>       return AARCH64_X0_REGNUM + reg - AARCH64_DWARF_X0;
> @@ -2518,7 +2518,7 @@ aarch64_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
>     CORE_ADDR jb_addr;
>     gdb_byte buf[X_REGISTER_SIZE];
>     struct gdbarch *gdbarch = get_frame_arch (frame);
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>   
>     jb_addr = get_frame_register_unsigned (frame, AARCH64_X0_REGNUM);
> @@ -2549,7 +2549,7 @@ aarch64_gen_return_address (struct gdbarch *gdbarch,
>   static const char *
>   aarch64_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     static const char *const q_name[] =
>       {
> @@ -2663,7 +2663,7 @@ aarch64_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
>   static struct type *
>   aarch64_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     int p_regnum = regnum - gdbarch_num_regs (gdbarch);
>   
> @@ -2700,7 +2700,7 @@ static int
>   aarch64_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
>   				    const struct reggroup *group)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     int p_regnum = regnum - gdbarch_num_regs (gdbarch);
>   
> @@ -2754,7 +2754,7 @@ static struct value *
>   aarch64_pseudo_read_value (struct gdbarch *gdbarch, readable_regcache *regcache,
>   			   int regnum)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>     struct value *result_value = allocate_value (register_type (gdbarch, regnum));
>   
>     VALUE_LVAL (result_value) = lval_register;
> @@ -2824,7 +2824,7 @@ static void
>   aarch64_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache,
>   		      int regnum, const gdb_byte *buf)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>     regnum -= gdbarch_num_regs (gdbarch);
>   
>     if (regnum >= AARCH64_Q0_REGNUM && regnum < AARCH64_Q0_REGNUM + 32)
> @@ -3377,7 +3377,7 @@ aarch64_get_tdesc_vq (const struct target_desc *tdesc)
>   static int
>   aarch64_cannot_store_register (struct gdbarch *gdbarch, int regnum)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->has_pauth ())
>       return 0;
> @@ -3444,7 +3444,7 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
>       {
>         aarch64_gdbarch_tdep *tdep
> -	= (aarch64_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
> +	= gdbarch_tdep<aarch64_gdbarch_tdep> (best_arch->gdbarch);
>         if (tdep && tdep->vq == vq)
>   	return best_arch->gdbarch;
>       }
> @@ -3693,7 +3693,7 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>   static void
>   aarch64_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
>   {
> -  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
>   
>     if (tdep == NULL)
>       return;
> @@ -3915,7 +3915,7 @@ aarch64_record_branch_except_sys (aarch64_insn_decode_record *aarch64_insn_r)
>   {
>   
>     aarch64_gdbarch_tdep *tdep
> -    = (aarch64_gdbarch_tdep *) gdbarch_tdep (aarch64_insn_r->gdbarch);
> +    = gdbarch_tdep<aarch64_gdbarch_tdep> (aarch64_insn_r->gdbarch);
>     uint8_t insn_bits24_27, insn_bits28_31, insn_bits22_23;
>     uint32_t record_buf[4];
>   
> diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c
> index ecd8200b692..3d76b8c6d01 100644
> --- a/gdb/aix-thread.c
> +++ b/gdb/aix-thread.c
> @@ -1114,7 +1114,7 @@ static void
>   supply_gprs64 (struct regcache *regcache, uint64_t *vals)
>   {
>     ppc_gdbarch_tdep *tdep
> -    = (ppc_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<ppc_gdbarch_tdep> (regcache->arch ());
>     int regno;
>   
>     for (regno = 0; regno < ppc_num_gprs; regno++)
> @@ -1136,7 +1136,7 @@ static void
>   supply_fprs (struct regcache *regcache, double *vals)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int regno;
>   
>     /* This function should never be called on architectures without
> @@ -1154,7 +1154,7 @@ supply_fprs (struct regcache *regcache, double *vals)
>   static int
>   special_register_p (struct gdbarch *gdbarch, int regno)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     return regno == gdbarch_pc_regnum (gdbarch)
>         || regno == tdep->ppc_ps_regnum
> @@ -1177,7 +1177,7 @@ supply_sprs64 (struct regcache *regcache,
>   	       uint32_t fpscr)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     regcache->raw_supply (gdbarch_pc_regnum (gdbarch), (char *) &iar);
>     regcache->raw_supply (tdep->ppc_ps_regnum, (char *) &msr);
> @@ -1199,7 +1199,7 @@ supply_sprs32 (struct regcache *regcache,
>   	       uint32_t fpscr)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     regcache->raw_supply (gdbarch_pc_regnum (gdbarch), (char *) &iar);
>     regcache->raw_supply (tdep->ppc_ps_regnum, (char *) &msr);
> @@ -1222,7 +1222,7 @@ static void
>   fetch_regs_user_thread (struct regcache *regcache, pthdb_pthread_t pdtid)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int status, i;
>     pthdb_context_t ctx;
>   
> @@ -1277,7 +1277,7 @@ fetch_regs_kernel_thread (struct regcache *regcache, int regno,
>   			  pthdb_tid_t tid)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     uint64_t gprs64[ppc_num_gprs];
>     uint32_t gprs32[ppc_num_gprs];
>     double fprs[ppc_num_fprs];
> @@ -1380,7 +1380,7 @@ static void
>   fill_gprs64 (const struct regcache *regcache, uint64_t *vals)
>   {
>     ppc_gdbarch_tdep *tdep
> -    = (ppc_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<ppc_gdbarch_tdep> (regcache->arch ());
>     int regno;
>   
>     for (regno = 0; regno < ppc_num_gprs; regno++)
> @@ -1393,7 +1393,7 @@ static void
>   fill_gprs32 (const struct regcache *regcache, uint32_t *vals)
>   {
>     ppc_gdbarch_tdep *tdep
> -    = (ppc_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<ppc_gdbarch_tdep> (regcache->arch ());
>     int regno;
>   
>     for (regno = 0; regno < ppc_num_gprs; regno++)
> @@ -1407,7 +1407,7 @@ static void
>   fill_fprs (const struct regcache *regcache, double *vals)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int regno;
>   
>     /* This function should never be called on architectures without
> @@ -1431,7 +1431,7 @@ fill_sprs64 (const struct regcache *regcache,
>   	     uint32_t *fpscr)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     /* Verify that the size of the size of the IAR buffer is the
>        same as the raw size of the PC (in the register cache).  If
> @@ -1465,7 +1465,7 @@ fill_sprs32 (const struct regcache *regcache,
>   	     uint32_t *fpscr)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     /* Verify that the size of the size of the IAR buffer is the
>        same as the raw size of the PC (in the register cache).  If
> @@ -1502,7 +1502,7 @@ static void
>   store_regs_user_thread (const struct regcache *regcache, pthdb_pthread_t pdtid)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int status, i;
>     pthdb_context_t ctx;
>     uint32_t int32;
> @@ -1592,7 +1592,7 @@ store_regs_kernel_thread (const struct regcache *regcache, int regno,
>   			  pthdb_tid_t tid)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     uint64_t gprs64[ppc_num_gprs];
>     uint32_t gprs32[ppc_num_gprs];
>     double fprs[ppc_num_fprs];
> diff --git a/gdb/alpha-linux-tdep.c b/gdb/alpha-linux-tdep.c
> index 6cea40d3f34..c103aafc1ff 100644
> --- a/gdb/alpha-linux-tdep.c
> +++ b/gdb/alpha-linux-tdep.c
> @@ -362,7 +362,7 @@ alpha_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>     /* Hook into the MDEBUG frame unwinder.  */
>     alpha_mdebug_init_abi (info, gdbarch);
>   
> -  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
>     tdep->dynamic_sigtramp_offset = alpha_linux_sigtramp_offset;
>     tdep->sigcontext_addr = alpha_linux_sigcontext_addr;
>     tdep->pc_in_sigtramp = alpha_linux_pc_in_sigtramp;
> diff --git a/gdb/alpha-netbsd-tdep.c b/gdb/alpha-netbsd-tdep.c
> index 6b604cfa9c6..72d7019377f 100644
> --- a/gdb/alpha-netbsd-tdep.c
> +++ b/gdb/alpha-netbsd-tdep.c
> @@ -250,7 +250,7 @@ static void
>   alphanbsd_init_abi (struct gdbarch_info info,
>   		    struct gdbarch *gdbarch)
>   {
> -  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
>   
>     /* Hook into the DWARF CFI frame unwinder.  */
>     alpha_dwarf2_init_abi (info, gdbarch);
> diff --git a/gdb/alpha-obsd-tdep.c b/gdb/alpha-obsd-tdep.c
> index 8baa8cc32c4..c0d672c3f72 100644
> --- a/gdb/alpha-obsd-tdep.c
> +++ b/gdb/alpha-obsd-tdep.c
> @@ -97,7 +97,7 @@ alphaobsd_sigcontext_addr (struct frame_info *this_frame)
>   static void
>   alphaobsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
>   
>     /* Hook into the DWARF CFI frame unwinder.  */
>     alpha_dwarf2_init_abi (info, gdbarch);
> diff --git a/gdb/alpha-tdep.c b/gdb/alpha-tdep.c
> index f04bad6bed8..44efc8e4bbb 100644
> --- a/gdb/alpha-tdep.c
> +++ b/gdb/alpha-tdep.c
> @@ -615,7 +615,7 @@ alpha_return_value (struct gdbarch *gdbarch, struct value *function,
>   		    gdb_byte *readbuf, const gdb_byte *writebuf)
>   {
>     enum type_code code = type->code ();
> -  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
>   
>     if ((code == TYPE_CODE_STRUCT
>          || code == TYPE_CODE_UNION
> @@ -851,7 +851,7 @@ static int
>   alpha_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (frame);
> -  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     CORE_ADDR jb_addr;
>     gdb_byte raw_buffer[ALPHA_REGISTER_SIZE];
> @@ -891,7 +891,7 @@ alpha_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
>     *this_prologue_cache = info;
>   
>     gdbarch *arch = get_frame_arch (this_frame);
> -  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (arch);
> +  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (arch);
>     info->sigcontext_addr = tdep->sigcontext_addr (this_frame);
>   
>     return info;
> @@ -904,7 +904,7 @@ static CORE_ADDR
>   alpha_sigtramp_register_address (struct gdbarch *gdbarch,
>   				 CORE_ADDR sigcontext_addr, int regnum)
>   {
> -  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
>   
>     if (regnum >= 0 && regnum < 32)
>       return sigcontext_addr + tdep->sc_regs_offset + regnum * 8;
> @@ -925,7 +925,7 @@ alpha_sigtramp_frame_this_id (struct frame_info *this_frame,
>   			      struct frame_id *this_id)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
>     struct alpha_sigtramp_unwind_cache *info
>       = alpha_sigtramp_frame_unwind_cache (this_frame, this_prologue_cache);
>     CORE_ADDR stack_addr, code_addr;
> @@ -1000,7 +1000,7 @@ alpha_sigtramp_frame_sniffer (const struct frame_unwind *self,
>   
>     /* We shouldn't even bother to try if the OSABI didn't register a
>        sigcontext_addr handler or pc_in_sigtramp handler.  */
> -  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
>     if (tdep->sigcontext_addr == NULL)
>       return 0;
>   
> @@ -1041,7 +1041,7 @@ static int heuristic_fence_post = 0;
>   static CORE_ADDR
>   alpha_heuristic_proc_start (struct gdbarch *gdbarch, CORE_ADDR pc)
>   {
> -  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
>     CORE_ADDR last_non_nop = pc;
>     CORE_ADDR fence = pc - heuristic_fence_post;
>     CORE_ADDR orig_pc = pc;
> diff --git a/gdb/amd64-darwin-tdep.c b/gdb/amd64-darwin-tdep.c
> index 74906f6a02d..7fc35536bc6 100644
> --- a/gdb/amd64-darwin-tdep.c
> +++ b/gdb/amd64-darwin-tdep.c
> @@ -97,7 +97,7 @@ amd64_darwin_sigcontext_addr (struct frame_info *this_frame)
>   static void
>   x86_darwin_init_abi_64 (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     amd64_init_abi (info, gdbarch,
>   		  amd64_target_description (X86_XSTATE_SSE_MASK, true));
> diff --git a/gdb/amd64-fbsd-nat.c b/gdb/amd64-fbsd-nat.c
> index d125d582a21..7023a182e78 100644
> --- a/gdb/amd64-fbsd-nat.c
> +++ b/gdb/amd64-fbsd-nat.c
> @@ -102,7 +102,7 @@ amd64_fbsd_nat_target::fetch_registers (struct regcache *regcache, int regnum)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
>   #if defined(PT_GETFSBASE) || defined(PT_GETGSBASE)
> -  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   #endif
>     pid_t pid = get_ptrace_pid (regcache->ptid ());
>     const struct regset *gregset = find_gregset (gdbarch);
> @@ -174,7 +174,7 @@ amd64_fbsd_nat_target::store_registers (struct regcache *regcache, int regnum)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
>   #if defined(PT_GETFSBASE) || defined(PT_GETGSBASE)
> -  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   #endif
>     pid_t pid = get_ptrace_pid (regcache->ptid ());
>     const struct regset *gregset = find_gregset (gdbarch);
> diff --git a/gdb/amd64-fbsd-tdep.c b/gdb/amd64-fbsd-tdep.c
> index 55764beaad2..8e40283d838 100644
> --- a/gdb/amd64-fbsd-tdep.c
> +++ b/gdb/amd64-fbsd-tdep.c
> @@ -262,7 +262,7 @@ amd64fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   					void *cb_data,
>   					const struct regcache *regcache)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     cb (".reg", AMD64_FBSD_SIZEOF_GREGSET, AMD64_FBSD_SIZEOF_GREGSET,
>         &amd64_fbsd_gregset, NULL, cb_data);
> @@ -299,7 +299,7 @@ amd64fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
>   static void
>   amd64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* Generic FreeBSD support. */
>     fbsd_init_abi (info, gdbarch);
> diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
> index 9a0759d639c..aa9c56586ab 100644
> --- a/gdb/amd64-linux-tdep.c
> +++ b/gdb/amd64-linux-tdep.c
> @@ -1656,7 +1656,7 @@ amd64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   					  void *cb_data,
>   					  const struct regcache *regcache)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     cb (".reg", 27 * 8, 27 * 8, &i386_gregset, NULL, cb_data);
>     cb (".reg2", 512, 512, &amd64_fpregset, NULL, cb_data);
> @@ -1793,7 +1793,7 @@ static void
>   amd64_linux_init_abi_common(struct gdbarch_info info, struct gdbarch *gdbarch,
>   			    int num_disp_step_buffers)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     linux_init_abi (info, gdbarch, num_disp_step_buffers);
>   
> @@ -1846,7 +1846,7 @@ amd64_linux_init_abi_common(struct gdbarch_info info, struct gdbarch *gdbarch,
>   static void
>   amd64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     struct tdesc_arch_data *tdesc_data = info.tdesc_data;
>     const struct tdesc_feature *feature;
>     int valid_p;
> @@ -2060,7 +2060,7 @@ amd64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   static void
>   amd64_x32_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     struct tdesc_arch_data *tdesc_data = info.tdesc_data;
>     const struct tdesc_feature *feature;
>     int valid_p;
> diff --git a/gdb/amd64-netbsd-tdep.c b/gdb/amd64-netbsd-tdep.c
> index 3ab0267060d..59d723caa55 100644
> --- a/gdb/amd64-netbsd-tdep.c
> +++ b/gdb/amd64-netbsd-tdep.c
> @@ -97,7 +97,7 @@ int amd64nbsd_r_reg_offset[] =
>   static void
>   amd64nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* Initialize general-purpose register set details first.  */
>     tdep->gregset_reg_offset = amd64nbsd_r_reg_offset;
> diff --git a/gdb/amd64-obsd-tdep.c b/gdb/amd64-obsd-tdep.c
> index 3cb64fe924f..f0bc7c474a6 100644
> --- a/gdb/amd64-obsd-tdep.c
> +++ b/gdb/amd64-obsd-tdep.c
> @@ -420,7 +420,7 @@ static const struct frame_unwind amd64obsd_trapframe_unwind =
>   static void
>   amd64obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     amd64_init_abi (info, gdbarch,
>   		  amd64_target_description (X86_XSTATE_SSE_MASK, true));
> diff --git a/gdb/amd64-sol2-tdep.c b/gdb/amd64-sol2-tdep.c
> index 22a48e476a5..ce96eb045ec 100644
> --- a/gdb/amd64-sol2-tdep.c
> +++ b/gdb/amd64-sol2-tdep.c
> @@ -80,7 +80,7 @@ amd64_sol2_mcontext_addr (struct frame_info *this_frame)
>   static void
>   amd64_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     tdep->gregset_reg_offset = amd64_sol2_gregset_reg_offset;
>     tdep->gregset_num_regs = ARRAY_SIZE (amd64_sol2_gregset_reg_offset);
> diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
> index b95ab1e87b8..0563b32a54b 100644
> --- a/gdb/amd64-tdep.c
> +++ b/gdb/amd64-tdep.c
> @@ -247,7 +247,7 @@ static const int amd64_dwarf_regmap_len =
>   static int
>   amd64_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int ymm0_regnum = tdep->ymm0_regnum;
>     int regnum = -1;
>   
> @@ -331,7 +331,7 @@ static const char * const amd64_dword_names[] =
>   static const char *
>   amd64_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     if (i386_byte_regnum_p (gdbarch, regnum))
>       return amd64_byte_names[regnum - tdep->al_regnum];
>     else if (i386_zmm_regnum_p (gdbarch, regnum))
> @@ -353,7 +353,7 @@ amd64_pseudo_register_read_value (struct gdbarch *gdbarch,
>   				  readable_regcache *regcache,
>   				  int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     value *result_value = allocate_value (register_type (gdbarch, regnum));
>     VALUE_LVAL (result_value) = lval_register;
> @@ -413,7 +413,7 @@ amd64_pseudo_register_write (struct gdbarch *gdbarch,
>   			     struct regcache *regcache,
>   			     int regnum, const gdb_byte *buf)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     if (i386_byte_regnum_p (gdbarch, regnum))
>       {
> @@ -465,7 +465,7 @@ static int
>   amd64_ax_pseudo_register_collect (struct gdbarch *gdbarch,
>   				  struct agent_expr *ax, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     if (i386_byte_regnum_p (gdbarch, regnum))
>       {
> @@ -2749,7 +2749,7 @@ static struct amd64_frame_cache *
>   amd64_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     struct amd64_frame_cache *cache;
>     CORE_ADDR addr;
> @@ -2832,7 +2832,7 @@ amd64_sigtramp_frame_sniffer (const struct frame_unwind *self,
>   			      void **this_cache)
>   {
>     gdbarch *arch = get_frame_arch (this_frame);
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
>   
>     /* We shouldn't even bother if we don't have a sigcontext_addr
>        handler.  */
> @@ -3032,7 +3032,7 @@ amd64_supply_fpregset (const struct regset *regset, struct regcache *regcache,
>   		       int regnum, const void *fpregs, size_t len)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     gdb_assert (len >= tdep->sizeof_fpregset);
>     amd64_supply_fxsave (regcache, regnum, fpregs);
> @@ -3049,7 +3049,7 @@ amd64_collect_fpregset (const struct regset *regset,
>   			int regnum, void *fpregs, size_t len)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     gdb_assert (len >= tdep->sizeof_fpregset);
>     amd64_collect_fxsave (regcache, regnum, fpregs);
> @@ -3073,7 +3073,7 @@ amd64_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
>     gdb_byte buf[8];
>     CORE_ADDR jb_addr;
>     struct gdbarch *gdbarch = get_frame_arch (frame);
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int jb_pc_offset = tdep->jb_pc_offset;
>     int len = TYPE_LENGTH (builtin_type (gdbarch)->builtin_func_ptr);
>   
> @@ -3117,7 +3117,7 @@ void
>   amd64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch,
>   		const target_desc *default_tdesc)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     const struct target_desc *tdesc = info.target_desc;
>     static const char *const stap_integer_prefixes[] = { "$", NULL };
>     static const char *const stap_register_prefixes[] = { "%", NULL };
> @@ -3296,7 +3296,7 @@ amd64_none_init_abi (gdbarch_info info, gdbarch *arch)
>   static struct type *
>   amd64_x32_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     switch (regnum - tdep->eax_regnum)
>       {
> @@ -3314,7 +3314,7 @@ void
>   amd64_x32_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch,
>   		    const target_desc *default_tdesc)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     amd64_init_abi (info, gdbarch, default_tdesc);
>   
> @@ -3384,7 +3384,7 @@ amd64_supply_fxsave (struct regcache *regcache, int regnum,
>   		     const void *fxsave)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     i387_supply_fxsave (regcache, regnum, fxsave);
>   
> @@ -3407,7 +3407,7 @@ amd64_supply_xsave (struct regcache *regcache, int regnum,
>   		    const void *xsave)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     i387_supply_xsave (regcache, regnum, xsave);
>   
> @@ -3442,7 +3442,7 @@ amd64_collect_fxsave (const struct regcache *regcache, int regnum,
>   		      void *fxsave)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     gdb_byte *regs = (gdb_byte *) fxsave;
>   
>     i387_collect_fxsave (regcache, regnum, fxsave);
> @@ -3463,7 +3463,7 @@ amd64_collect_xsave (const struct regcache *regcache, int regnum,
>   		     void *xsave, int gcore)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     gdb_byte *regs = (gdb_byte *) xsave;
>   
>     i387_collect_xsave (regcache, regnum, xsave, gcore);
> diff --git a/gdb/amd64-windows-tdep.c b/gdb/amd64-windows-tdep.c
> index eca94f2ea7c..a9aef0bab88 100644
> --- a/gdb/amd64-windows-tdep.c
> +++ b/gdb/amd64-windows-tdep.c
> @@ -1277,7 +1277,7 @@ amd64_windows_auto_wide_charset (void)
>   static void
>   amd64_windows_init_abi_common (gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* The dwarf2 unwinder (appended very early by i386_gdbarch_init) is
>        preferred over the SEH one.  The reasons are:
> diff --git a/gdb/arc-linux-tdep.c b/gdb/arc-linux-tdep.c
> index 13595f2e8e9..9c1febcd900 100644
> --- a/gdb/arc-linux-tdep.c
> +++ b/gdb/arc-linux-tdep.c
> @@ -411,7 +411,7 @@ static std::vector<CORE_ADDR>
>   arc_linux_software_single_step (struct regcache *regcache)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
>     struct disassemble_info di = arc_disassemble_info (gdbarch);
>   
>     /* Read current instruction.  */
> @@ -693,7 +693,7 @@ arc_linux_core_read_description (struct gdbarch *gdbarch,
>   static void
>   arc_linux_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
>   
>     arc_linux_debug_printf ("GNU/Linux OS/ABI initialization.");
>   
> diff --git a/gdb/arc-newlib-tdep.c b/gdb/arc-newlib-tdep.c
> index 7d7406c501c..2499dff43ec 100644
> --- a/gdb/arc-newlib-tdep.c
> +++ b/gdb/arc-newlib-tdep.c
> @@ -36,7 +36,7 @@ arc_newlib_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
>     arc_newlib_debug_printf ("Initialization.");
>   
> -  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
>   
>     /* Offset of original PC in longjmp jump buffer (in registers).  Value of PC
>        offset can be found in newlib/libc/machine/arc/setjmp.S.  */
> diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c
> index 3edfd466f3b..b9c734210fe 100644
> --- a/gdb/arc-tdep.c
> +++ b/gdb/arc-tdep.c
> @@ -1002,7 +1002,7 @@ arc_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
>     arc_debug_printf ("called");
>   
>     struct gdbarch *gdbarch = get_frame_arch (frame);
> -  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
>     int pc_offset = tdep->jb_pc * ARC_REGISTER_SIZE;
>     gdb_byte buf[ARC_REGISTER_SIZE];
>     CORE_ADDR jb_addr = get_frame_register_unsigned (frame, ARC_FIRST_ARG_REGNUM);
> @@ -1827,7 +1827,7 @@ arc_make_sigtramp_frame_cache (struct frame_info *this_frame)
>     arc_debug_printf ("called");
>   
>     gdbarch *arch = get_frame_arch (this_frame);
> -  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (arch);
> +  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (arch);
>   
>     /* Allocate new frame cache instance and space for saved register info.  */
>     struct arc_frame_cache *cache = FRAME_OBSTACK_ZALLOC (struct arc_frame_cache);
> @@ -1904,7 +1904,7 @@ arc_sigtramp_frame_sniffer (const struct frame_unwind *self,
>     arc_debug_printf ("called");
>   
>     gdbarch *arch = get_frame_arch (this_frame);
> -  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (arch);
> +  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (arch);
>   
>     /* If we have a sigcontext_addr handler, then just return 1 (same as the
>        "default_frame_sniffer ()").  */
> @@ -2431,7 +2431,7 @@ arc_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>   static void
>   arc_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
>   {
> -  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
>   
>     gdb_printf (file, "arc_dump_tdep: jb_pc = %i\n", tdep->jb_pc);
>   
> diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
> index ff946ee3767..360b8d694be 100644
> --- a/gdb/arch-utils.c
> +++ b/gdb/arch-utils.c
> @@ -1198,11 +1198,13 @@ gdbarch_free (struct gdbarch *arch)
>     xfree (obstack);
>   }
>   
> +/* See gdbarch.h.  */
> +
>   struct gdbarch_tdep *
> -gdbarch_tdep (struct gdbarch *gdbarch)
> +gdbarch_tdep_1 (struct gdbarch *gdbarch)
>   {
>     if (gdbarch_debug >= 2)
> -    gdb_printf (gdb_stdlog, "gdbarch_tdep called\n");
> +    gdb_printf (gdb_stdlog, "gdbarch_tdep_1 called\n");
>     return gdbarch->tdep;
>   }
>   
> diff --git a/gdb/arm-fbsd-nat.c b/gdb/arm-fbsd-nat.c
> index a306e1e2ee0..b161b7ed908 100644
> --- a/gdb/arm-fbsd-nat.c
> +++ b/gdb/arm-fbsd-nat.c
> @@ -55,7 +55,7 @@ arm_fbsd_nat_target::fetch_registers (struct regcache *regcache, int regnum)
>   #endif
>   #ifdef PT_GETREGSET
>     gdbarch *gdbarch = regcache->arch ();
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->tls_regnum > 0)
>       {
> @@ -90,7 +90,7 @@ arm_fbsd_nat_target::store_registers (struct regcache *regcache, int regnum)
>   #endif
>   #ifdef PT_GETREGSET
>     gdbarch *gdbarch = regcache->arch ();
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->tls_regnum > 0)
>       {
> diff --git a/gdb/arm-fbsd-tdep.c b/gdb/arm-fbsd-tdep.c
> index 483820c1092..61c8f0cecad 100644
> --- a/gdb/arm-fbsd-tdep.c
> +++ b/gdb/arm-fbsd-tdep.c
> @@ -159,7 +159,7 @@ arm_fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   				       void *cb_data,
>   				       const struct regcache *regcache)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     cb (".reg", ARM_FBSD_SIZEOF_GREGSET, ARM_FBSD_SIZEOF_GREGSET,
>         &arm_fbsd_gregset, NULL, cb_data);
> @@ -233,7 +233,7 @@ static CORE_ADDR
>   arm_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
>   				   CORE_ADDR lm_addr, CORE_ADDR offset)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>     struct regcache *regcache;
>   
>     regcache = get_thread_arch_regcache (current_inferior ()->process_target (),
> @@ -256,7 +256,7 @@ arm_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
>   static void
>   arm_fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     /* Generic FreeBSD support.  */
>     fbsd_init_abi (info, gdbarch);
> diff --git a/gdb/arm-linux-nat.c b/gdb/arm-linux-nat.c
> index 8dac8456282..0188c78fe7a 100644
> --- a/gdb/arm-linux-nat.c
> +++ b/gdb/arm-linux-nat.c
> @@ -339,7 +339,7 @@ fetch_vfp_regs (struct regcache *regcache)
>     gdb_byte regbuf[ARM_VFP3_REGS_SIZE];
>     int ret, tid;
>     struct gdbarch *gdbarch = regcache->arch ();
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     /* Get the thread id for the ptrace call.  */
>     tid = regcache->ptid ().lwp ();
> @@ -368,7 +368,7 @@ store_vfp_regs (const struct regcache *regcache)
>     gdb_byte regbuf[ARM_VFP3_REGS_SIZE];
>     int ret, tid;
>     struct gdbarch *gdbarch = regcache->arch ();
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     /* Get the thread id for the ptrace call.  */
>     tid = regcache->ptid ().lwp ();
> @@ -413,7 +413,7 @@ void
>   arm_linux_nat_target::fetch_registers (struct regcache *regcache, int regno)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (-1 == regno)
>       {
> @@ -450,7 +450,7 @@ void
>   arm_linux_nat_target::store_registers (struct regcache *regcache, int regno)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (-1 == regno)
>       {
> diff --git a/gdb/arm-linux-tdep.c b/gdb/arm-linux-tdep.c
> index f299e9665d5..d530b7f59a8 100644
> --- a/gdb/arm-linux-tdep.c
> +++ b/gdb/arm-linux-tdep.c
> @@ -712,7 +712,7 @@ arm_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   					void *cb_data,
>   					const struct regcache *regcache)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     cb (".reg", ARM_LINUX_SIZEOF_GREGSET, ARM_LINUX_SIZEOF_GREGSET,
>         &arm_linux_gregset, NULL, cb_data);
> @@ -1715,7 +1715,7 @@ arm_linux_init_abi (struct gdbarch_info info,
>   								    NULL };
>     static const char *const stap_register_indirection_suffixes[] = { "]",
>   								    NULL };
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     linux_init_abi (info, gdbarch, 1);
>   
> diff --git a/gdb/arm-netbsd-nat.c b/gdb/arm-netbsd-nat.c
> index 764bbe8cd3d..251159154c9 100644
> --- a/gdb/arm-netbsd-nat.c
> +++ b/gdb/arm-netbsd-nat.c
> @@ -50,7 +50,7 @@ static arm_netbsd_nat_target the_arm_netbsd_nat_target;
>   static void
>   arm_supply_vfpregset (struct regcache *regcache, struct fpreg *fpregset)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
>     if (tdep->vfp_register_count == 0)
>       return;
>   
> @@ -97,7 +97,7 @@ fetch_fp_register (struct regcache *regcache, int regno)
>         return;
>       }
>   
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
>     if (regno == ARM_FPSCR_REGNUM && tdep->vfp_register_count != 0)
>       regcache->raw_supply (ARM_FPSCR_REGNUM, (char *) &vfp.vfp_fpscr);
>     else if (regno >= ARM_D0_REGNUM
> @@ -279,7 +279,7 @@ store_fp_register (const struct regcache *regcache, int regno)
>         return;
>       }
>   
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
>     if (regno == ARM_FPSCR_REGNUM && tdep->vfp_register_count != 0)
>       regcache->raw_collect (ARM_FPSCR_REGNUM, (char *) &vfp.vfp_fpscr);
>     else if (regno >= ARM_D0_REGNUM
> @@ -301,7 +301,7 @@ store_fp_register (const struct regcache *regcache, int regno)
>   static void
>   store_fp_regs (const struct regcache *regcache)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
>     int lwp = regcache->ptid ().lwp ();
>     if (tdep->vfp_register_count == 0)
>       return;
> diff --git a/gdb/arm-netbsd-tdep.c b/gdb/arm-netbsd-tdep.c
> index a6a78f0b893..aa4d15df4c6 100644
> --- a/gdb/arm-netbsd-tdep.c
> +++ b/gdb/arm-netbsd-tdep.c
> @@ -111,7 +111,7 @@ static void
>   arm_netbsd_init_abi_common (struct gdbarch_info info,
>   			    struct gdbarch *gdbarch)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     tdep->lowest_pc = 0x8000;
>     switch (info.byte_order)
> @@ -148,7 +148,7 @@ static void
>   arm_netbsd_elf_init_abi (struct gdbarch_info info,
>   			 struct gdbarch *gdbarch)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     arm_netbsd_init_abi_common (info, gdbarch);
>   
> diff --git a/gdb/arm-none-tdep.c b/gdb/arm-none-tdep.c
> index 510ce4fa3c5..0d5eb04826e 100644
> --- a/gdb/arm-none-tdep.c
> +++ b/gdb/arm-none-tdep.c
> @@ -177,7 +177,7 @@ arm_none_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   				       void *cb_data,
>   				       const struct regcache *regcache)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     cb (".reg", ARM_NONE_SIZEOF_GREGSET, ARM_NONE_SIZEOF_GREGSET,
>         &arm_none_gregset, nullptr, cb_data);
> diff --git a/gdb/arm-obsd-tdep.c b/gdb/arm-obsd-tdep.c
> index 37cb30b9a2a..634c76b7561 100644
> --- a/gdb/arm-obsd-tdep.c
> +++ b/gdb/arm-obsd-tdep.c
> @@ -76,7 +76,7 @@ static void
>   armobsd_init_abi (struct gdbarch_info info,
>   		  struct gdbarch *gdbarch)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->fp_model == ARM_FLOAT_AUTO)
>       tdep->fp_model = ARM_FLOAT_SOFT_VFP;
> diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
> index 46027afade4..7d85759eff2 100644
> --- a/gdb/arm-tdep.c
> +++ b/gdb/arm-tdep.c
> @@ -338,7 +338,7 @@ static void
>   arm_cache_init (struct arm_prologue_cache *cache, struct frame_info *frame)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (frame);
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     arm_cache_init (cache, gdbarch);
>   
> @@ -520,7 +520,7 @@ bool arm_unwind_secure_frames = true;
>   int
>   arm_psr_thumb_bit (struct gdbarch *gdbarch)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->is_m)
>       return XPSR_T;
> @@ -632,7 +632,7 @@ arm_pc_is_thumb (struct gdbarch *gdbarch, CORE_ADDR memaddr)
>     struct bound_minimal_symbol sym;
>     char type;
>     arm_displaced_step_copy_insn_closure *dsc = nullptr;
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (gdbarch_displaced_step_copy_insn_closure_by_addr_p (gdbarch))
>       dsc = ((arm_displaced_step_copy_insn_closure * )
> @@ -736,7 +736,7 @@ arm_pc_is_thumb (struct gdbarch *gdbarch, CORE_ADDR memaddr)
>   static int
>   arm_m_addr_is_magic (struct gdbarch *gdbarch, CORE_ADDR addr)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>     if (tdep->have_sec_ext)
>       {
>         switch ((addr & 0xff000000))
> @@ -778,7 +778,7 @@ arm_m_addr_is_magic (struct gdbarch *gdbarch, CORE_ADDR addr)
>   static CORE_ADDR
>   arm_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR val)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     /* On M-profile devices, do not strip the low bit from EXC_RETURN
>        (the magic exception return address).  */
> @@ -1382,7 +1382,7 @@ thumb_analyze_prologue (struct gdbarch *gdbarch,
>   	    }
>   
>   	  arm_gdbarch_tdep *tdep
> -	    = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +	    = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>   	  /* Make sure we are dealing with a target that supports ARMv8.1-m
>   	     PACBTI.  */
> @@ -1844,7 +1844,7 @@ arm_analyze_prologue (struct gdbarch *gdbarch,
>     CORE_ADDR offset, current_pc;
>     pv_t regs[ARM_FPS_REGNUM];
>     CORE_ADDR unrecognized_pc = 0;
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     /* Search the prologue looking for instructions that set up the
>        frame pointer, adjust the stack pointer, and save registers.
> @@ -2088,7 +2088,7 @@ arm_scan_prologue (struct frame_info *this_frame,
>     CORE_ADDR prologue_start, prologue_end;
>     CORE_ADDR prev_pc = get_frame_pc (this_frame);
>     CORE_ADDR block_addr = get_frame_address_in_block (this_frame);
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     /* Assume there is no frame until proven otherwise.  */
>     cache->framereg = ARM_SP_REGNUM;
> @@ -2193,7 +2193,7 @@ arm_make_prologue_cache (struct frame_info *this_frame)
>       return cache;
>   
>     arm_gdbarch_tdep *tdep =
> -    (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
> +    gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
>   
>     prev_sp = unwound_fp + cache->framesize;
>     arm_cache_set_active_sp_value (cache, tdep, prev_sp);
> @@ -2224,7 +2224,7 @@ arm_prologue_unwind_stop_reason (struct frame_info *this_frame,
>     /* This is meant to halt the backtrace at "_start".  */
>     pc = get_frame_pc (this_frame);
>     gdbarch *arch = get_frame_arch (this_frame);
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (arch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (arch);
>     if (pc <= tdep->lowest_pc)
>       return UNWIND_OUTERMOST;
>   
> @@ -2252,7 +2252,7 @@ arm_prologue_this_id (struct frame_info *this_frame,
>     cache = (struct arm_prologue_cache *) *this_cache;
>   
>     arm_gdbarch_tdep *tdep
> -    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
> +    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
>   
>     /* Use function start address as part of the frame ID.  If we cannot
>        identify the start address (due to missing symbol information),
> @@ -2279,7 +2279,7 @@ arm_prologue_prev_register (struct frame_info *this_frame,
>       *this_cache = arm_make_prologue_cache (this_frame);
>     cache = (struct arm_prologue_cache *) *this_cache;
>   
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     /* If this frame has signed the return address, mark it as so.  */
>     if (tdep->have_pacbti && cache->ra_signed_state.has_value ()
> @@ -2952,7 +2952,7 @@ arm_exidx_fill_cache (struct frame_info *this_frame, gdb_byte *entry)
>   
>     /* We already got the previous SP.  */
>     arm_gdbarch_tdep *tdep
> -    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
> +    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
>     arm_cache_set_active_sp_value (cache, tdep, vsp);
>   
>     return cache;
> @@ -3077,7 +3077,7 @@ arm_make_epilogue_frame_cache (struct frame_info *this_frame)
>   
>     /* Since we are in epilogue, the SP has been restored.  */
>     arm_gdbarch_tdep *tdep
> -    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
> +    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
>     arm_cache_set_active_sp_value (cache, tdep,
>   				 get_frame_register_unsigned (this_frame,
>   							      ARM_SP_REGNUM));
> @@ -3116,7 +3116,7 @@ arm_epilogue_frame_this_id (struct frame_info *this_frame,
>       func = pc;
>   
>     arm_gdbarch_tdep *tdep
> -    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
> +    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
>     *this_id = frame_id_build (arm_cache_get_prev_sp_value (cache, tdep), pc);
>   }
>   
> @@ -3240,7 +3240,7 @@ arm_make_stub_cache (struct frame_info *this_frame)
>     arm_cache_init (cache, this_frame);
>   
>     arm_gdbarch_tdep *tdep
> -    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
> +    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
>     arm_cache_set_active_sp_value (cache, tdep,
>   				 get_frame_register_unsigned (this_frame,
>   							      ARM_SP_REGNUM));
> @@ -3262,7 +3262,7 @@ arm_stub_this_id (struct frame_info *this_frame,
>     cache = (struct arm_prologue_cache *) *this_cache;
>   
>     arm_gdbarch_tdep *tdep
> -    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
> +    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
>     *this_id = frame_id_build (arm_cache_get_prev_sp_value (cache, tdep),
>   			     get_frame_pc (this_frame));
>   }
> @@ -3310,7 +3310,7 @@ static struct arm_prologue_cache *
>   arm_m_exception_cache (struct frame_info *this_frame)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     struct arm_prologue_cache *cache;
>     CORE_ADDR lr;
> @@ -3597,7 +3597,7 @@ arm_m_exception_this_id (struct frame_info *this_frame,
>   
>     /* Our frame ID for a stub frame is the current SP and LR.  */
>     arm_gdbarch_tdep *tdep
> -    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
> +    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
>     *this_id = frame_id_build (arm_cache_get_prev_sp_value (cache, tdep),
>   			     get_frame_pc (this_frame));
>   }
> @@ -3619,7 +3619,7 @@ arm_m_exception_prev_register (struct frame_info *this_frame,
>   
>     /* The value was already reconstructed into PREV_SP.  */
>     arm_gdbarch_tdep *tdep
> -    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
> +    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
>     if (prev_regnum == ARM_SP_REGNUM)
>       return frame_unwind_got_constant (this_frame, prev_regnum,
>   				      arm_cache_get_prev_sp_value (cache, tdep));
> @@ -3677,7 +3677,7 @@ arm_normal_frame_base (struct frame_info *this_frame, void **this_cache)
>     cache = (struct arm_prologue_cache *) *this_cache;
>   
>     arm_gdbarch_tdep *tdep
> -    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
> +    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
>     return arm_cache_get_prev_sp_value (cache, tdep) - cache->framesize;
>   }
>   
> @@ -3693,7 +3693,7 @@ arm_dwarf2_prev_register (struct frame_info *this_frame, void **this_cache,
>   			  int regnum)
>   {
>     struct gdbarch * gdbarch = get_frame_arch (this_frame);
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>     CORE_ADDR lr, cpsr;
>     ULONGEST t_bit = arm_psr_thumb_bit (gdbarch);
>   
> @@ -4220,7 +4220,7 @@ arm_vfp_call_candidate (struct type *t, enum arm_vfp_cprc_base_type *base_type,
>   static int
>   arm_vfp_abi_for_function (struct gdbarch *gdbarch, struct type *func_type)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     /* Variadic functions always use the base ABI.  Assume that functions
>        without debug info are not variadic.  */
> @@ -4254,7 +4254,7 @@ arm_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>     int use_vfp_abi;
>     struct type *ftype;
>     unsigned vfp_regs_free = (1 << 16) - 1;
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     /* Determine the type of this function and whether the VFP ABI
>        applies.  */
> @@ -4526,7 +4526,7 @@ arm_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
>   static struct type *
>   arm_ext_type (struct gdbarch *gdbarch)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->arm_ext_type)
>       tdep->arm_ext_type
> @@ -4539,7 +4539,7 @@ arm_ext_type (struct gdbarch *gdbarch)
>   static struct type *
>   arm_neon_double_type (struct gdbarch *gdbarch)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->neon_double_type == NULL)
>       {
> @@ -4578,7 +4578,7 @@ arm_neon_double_type (struct gdbarch *gdbarch)
>   static struct type *
>   arm_neon_quad_type (struct gdbarch *gdbarch)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->neon_quad_type == NULL)
>       {
> @@ -4616,7 +4616,7 @@ arm_neon_quad_type (struct gdbarch *gdbarch)
>   static bool
>   is_q_pseudo (struct gdbarch *gdbarch, int regnum)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     /* Q pseudo registers are available for both NEON (Q0~Q15) and
>        MVE (Q0~Q7) features.  */
> @@ -4637,7 +4637,7 @@ is_q_pseudo (struct gdbarch *gdbarch, int regnum)
>   static bool
>   is_s_pseudo (struct gdbarch *gdbarch, int regnum)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->have_s_pseudos
>         && regnum >= tdep->s_pseudo_base
> @@ -4656,7 +4656,7 @@ is_s_pseudo (struct gdbarch *gdbarch, int regnum)
>   static bool
>   is_mve_pseudo (struct gdbarch *gdbarch, int regnum)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->have_mve
>         && regnum >= tdep->mve_pseudo_base
> @@ -4675,7 +4675,7 @@ is_mve_pseudo (struct gdbarch *gdbarch, int regnum)
>   static bool
>   is_pacbti_pseudo (struct gdbarch *gdbarch, int regnum)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->have_pacbti
>         && regnum >= tdep->pacbti_pseudo_base
> @@ -4691,7 +4691,7 @@ is_pacbti_pseudo (struct gdbarch *gdbarch, int regnum)
>   static struct type *
>   arm_register_type (struct gdbarch *gdbarch, int regnum)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (is_s_pseudo (gdbarch, regnum))
>       return builtin_type (gdbarch)->builtin_float;
> @@ -4770,7 +4770,7 @@ arm_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
>     /* PACBTI register containing the Pointer Authentication Code.  */
>     if (reg == ARM_DWARF_RA_AUTH_CODE)
>       {
> -      arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>         if (tdep->have_pacbti)
>   	return tdep->pacbti_pseudo_base;
> @@ -4916,7 +4916,7 @@ arm_adjust_breakpoint_address (struct gdbarch *gdbarch, CORE_ADDR bpaddr)
>     int buf_len;
>     enum bfd_endian order = gdbarch_byte_order_for_code (gdbarch);
>     int i, any, last_it, last_it_count;
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     /* If we are using BKPT breakpoints, none of this is necessary.  */
>     if (tdep->thumb2_breakpoint == NULL)
> @@ -8224,7 +8224,7 @@ arm_displaced_init_closure (struct gdbarch *gdbarch, CORE_ADDR from,
>   			    CORE_ADDR to,
>   			    arm_displaced_step_copy_insn_closure *dsc)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>     unsigned int i, len, offset;
>     enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
>     int size = dsc->is_thumb? 2 : 4;
> @@ -8387,7 +8387,7 @@ static const gdb_byte arm_default_thumb_be_breakpoint[] = THUMB_BE_BREAKPOINT;
>   static int
>   arm_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
>   
>     if (arm_pc_is_thumb (gdbarch, *pcptr))
> @@ -8422,7 +8422,7 @@ arm_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
>   static const gdb_byte *
>   arm_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     switch (kind)
>       {
> @@ -8494,7 +8494,7 @@ arm_extract_return_value (struct type *type, struct regcache *regs,
>   {
>     struct gdbarch *gdbarch = regs->arch ();
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (TYPE_CODE_FLT == type->code ())
>       {
> @@ -8605,7 +8605,7 @@ arm_return_in_memory (struct gdbarch *gdbarch, struct type *type)
>         return (TYPE_LENGTH (type) > 16);
>       }
>   
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>     if (tdep->arm_abi != ARM_ABI_APCS)
>       {
>         /* The AAPCS says all aggregates not larger than a word are returned
> @@ -8711,7 +8711,7 @@ arm_store_return_value (struct type *type, struct regcache *regs,
>     if (type->code () == TYPE_CODE_FLT)
>       {
>         gdb_byte buf[ARM_FP_REGISTER_SIZE];
> -      arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>         switch (tdep->fp_model)
>   	{
> @@ -8800,7 +8800,7 @@ arm_return_value (struct gdbarch *gdbarch, struct value *function,
>   		  struct type *valtype, struct regcache *regcache,
>   		  gdb_byte *readbuf, const gdb_byte *writebuf)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>     struct type *func_type = function ? value_type (function) : NULL;
>     enum arm_vfp_cprc_base_type vfp_base_type;
>     int vfp_base_count;
> @@ -8892,7 +8892,7 @@ static int
>   arm_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (frame);
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     CORE_ADDR jb_addr;
>     gdb_byte buf[ARM_INT_REGISTER_SIZE];
> @@ -9085,7 +9085,7 @@ show_fp_model (struct ui_file *file, int from_tty,
>         && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm)
>       {
>         arm_gdbarch_tdep *tdep
> -	= (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
> +	= gdbarch_tdep<arm_gdbarch_tdep> (target_gdbarch ());
>   
>         gdb_printf (file, _("\
>   The current ARM floating point model is \"auto\" (currently \"%s\").\n"),
> @@ -9125,7 +9125,7 @@ arm_show_abi (struct ui_file *file, int from_tty,
>         && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm)
>       {
>         arm_gdbarch_tdep *tdep
> -	= (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
> +	= gdbarch_tdep<arm_gdbarch_tdep> (target_gdbarch ());
>   
>         gdb_printf (file, _("\
>   The current ARM ABI is \"auto\" (currently \"%s\").\n"),
> @@ -9204,7 +9204,7 @@ show_disassembly_style_sfunc (struct ui_file *file, int from_tty,
>   static const char *
>   arm_register_name (struct gdbarch *gdbarch, int i)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (is_s_pseudo (gdbarch, i))
>       {
> @@ -9375,7 +9375,7 @@ static enum register_status
>   arm_mve_pseudo_read (struct gdbarch *gdbarch, readable_regcache *regcache,
>   		     int regnum, gdb_byte *buf)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     /* P0 is the first 16 bits of VPR.  */
>     return regcache->raw_read_part (tdep->mve_vpr_regnum, 0, 2, buf);
> @@ -9389,7 +9389,7 @@ arm_pseudo_read (struct gdbarch *gdbarch, readable_regcache *regcache,
>     char name_buf[4];
>     gdb_byte reg_buf[8];
>     int offset, double_regnum;
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     gdb_assert (regnum >= num_regs);
>   
> @@ -9461,7 +9461,7 @@ static void
>   arm_mve_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache,
>   		      int regnum, const gdb_byte *buf)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     /* P0 is the first 16 bits of VPR.  */
>     regcache->raw_write_part (tdep->mve_vpr_regnum, 0, 2, buf);
> @@ -9475,7 +9475,7 @@ arm_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache,
>     char name_buf[4];
>     gdb_byte reg_buf[8];
>     int offset, double_regnum;
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     gdb_assert (regnum >= num_regs);
>   
> @@ -9563,7 +9563,7 @@ arm_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
>   static void
>   arm_register_g_packet_guesses (struct gdbarch *gdbarch)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->is_m)
>       {
> @@ -9606,7 +9606,7 @@ arm_register_g_packet_guesses (struct gdbarch *gdbarch)
>   static int
>   arm_code_of_frame_writable (struct gdbarch *gdbarch, struct frame_info *frame)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->is_m && get_frame_type (frame) == SIGTRAMP_FRAME)
>       {
> @@ -10165,7 +10165,7 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
>       {
>         arm_gdbarch_tdep *tdep
> -	= (arm_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
> +	= gdbarch_tdep<arm_gdbarch_tdep> (best_arch->gdbarch);
>   
>         if (arm_abi != ARM_ABI_AUTO && arm_abi != tdep->arm_abi)
>   	continue;
> @@ -10485,7 +10485,7 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>   static void
>   arm_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     if (tdep == NULL)
>       return;
> @@ -12694,7 +12694,7 @@ arm_record_coproc_data_proc (arm_insn_decode_record *arm_insn_r)
>   {
>     uint32_t op, op1_ebit, coproc, bits_24_25;
>     arm_gdbarch_tdep *tdep
> -    = (arm_gdbarch_tdep *) gdbarch_tdep (arm_insn_r->gdbarch);
> +    = gdbarch_tdep<arm_gdbarch_tdep> (arm_insn_r->gdbarch);
>     struct regcache *reg_cache = arm_insn_r->regcache;
>   
>     arm_insn_r->opcode = bits (arm_insn_r->arm_insn, 24, 27);
> @@ -13182,7 +13182,7 @@ static int
>   thumb_record_ldm_stm_swi (arm_insn_decode_record *thumb_insn_r)
>   {
>     arm_gdbarch_tdep *tdep
> -    = (arm_gdbarch_tdep *) gdbarch_tdep  (thumb_insn_r->gdbarch);
> +    = gdbarch_tdep<arm_gdbarch_tdep>  (thumb_insn_r->gdbarch);
>     struct regcache *reg_cache = thumb_insn_r->regcache;
>   
>     uint32_t ret = 0; /* function return value: -1:record failure ;  0:success  */
> diff --git a/gdb/arm-wince-tdep.c b/gdb/arm-wince-tdep.c
> index 354c6fbca7f..5063b308809 100644
> --- a/gdb/arm-wince-tdep.c
> +++ b/gdb/arm-wince-tdep.c
> @@ -115,7 +115,7 @@ arm_wince_skip_main_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
>   static void
>   arm_wince_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
>   
>     windows_init_abi (info, gdbarch);
>   
> diff --git a/gdb/avr-tdep.c b/gdb/avr-tdep.c
> index e103045cb23..4722f7ee748 100644
> --- a/gdb/avr-tdep.c
> +++ b/gdb/avr-tdep.c
> @@ -232,7 +232,7 @@ avr_register_type (struct gdbarch *gdbarch, int reg_nr)
>     if (reg_nr == AVR_PC_REGNUM)
>       return builtin_type (gdbarch)->builtin_uint32;
>   
> -  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
>     if (reg_nr == AVR_PSEUDO_PC_REGNUM)
>       return tdep->pc_type;
>   
> @@ -750,7 +750,7 @@ avr_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR pc_beg, CORE_ADDR pc_end,
>     gdb_assert (vpc < AVR_MAX_PROLOGUE_SIZE);
>   
>     /* Handle static small stack allocation using rcall or push.  */
> -  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
>     while (scan_stage == 1 && vpc < len)
>       {
>         insn = extract_unsigned_integer (&prologue[vpc], 2, byte_order);
> @@ -1053,7 +1053,7 @@ avr_frame_unwind_cache (struct frame_info *this_frame,
>   
>     /* The previous frame's SP needed to be computed.  Save the computed
>        value.  */
> -  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
>     info->saved_regs[AVR_SP_REGNUM].set_value (info->prev_sp
>   					     - 1 + tdep->call_length);
>   
> @@ -1135,7 +1135,7 @@ avr_frame_prev_register (struct frame_info *this_frame,
>   	  int i;
>   	  gdb_byte buf[3];
>   	  struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -	  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +	  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
>   
>   	  read_memory (info->saved_regs[AVR_PC_REGNUM].addr (),
>   		       buf, tdep->call_length);
> @@ -1277,7 +1277,7 @@ avr_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>   {
>     int i;
>     gdb_byte buf[3];
> -  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
>     int call_length = tdep->call_length;
>     CORE_ADDR return_pc = avr_convert_iaddr_to_raw (bp_addr);
>     int regnum = AVR_ARGN_REGNUM;
> @@ -1461,7 +1461,7 @@ avr_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
>       {
>         avr_gdbarch_tdep *tdep
> -	= (avr_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
> +	= gdbarch_tdep<avr_gdbarch_tdep> (best_arch->gdbarch);
>   
>         if (tdep->call_length == call_length)
>   	return best_arch->gdbarch;
> diff --git a/gdb/bfin-tdep.c b/gdb/bfin-tdep.c
> index 573eed94793..f232e22c37c 100644
> --- a/gdb/bfin-tdep.c
> +++ b/gdb/bfin-tdep.c
> @@ -766,7 +766,7 @@ bfin_frame_align (struct gdbarch *gdbarch, CORE_ADDR address)
>   enum bfin_abi
>   bfin_abi (struct gdbarch *gdbarch)
>   {
> -  bfin_gdbarch_tdep *tdep = (bfin_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  bfin_gdbarch_tdep *tdep = gdbarch_tdep<bfin_gdbarch_tdep> (gdbarch);
>     return tdep->bfin_abi;
>   }
>   
> @@ -792,7 +792,7 @@ bfin_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          arches = gdbarch_list_lookup_by_info (arches->next, &info))
>       {
>         bfin_gdbarch_tdep *tdep
> -	= (bfin_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<bfin_gdbarch_tdep> (arches->gdbarch);
>   
>         if (tdep->bfin_abi != abi)
>   	continue;
> diff --git a/gdb/cris-linux-tdep.c b/gdb/cris-linux-tdep.c
> index f55f9b9083c..b3ed7450e99 100644
> --- a/gdb/cris-linux-tdep.c
> +++ b/gdb/cris-linux-tdep.c
> @@ -33,7 +33,7 @@
>   static void
>   cris_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
>   
>     linux_init_abi (info, gdbarch, 0);
>   
> diff --git a/gdb/cris-tdep.c b/gdb/cris-tdep.c
> index efd728a5229..73110d97f2f 100644
> --- a/gdb/cris-tdep.c
> +++ b/gdb/cris-tdep.c
> @@ -313,7 +313,7 @@ cris_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
>   				  void **this_cache)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     struct cris_unwind_cache *info;
>     CORE_ADDR addr;
> @@ -450,7 +450,7 @@ static int
>   crisv32_single_step_through_delay (struct gdbarch *gdbarch,
>   				   struct frame_info *this_frame)
>   {
> -  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
>     ULONGEST erp;
>     int ret = 0;
>   
> @@ -696,7 +696,7 @@ cris_frame_unwind_cache (struct frame_info *this_frame,
>   			 void **this_prologue_cache)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
>     struct cris_unwind_cache *info;
>   
>     if ((*this_prologue_cache))
> @@ -1334,7 +1334,7 @@ crisv32_scan_prologue (CORE_ADDR pc, struct frame_info *this_frame,
>   static CORE_ADDR
>   cris_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
>   {
> -  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
>     CORE_ADDR func_addr, func_end;
>     struct symtab_and_line sal;
>     CORE_ADDR pc_after_prologue;
> @@ -1369,7 +1369,7 @@ cris_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
>   static const gdb_byte *
>   cris_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
>   {
> -  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
>     static unsigned char break8_insn[] = {0x38, 0xe9};
>     static unsigned char break15_insn[] = {0x3f, 0xe9};
>   
> @@ -1388,7 +1388,7 @@ static int
>   cris_spec_reg_applicable (struct gdbarch *gdbarch,
>   			  struct cris_spec_reg spec_reg)
>   {
> -  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
>     unsigned int version = tdep->cris_version;
>     
>     switch (spec_reg.applicable_version)
> @@ -3767,7 +3767,7 @@ cris_supply_gregset (const struct regset *regset, struct regcache *regcache,
>   		     int regnum, const void *gregs, size_t len)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
>     int i;
>     const cris_elf_greg_t *regp = static_cast<const cris_elf_greg_t *>(gregs);
>   
> @@ -3861,7 +3861,7 @@ Makes GDB use the NRP register instead of the ERP register in certain cases."),
>   static void
>   cris_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
>   {
> -  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
>     if (tdep != NULL)
>       {
>         gdb_printf (file, "cris_dump_tdep: tdep->cris_version = %i\n",
> @@ -3941,7 +3941,7 @@ cris_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          arches = gdbarch_list_lookup_by_info (arches->next, &info))
>       {
>         cris_gdbarch_tdep *tdep
> -	= (cris_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<cris_gdbarch_tdep> (arches->gdbarch);
>   
>         if (tdep->cris_version == usr_cmd_cris_version
>   	  && tdep->cris_mode == usr_cmd_cris_mode
> diff --git a/gdb/csky-tdep.c b/gdb/csky-tdep.c
> index 3b4db049d96..c9450802b32 100644
> --- a/gdb/csky-tdep.c
> +++ b/gdb/csky-tdep.c
> @@ -2181,7 +2181,7 @@ csky_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          arches = gdbarch_list_lookup_by_info (arches->next, &info))
>       {
>         csky_gdbarch_tdep *tdep
> -        = (csky_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<csky_gdbarch_tdep> (arches->gdbarch);
>         if (fpu_abi != tdep->fpu_abi)
>           continue;
>         if (vdsp_version != tdep->vdsp_version)
> diff --git a/gdb/frv-tdep.c b/gdb/frv-tdep.c
> index 2328791a540..34f437764a9 100644
> --- a/gdb/frv-tdep.c
> +++ b/gdb/frv-tdep.c
> @@ -93,7 +93,7 @@ struct frv_gdbarch_tdep : gdbarch_tdep
>   enum frv_abi
>   frv_abi (struct gdbarch *gdbarch)
>   {
> -  frv_gdbarch_tdep *tdep = (frv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  frv_gdbarch_tdep *tdep = gdbarch_tdep<frv_gdbarch_tdep> (gdbarch);
>     return tdep->frv_abi;
>   }
>   
> @@ -275,7 +275,7 @@ frv_register_name (struct gdbarch *gdbarch, int reg)
>     if (reg >= frv_num_regs + frv_num_pseudo_regs)
>       return "?toolarge?";
>   
> -  frv_gdbarch_tdep *tdep = (frv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  frv_gdbarch_tdep *tdep = gdbarch_tdep<frv_gdbarch_tdep> (gdbarch);
>     return tdep->register_names[reg];
>   }
>   
> diff --git a/gdb/ft32-tdep.c b/gdb/ft32-tdep.c
> index f77e313e0dd..024ca47ce4d 100644
> --- a/gdb/ft32-tdep.c
> +++ b/gdb/ft32-tdep.c
> @@ -110,7 +110,7 @@ ft32_register_type (struct gdbarch *gdbarch, int reg_nr)
>   {
>     if (reg_nr == FT32_PC_REGNUM)
>       {
> -      ft32_gdbarch_tdep *tdep = (ft32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      ft32_gdbarch_tdep *tdep = gdbarch_tdep<ft32_gdbarch_tdep> (gdbarch);
>         return tdep->pc_type;
>       }
>     else if (reg_nr == FT32_SP_REGNUM || reg_nr == FT32_FP_REGNUM)
> diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
> index 3a7b7f92ef7..b2c91db0c4f 100644
> --- a/gdb/gdbarch.h
> +++ b/gdb/gdbarch.h
> @@ -142,8 +142,23 @@ using read_core_file_mappings_loop_ftype =
>   
>   #include "gdbarch-gen.h"
>   
> -extern struct gdbarch_tdep *gdbarch_tdep (struct gdbarch *gdbarch);
> +/* An internal function that should _only_ be called from gdbarch_tdep.
> +   Returns the gdbarch_tdep field held within GDBARCH.  */
>   
> +extern struct gdbarch_tdep *gdbarch_tdep_1 (struct gdbarch *gdbarch);
> +
> +/* Return the gdbarch_tdep object held within GDBARCH cast to the type
> +   TDepType, which should be a sub-class of gdbarch_tdep.  There is no
> +   checking done that the gdbarch_tdep within GDBARCH actually is of the
> +   type TDepType, we just assume the caller knows what they are doing.  */
> +
> +template<typename TDepType>
> +static inline TDepType *
> +gdbarch_tdep (struct gdbarch *gdbarch)
> +{
> +  struct gdbarch_tdep *tdep = gdbarch_tdep_1 (gdbarch);
> +  return static_cast<TDepType *> (tdep);
> +}
>   
>   /* Mechanism for co-ordinating the selection of a specific
>      architecture.
> diff --git a/gdb/hppa-bsd-tdep.c b/gdb/hppa-bsd-tdep.c
> index 34f57d2512a..c405511529d 100644
> --- a/gdb/hppa-bsd-tdep.c
> +++ b/gdb/hppa-bsd-tdep.c
> @@ -118,7 +118,7 @@ hppabsd_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
>   void
>   hppabsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
>   
>     /* OpenBSD and NetBSD have a 64-bit 'long double'.  */
>     set_gdbarch_long_double_bit (gdbarch, 64);
> diff --git a/gdb/hppa-linux-tdep.c b/gdb/hppa-linux-tdep.c
> index 40e32c115d2..f17d2ae6b02 100644
> --- a/gdb/hppa-linux-tdep.c
> +++ b/gdb/hppa-linux-tdep.c
> @@ -476,7 +476,7 @@ hppa_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   					 void *cb_data,
>   					 const struct regcache *regcache)
>   {
> -  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
>   
>     cb (".reg", 80 * tdep->bytes_per_address, 80 * tdep->bytes_per_address,
>         &hppa_linux_regset, NULL, cb_data);
> @@ -486,7 +486,7 @@ hppa_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   static void
>   hppa_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
>   
>     linux_init_abi (info, gdbarch, 0);
>   
> diff --git a/gdb/hppa-tdep.c b/gdb/hppa-tdep.c
> index f9ececbb04f..9f93a945a6a 100644
> --- a/gdb/hppa-tdep.c
> +++ b/gdb/hppa-tdep.c
> @@ -247,7 +247,7 @@ internalize_unwinds (struct objfile *objfile, struct unwind_table_entry *table,
>     if (size > 0)
>       {
>         struct gdbarch *gdbarch = objfile->arch ();
> -      hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
>         unsigned long tmp;
>         unsigned i;
>         char *buf = (char *) alloca (size);
> @@ -718,7 +718,7 @@ hppa32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>     /* Global pointer (r19) of the function we are trying to call.  */
>     CORE_ADDR gp;
>   
> -  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
>   
>     for (write_pass = 0; write_pass < 2; write_pass++)
>       {
> @@ -955,7 +955,7 @@ hppa64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>   			function_call_return_method return_method,
>   			CORE_ADDR struct_addr)
>   {
> -  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     int i, offset = 0;
>     CORE_ADDR gp;
> @@ -2241,7 +2241,7 @@ hppa_frame_cache (struct frame_info *this_frame, void **this_cache)
>     }
>   
>     {
> -    hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +    hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
>   
>       if (tdep->unwind_adjust_stub)
>         tdep->unwind_adjust_stub (this_frame, cache->base, cache->saved_regs);
> @@ -2471,7 +2471,7 @@ hppa_stub_unwind_sniffer (const struct frame_unwind *self,
>   {
>     CORE_ADDR pc = get_frame_address_in_block (this_frame);
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
>   
>     if (pc == 0
>         || (tdep->in_solib_call_trampoline != NULL
> @@ -3147,7 +3147,7 @@ hppa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>   static void
>   hppa_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
>   {
> -  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
>   
>     gdb_printf (file, "bytes_per_address = %d\n",
>   	      tdep->bytes_per_address);
> diff --git a/gdb/i386-bsd-tdep.c b/gdb/i386-bsd-tdep.c
> index b38f8d05887..dbbd3c786c3 100644
> --- a/gdb/i386-bsd-tdep.c
> +++ b/gdb/i386-bsd-tdep.c
> @@ -74,7 +74,7 @@ int i386bsd_sc_reg_offset[] =
>   void
>   i386bsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     tdep->jb_pc_offset = 0;
>   
> diff --git a/gdb/i386-darwin-tdep.c b/gdb/i386-darwin-tdep.c
> index dc780583766..2a9198aceb3 100644
> --- a/gdb/i386-darwin-tdep.c
> +++ b/gdb/i386-darwin-tdep.c
> @@ -156,7 +156,7 @@ i386_darwin_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>   			     function_call_return_method return_method,
>   			     CORE_ADDR struct_addr)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     gdb_byte buf[4];
>     int i;
> @@ -248,7 +248,7 @@ i386_darwin_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>   static void
>   i386_darwin_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* We support the SSE registers.  */
>     tdep->num_xmm_regs = I386_NUM_XREGS - 1;
> diff --git a/gdb/i386-fbsd-tdep.c b/gdb/i386-fbsd-tdep.c
> index d68498cd5e9..b7a524db68c 100644
> --- a/gdb/i386-fbsd-tdep.c
> +++ b/gdb/i386-fbsd-tdep.c
> @@ -325,7 +325,7 @@ i386fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   				       void *cb_data,
>   				       const struct regcache *regcache)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     cb (".reg", I386_FBSD_SIZEOF_GREGSET, I386_FBSD_SIZEOF_GREGSET,
>         &i386_fbsd_gregset, NULL, cb_data);
> @@ -365,7 +365,7 @@ i386fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
>   static void
>   i386fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* Generic FreeBSD support. */
>     fbsd_init_abi (info, gdbarch);
> diff --git a/gdb/i386-gnu-tdep.c b/gdb/i386-gnu-tdep.c
> index 51c253d2dfe..3d97fe36a85 100644
> --- a/gdb/i386-gnu-tdep.c
> +++ b/gdb/i386-gnu-tdep.c
> @@ -173,7 +173,7 @@ static int i386gnu_gregset_reg_offset[] =
>   static void
>   i386gnu_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* GNU uses ELF.  */
>     i386_elf_init_abi (info, gdbarch);
> diff --git a/gdb/i386-go32-tdep.c b/gdb/i386-go32-tdep.c
> index 15ac38dc12f..0c0c08e3579 100644
> --- a/gdb/i386-go32-tdep.c
> +++ b/gdb/i386-go32-tdep.c
> @@ -26,7 +26,7 @@
>   static void
>   i386_go32_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* DJGPP doesn't have any special frames for signal handlers.  */
>     tdep->sigtramp_p = NULL;
> diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c
> index 5d7f54194af..6033104230f 100644
> --- a/gdb/i386-linux-tdep.c
> +++ b/gdb/i386-linux-tdep.c
> @@ -763,7 +763,7 @@ i386_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   					 void *cb_data,
>   					 const struct regcache *regcache)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     cb (".reg", 68, 68, &i386_gregset, NULL, cb_data);
>   
> @@ -825,7 +825,7 @@ i386_linux_displaced_step_copy_insn (struct gdbarch *gdbarch,
>   static void
>   i386_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     const struct target_desc *tdesc = info.target_desc;
>     struct tdesc_arch_data *tdesc_data = info.tdesc_data;
>     const struct tdesc_feature *feature;
> diff --git a/gdb/i386-netbsd-tdep.c b/gdb/i386-netbsd-tdep.c
> index 2cee1b94760..a9ebc3dd827 100644
> --- a/gdb/i386-netbsd-tdep.c
> +++ b/gdb/i386-netbsd-tdep.c
> @@ -372,7 +372,7 @@ i386nbsd_sigtramp_cache_init (const struct tramp_frame *self,
>   static void
>   i386nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* Obviously NetBSD is BSD-based.  */
>     i386bsd_init_abi (info, gdbarch);
> @@ -407,7 +407,7 @@ i386nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   static void
>   i386nbsdelf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* It's still NetBSD.  */
>     i386nbsd_init_abi (info, gdbarch);
> diff --git a/gdb/i386-nto-tdep.c b/gdb/i386-nto-tdep.c
> index 6716329149b..259867f262b 100644
> --- a/gdb/i386-nto-tdep.c
> +++ b/gdb/i386-nto-tdep.c
> @@ -77,7 +77,7 @@ static void
>   i386nto_supply_gregset (struct regcache *regcache, char *gpregs)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     gdb_assert (tdep->gregset_reg_offset == i386nto_gregset_reg_offset);
>     i386_gregset.supply_regset (&i386_gregset, regcache, -1,
> @@ -126,7 +126,7 @@ static int
>   i386nto_register_area (struct gdbarch *gdbarch,
>   		       int regno, int regset, unsigned *off)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     *off = 0;
>     if (regset == NTO_REG_GENERAL)
> @@ -315,7 +315,7 @@ init_i386nto_ops (void)
>   static void
>   i386nto_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     static struct target_so_ops nto_svr4_so_ops;
>   
>     /* Deal with our strange signals.  */
> diff --git a/gdb/i386-obsd-tdep.c b/gdb/i386-obsd-tdep.c
> index b1f4d6c5e8d..798094509c6 100644
> --- a/gdb/i386-obsd-tdep.c
> +++ b/gdb/i386-obsd-tdep.c
> @@ -407,7 +407,7 @@ static const struct frame_unwind i386obsd_trapframe_unwind = {
>   static void
>   i386obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* Obviously OpenBSD is BSD-based.  */
>     i386bsd_init_abi (info, gdbarch);
> diff --git a/gdb/i386-sol2-tdep.c b/gdb/i386-sol2-tdep.c
> index e8a3ba20045..5ee108d3578 100644
> --- a/gdb/i386-sol2-tdep.c
> +++ b/gdb/i386-sol2-tdep.c
> @@ -65,7 +65,7 @@ i386_sol2_mcontext_addr (struct frame_info *this_frame)
>   static void
>   i386_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* Solaris is SVR4-based.  */
>     i386_svr4_init_abi (info, gdbarch);
> diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
> index 8501e12e241..d500f6998c5 100644
> --- a/gdb/i386-tdep.c
> +++ b/gdb/i386-tdep.c
> @@ -169,7 +169,7 @@ const int num_lower_zmm_regs = 16;
>   static int
>   i386_mmx_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int mm0_regnum = tdep->mm0_regnum;
>   
>     if (mm0_regnum < 0)
> @@ -184,7 +184,7 @@ i386_mmx_regnum_p (struct gdbarch *gdbarch, int regnum)
>   int
>   i386_byte_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     regnum -= tdep->al_regnum;
>     return regnum >= 0 && regnum < tdep->num_byte_regs;
> @@ -195,7 +195,7 @@ i386_byte_regnum_p (struct gdbarch *gdbarch, int regnum)
>   int
>   i386_word_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     regnum -= tdep->ax_regnum;
>     return regnum >= 0 && regnum < tdep->num_word_regs;
> @@ -206,7 +206,7 @@ i386_word_regnum_p (struct gdbarch *gdbarch, int regnum)
>   int
>   i386_dword_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int eax_regnum = tdep->eax_regnum;
>   
>     if (eax_regnum < 0)
> @@ -221,7 +221,7 @@ i386_dword_regnum_p (struct gdbarch *gdbarch, int regnum)
>   int
>   i386_zmmh_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int zmm0h_regnum = tdep->zmm0h_regnum;
>   
>     if (zmm0h_regnum < 0)
> @@ -234,7 +234,7 @@ i386_zmmh_regnum_p (struct gdbarch *gdbarch, int regnum)
>   int
>   i386_zmm_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int zmm0_regnum = tdep->zmm0_regnum;
>   
>     if (zmm0_regnum < 0)
> @@ -247,7 +247,7 @@ i386_zmm_regnum_p (struct gdbarch *gdbarch, int regnum)
>   int
>   i386_k_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int k0_regnum = tdep->k0_regnum;
>   
>     if (k0_regnum < 0)
> @@ -260,7 +260,7 @@ i386_k_regnum_p (struct gdbarch *gdbarch, int regnum)
>   static int
>   i386_ymmh_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int ymm0h_regnum = tdep->ymm0h_regnum;
>   
>     if (ymm0h_regnum < 0)
> @@ -275,7 +275,7 @@ i386_ymmh_regnum_p (struct gdbarch *gdbarch, int regnum)
>   int
>   i386_ymm_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int ymm0_regnum = tdep->ymm0_regnum;
>   
>     if (ymm0_regnum < 0)
> @@ -288,7 +288,7 @@ i386_ymm_regnum_p (struct gdbarch *gdbarch, int regnum)
>   static int
>   i386_ymmh_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int ymm16h_regnum = tdep->ymm16h_regnum;
>   
>     if (ymm16h_regnum < 0)
> @@ -301,7 +301,7 @@ i386_ymmh_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
>   int
>   i386_ymm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int ymm16_regnum = tdep->ymm16_regnum;
>   
>     if (ymm16_regnum < 0)
> @@ -316,7 +316,7 @@ i386_ymm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
>   int
>   i386_bnd_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int bnd0_regnum = tdep->bnd0_regnum;
>   
>     if (bnd0_regnum < 0)
> @@ -331,7 +331,7 @@ i386_bnd_regnum_p (struct gdbarch *gdbarch, int regnum)
>   int
>   i386_xmm_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int num_xmm_regs = I387_NUM_XMM_REGS (tdep);
>   
>     if (num_xmm_regs == 0)
> @@ -346,7 +346,7 @@ i386_xmm_regnum_p (struct gdbarch *gdbarch, int regnum)
>   int
>   i386_xmm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int num_xmm_avx512_regs = I387_NUM_XMM_AVX512_REGS (tdep);
>   
>     if (num_xmm_avx512_regs == 0)
> @@ -359,7 +359,7 @@ i386_xmm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
>   static int
>   i386_mxcsr_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     if (I387_NUM_XMM_REGS (tdep) == 0)
>       return 0;
> @@ -372,7 +372,7 @@ i386_mxcsr_regnum_p (struct gdbarch *gdbarch, int regnum)
>   int
>   i386_fp_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     if (I387_ST0_REGNUM (tdep) < 0)
>       return 0;
> @@ -384,7 +384,7 @@ i386_fp_regnum_p (struct gdbarch *gdbarch, int regnum)
>   int
>   i386_fpc_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     if (I387_ST0_REGNUM (tdep) < 0)
>       return 0;
> @@ -398,7 +398,7 @@ i386_fpc_regnum_p (struct gdbarch *gdbarch, int regnum)
>   static int
>   i386_bndr_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>      if (I387_BND0R_REGNUM (tdep) < 0)
>        return 0;
> @@ -412,7 +412,7 @@ i386_bndr_regnum_p (struct gdbarch *gdbarch, int regnum)
>   static int
>   i386_mpx_ctrl_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>      if (I387_BNDCFGU_REGNUM (tdep) < 0)
>        return 0;
> @@ -426,7 +426,7 @@ i386_mpx_ctrl_regnum_p (struct gdbarch *gdbarch, int regnum)
>   bool
>   i386_pkru_regnum_p (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int pkru_regnum = tdep->pkru_regnum;
>   
>     if (pkru_regnum < 0)
> @@ -462,7 +462,7 @@ i386_register_name (struct gdbarch *gdbarch, int regnum)
>   const char *
>   i386_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     if (i386_bnd_regnum_p (gdbarch, regnum))
>       return i386_bnd_names[regnum - tdep->bnd0_regnum];
>     if (i386_mmx_regnum_p (gdbarch, regnum))
> @@ -485,7 +485,7 @@ i386_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
>   static int
>   i386_dbx_reg_to_regnum (struct gdbarch *gdbarch, int reg)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* This implements what GCC calls the "default" register map
>        (dbx_register_map[]).  */
> @@ -532,7 +532,7 @@ i386_dbx_reg_to_regnum (struct gdbarch *gdbarch, int reg)
>   static int
>   i386_svr4_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* This implements the GCC register map that tries to be compatible
>        with the SVR4 C compiler for DWARF (svr4_dbx_register_map[]).  */
> @@ -2434,7 +2434,7 @@ static struct i386_frame_cache *
>   i386_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     struct i386_frame_cache *cache;
>     CORE_ADDR addr;
> @@ -2524,7 +2524,7 @@ i386_sigtramp_frame_sniffer (const struct frame_unwind *self,
>   			     void **this_prologue_cache)
>   {
>     gdbarch *arch = get_frame_arch (this_frame);
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
>   
>     /* We shouldn't even bother if we don't have a sigcontext_addr
>        handler.  */
> @@ -2611,7 +2611,7 @@ i386_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
>     CORE_ADDR sp, jb_addr;
>     struct gdbarch *gdbarch = get_frame_arch (frame);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int jb_pc_offset = tdep->jb_pc_offset;
>   
>     /* If JB_PC_OFFSET is -1, we have no way to find out where the
> @@ -2860,7 +2860,7 @@ static void
>   i386_extract_return_value (struct gdbarch *gdbarch, struct type *type,
>   			   struct regcache *regcache, gdb_byte *valbuf)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int len = TYPE_LENGTH (type);
>     gdb_byte buf[I386_MAX_REGISTER_SIZE];
>   
> @@ -2918,7 +2918,7 @@ static void
>   i386_store_return_value (struct gdbarch *gdbarch, struct type *type,
>   			 struct regcache *regcache, const gdb_byte *valbuf)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int len = TYPE_LENGTH (type);
>   
>     if (type->code () == TYPE_CODE_FLT)
> @@ -2997,7 +2997,7 @@ static const char *struct_convention = default_struct_convention;
>   static int
>   i386_reg_struct_return_p (struct gdbarch *gdbarch, struct type *type)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     enum type_code code = type->code ();
>     int len = TYPE_LENGTH (type);
>   
> @@ -3099,7 +3099,7 @@ i386_return_value (struct gdbarch *gdbarch, struct value *function,
>   struct type *
>   i387_ext_type (struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->i387_ext_type)
>       {
> @@ -3117,7 +3117,7 @@ i387_ext_type (struct gdbarch *gdbarch)
>   static struct type *
>   i386_bnd_type (struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>   
>     if (!tdep->i386_bnd_type)
> @@ -3153,7 +3153,7 @@ i386_bnd_type (struct gdbarch *gdbarch)
>   static struct type *
>   i386_zmm_type (struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->i386_zmm_type)
>       {
> @@ -3212,7 +3212,7 @@ i386_zmm_type (struct gdbarch *gdbarch)
>   static struct type *
>   i386_ymm_type (struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->i386_ymm_type)
>       {
> @@ -3269,7 +3269,7 @@ i386_ymm_type (struct gdbarch *gdbarch)
>   static struct type *
>   i386_mmx_type (struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->i386_mmx_type)
>       {
> @@ -3346,7 +3346,7 @@ static int
>   i386_mmx_regnum_to_fp_regnum (readable_regcache *regcache, int regnum)
>   {
>     gdbarch *arch = regcache->arch ();
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
>     int mmxreg, fpreg;
>     ULONGEST fstat;
>     int tos;
> @@ -3387,7 +3387,7 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
>       }
>     else
>       {
> -      i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>         if (i386_bnd_regnum_p (gdbarch, regnum))
>   	{
>   	  regnum -= tdep->bnd0_regnum;
> @@ -3577,7 +3577,7 @@ i386_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
>       }
>     else
>       {
> -      i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>         if (i386_bnd_regnum_p (gdbarch, regnum))
>   	{
> @@ -3685,7 +3685,7 @@ int
>   i386_ax_pseudo_register_collect (struct gdbarch *gdbarch,
>   				 struct agent_expr *ax, int regnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     if (i386_mmx_regnum_p (gdbarch, regnum))
>       {
> @@ -3902,7 +3902,7 @@ i386_supply_gregset (const struct regset *regset, struct regcache *regcache,
>   		     int regnum, const void *gregs, size_t len)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     const gdb_byte *regs = (const gdb_byte *) gregs;
>     int i;
>   
> @@ -3927,7 +3927,7 @@ i386_collect_gregset (const struct regset *regset,
>   		      int regnum, void *gregs, size_t len)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     gdb_byte *regs = (gdb_byte *) gregs;
>     int i;
>   
> @@ -3950,7 +3950,7 @@ i386_supply_fpregset (const struct regset *regset, struct regcache *regcache,
>   		      int regnum, const void *fpregs, size_t len)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     if (len == I387_SIZEOF_FXSAVE)
>       {
> @@ -3973,7 +3973,7 @@ i386_collect_fpregset (const struct regset *regset,
>   		       int regnum, void *fpregs, size_t len)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     if (len == I387_SIZEOF_FXSAVE)
>       {
> @@ -4005,7 +4005,7 @@ i386_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   				   void *cb_data,
>   				   const struct regcache *regcache)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     cb (".reg", tdep->sizeof_gregset, tdep->sizeof_gregset, &i386_gregset, NULL,
>         cb_data);
> @@ -4510,7 +4510,7 @@ i386_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   void
>   i386_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* System V Release 4 uses ELF.  */
>     i386_elf_init_abi (info, gdbarch);
> @@ -4552,7 +4552,7 @@ int
>   i386_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
>   			  const struct reggroup *group)
>   {
> -  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int fp_regnum_p, mmx_regnum_p, xmm_regnum_p, mxcsr_regnum_p,
>         ymm_regnum_p, ymmh_regnum_p, ymm_avx512_regnum_p, ymmh_avx512_regnum_p,
>         bndr_regnum_p, bnd_regnum_p, zmm_regnum_p, zmmh_regnum_p,
> @@ -4997,7 +4997,7 @@ static int i386_record_floats (struct gdbarch *gdbarch,
>   			       struct i386_record_s *ir,
>   			       uint32_t iregnum)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     int i;
>   
>     /* Oza: Because of floating point insn push/pop of fpu stack is going to
> @@ -5068,7 +5068,7 @@ i386_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
>     ULONGEST addr;
>     gdb_byte buf[I386_MAX_REGISTER_SIZE];
>     struct i386_record_s ir;
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     uint8_t rex_w = -1;
>     uint8_t rex_r = 0;
>   
> @@ -8839,7 +8839,7 @@ i386_mpx_bd_base (void)
>   
>     rcache = get_current_regcache ();
>     gdbarch *arch = rcache->arch ();
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
>   
>     regstatus = regcache_raw_read_unsigned (rcache, tdep->bndcfgu_regnum, &ret);
>   
> @@ -8853,7 +8853,7 @@ int
>   i386_mpx_enabled (void)
>   {
>     gdbarch *arch = get_current_arch ();
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
>     const struct target_desc *tdesc = tdep->tdesc;
>   
>     return (tdesc_find_feature (tdesc, "org.gnu.gdb.i386.mpx") != NULL);
> diff --git a/gdb/i386-windows-tdep.c b/gdb/i386-windows-tdep.c
> index 8e1cc17b91c..9eec6e28109 100644
> --- a/gdb/i386-windows-tdep.c
> +++ b/gdb/i386-windows-tdep.c
> @@ -136,7 +136,7 @@ i386_windows_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>   static void
>   i386_windows_init_abi_common (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     set_gdbarch_skip_trampoline_code (gdbarch, i386_windows_skip_trampoline_code);
>   
> diff --git a/gdb/i387-tdep.c b/gdb/i387-tdep.c
> index f056ea59347..42ed4eebc2c 100644
> --- a/gdb/i387-tdep.c
> +++ b/gdb/i387-tdep.c
> @@ -204,7 +204,7 @@ void
>   i387_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
>   		       struct frame_info *frame, const char *args)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     ULONGEST fctrl;
>     int fctrl_p;
>     ULONGEST fstat;
> @@ -440,7 +440,7 @@ void
>   i387_supply_fsave (struct regcache *regcache, int regnum, const void *fsave)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     const gdb_byte *regs = (const gdb_byte *) fsave;
>     int i;
> @@ -495,7 +495,7 @@ void
>   i387_collect_fsave (const struct regcache *regcache, int regnum, void *fsave)
>   {
>     gdbarch *arch = regcache->arch ();
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
>     gdb_byte *regs = (gdb_byte *) fsave;
>     int i;
>   
> @@ -589,7 +589,7 @@ void
>   i387_supply_fxsave (struct regcache *regcache, int regnum, const void *fxsave)
>   {
>     gdbarch *arch = regcache->arch ();
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
>     const gdb_byte *regs = (const gdb_byte *) fxsave;
>     int i;
>   
> @@ -673,7 +673,7 @@ void
>   i387_collect_fxsave (const struct regcache *regcache, int regnum, void *fxsave)
>   {
>     gdbarch *arch = regcache->arch ();
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
>     gdb_byte *regs = (gdb_byte *) fxsave;
>     int i;
>   
> @@ -906,7 +906,7 @@ i387_xsave_get_clear_bv (struct gdbarch *gdbarch, const void *xsave)
>   {
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     const gdb_byte *regs = (const gdb_byte *) xsave;
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     /* Get `xstat_bv'.  The supported bits in `xstat_bv' are 8 bytes.  */
>     ULONGEST xstate_bv = extract_unsigned_integer (XSAVE_XSTATE_BV_ADDR (regs),
> @@ -926,7 +926,7 @@ i387_supply_xsave (struct regcache *regcache, int regnum,
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     const gdb_byte *regs = (const gdb_byte *) xsave;
>     int i;
>     /* In 64-bit mode the split between "low" and "high" ZMM registers is at
> @@ -1349,7 +1349,7 @@ i387_collect_xsave (const struct regcache *regcache, int regnum,
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     gdb_byte *p, *regs = (gdb_byte *) xsave;
>     gdb_byte raw[I386_MAX_REGISTER_SIZE];
>     ULONGEST initial_xstate_bv, clear_bv, xstate_bv = 0;
> @@ -1934,7 +1934,7 @@ i387_tag (const gdb_byte *raw)
>   void
>   i387_return_value (struct gdbarch *gdbarch, struct regcache *regcache)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>     ULONGEST fstat;
>   
>     /* Set the top of the floating-point register stack to 7.  The
> @@ -1957,7 +1957,7 @@ i387_return_value (struct gdbarch *gdbarch, struct regcache *regcache)
>   void
>   i387_reset_bnd_regs (struct gdbarch *gdbarch, struct regcache *regcache)
>   {
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     if (I387_BND0R_REGNUM (tdep) > 0)
>       {
> diff --git a/gdb/ia64-linux-tdep.c b/gdb/ia64-linux-tdep.c
> index 64a57f5bf2f..508d4e6f7c6 100644
> --- a/gdb/ia64-linux-tdep.c
> +++ b/gdb/ia64-linux-tdep.c
> @@ -216,7 +216,7 @@ ia64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   static void
>   ia64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
>     static const char *const stap_register_prefixes[] = { "r", NULL };
>     static const char *const stap_register_indirection_prefixes[] = { "[",
>   								    NULL };
> diff --git a/gdb/ia64-tdep.c b/gdb/ia64-tdep.c
> index 82456dc9c98..de343cfe17d 100644
> --- a/gdb/ia64-tdep.c
> +++ b/gdb/ia64-tdep.c
> @@ -310,7 +310,7 @@ static const struct floatformat *floatformats_ia64_ext[2] =
>   static struct type *
>   ia64_ext_type (struct gdbarch *gdbarch)
>   {
> -  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->ia64_ext_type)
>       tdep->ia64_ext_type
> @@ -2177,7 +2177,7 @@ ia64_sigtramp_frame_init_saved_regs (struct frame_info *this_frame,
>   				     struct ia64_frame_cache *cache)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->sigcontext_register_address)
>       {
> @@ -2336,7 +2336,7 @@ ia64_sigtramp_frame_sniffer (const struct frame_unwind *self,
>   			     void **this_cache)
>   {
>     gdbarch *arch = get_frame_arch (this_frame);
> -  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (arch);
> +  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (arch);
>     if (tdep->pc_in_sigtramp)
>       {
>         CORE_ADDR pc = get_frame_pc (this_frame);
> @@ -2485,7 +2485,7 @@ ia64_access_reg (unw_addr_space_t as, unw_regnum_t uw_regnum, unw_word_t *val,
>     unw_word_t bsp, sof, cfm, psr, ip;
>     struct frame_info *this_frame = (struct frame_info *) arg;
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
>     
>     /* We never call any libunwind routines that need to write registers.  */
>     gdb_assert (!write);
> @@ -3484,7 +3484,7 @@ ia64_find_global_pointer_from_dynamic_section (struct gdbarch *gdbarch,
>   static CORE_ADDR
>   ia64_find_global_pointer (struct gdbarch *gdbarch, CORE_ADDR faddr)
>   {
> -  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
>     CORE_ADDR addr = 0;
>   
>     if (tdep->find_global_pointer_from_solib)
> @@ -3679,7 +3679,7 @@ ia64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>   		      function_call_return_method return_method,
>   		      CORE_ADDR struct_addr)
>   {
> -  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     int argno;
>     struct value *arg;
> diff --git a/gdb/loongarch-linux-nat.c b/gdb/loongarch-linux-nat.c
> index edc3d697d7b..689c10bd57e 100644
> --- a/gdb/loongarch-linux-nat.c
> +++ b/gdb/loongarch-linux-nat.c
> @@ -51,7 +51,7 @@ static void
>   fetch_gregs_from_thread (struct regcache *regcache, int regno, pid_t tid)
>   {
>     loongarch_gdbarch_tdep *tdep
> -    = (loongarch_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<loongarch_gdbarch_tdep> (regcache->arch ());
>     auto regs = tdep->regs;
>     elf_gregset_t regset;
>   
> @@ -78,7 +78,7 @@ static void
>   store_gregs_to_thread (struct regcache *regcache, int regno, pid_t tid)
>   {
>     loongarch_gdbarch_tdep *tdep
> -    = (loongarch_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<loongarch_gdbarch_tdep> (regcache->arch ());
>     auto regs = tdep->regs;
>     elf_gregset_t regset;
>   
> @@ -131,7 +131,7 @@ loongarch_linux_nat_target::register_u_offset (struct gdbarch *gdbarch,
>   					       int regno, int store_p)
>   {
>     loongarch_gdbarch_tdep *tdep
> -    = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +    = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
>     auto regs = tdep->regs;
>   
>     /* According to <asm/ptrace.h> */
> diff --git a/gdb/loongarch-linux-tdep.c b/gdb/loongarch-linux-tdep.c
> index 372643761b1..b6d790ab185 100644
> --- a/gdb/loongarch-linux-tdep.c
> +++ b/gdb/loongarch-linux-tdep.c
> @@ -41,7 +41,7 @@ loongarch_supply_gregset (const struct regset *r,
>   			  const void *gprs, size_t len)
>   {
>     loongarch_gdbarch_tdep *tdep
> -    = (loongarch_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<loongarch_gdbarch_tdep> (regcache->arch ());
>     auto regs = tdep->regs;
>   
>     int regsize = register_size (regcache->arch (), regs.r);
> @@ -85,7 +85,7 @@ loongarch_fill_gregset (const struct regset *r,
>   			void *gprs, size_t len)
>   {
>     loongarch_gdbarch_tdep *tdep
> -    = (loongarch_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
> +    = gdbarch_tdep<loongarch_gdbarch_tdep> (regcache->arch ());
>     auto regs = tdep->regs;
>     int regsize = register_size (regcache->arch (), regs.r);
>     gdb_byte *buf = nullptr;
> @@ -136,7 +136,7 @@ loongarch_linux_rt_sigframe_init (const struct tramp_frame *self,
>   				  CORE_ADDR func)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  loongarch_gdbarch_tdep *tdep = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
>     auto regs = tdep->regs;
>   
>     CORE_ADDR frame_sp = get_frame_sp (this_frame);
> @@ -177,7 +177,7 @@ loongarch_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   					const struct regcache *regcache)
>   {
>     loongarch_gdbarch_tdep *tdep
> -    = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +    = gdbarch_tdep<loongarch_gdbarch_tdep> (regcache->arch ());
>     auto regs = tdep->regs;
>     int regsize = register_size (gdbarch, regs.r);
>   
> diff --git a/gdb/loongarch-tdep.c b/gdb/loongarch-tdep.c
> index 963e832454a..af5ccb17286 100644
> --- a/gdb/loongarch-tdep.c
> +++ b/gdb/loongarch-tdep.c
> @@ -74,7 +74,7 @@ loongarch_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc,
>   			 struct trad_frame_cache *this_cache)
>   {
>     CORE_ADDR cur_pc = start_pc, prologue_end = 0;
> -  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  loongarch_gdbarch_tdep *tdep = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
>     auto regs = tdep->regs;
>     int32_t sp = regs.r + 3;
>     int32_t fp = regs.r + 22;
> @@ -306,7 +306,7 @@ loongarch_frame_cache (struct frame_info *this_frame, void **this_cache)
>     cache = trad_frame_cache_zalloc (this_frame);
>     *this_cache = cache;
>   
> -  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  loongarch_gdbarch_tdep *tdep = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
>     trad_frame_set_reg_realreg (cache, gdbarch_pc_regnum (gdbarch), tdep->regs.ra);
>   
>     pc = get_frame_address_in_block (this_frame);
> @@ -358,7 +358,7 @@ loongarch_return_value (struct gdbarch *gdbarch, struct value *function,
>   			struct type *type, struct regcache *regcache,
>   			gdb_byte *readbuf, const gdb_byte *writebuf)
>   {
> -  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  loongarch_gdbarch_tdep *tdep = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
>     auto regs = tdep->regs;
>     int len = TYPE_LENGTH (type);
>     int regnum = -1;
> @@ -386,7 +386,7 @@ loongarch_return_value (struct gdbarch *gdbarch, struct value *function,
>   static int
>   loongarch_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int num)
>   {
> -  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  loongarch_gdbarch_tdep *tdep = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
>     auto regs = tdep->regs;
>   
>     if (0 <= num && num < 32)
> @@ -512,7 +512,7 @@ loongarch_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>   	 we are looking for.  If it doesn't then we can't reuse this
>   	 gdbarch.  */
>         loongarch_gdbarch_tdep *candidate_tdep
> -	= (loongarch_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<loongarch_gdbarch_tdep> (arches->gdbarch);
>   
>         if (candidate_tdep->abi_features != abi_features)
>   	continue;
> diff --git a/gdb/m32c-tdep.c b/gdb/m32c-tdep.c
> index 4971be796cd..37456d16cb3 100644
> --- a/gdb/m32c-tdep.c
> +++ b/gdb/m32c-tdep.c
> @@ -142,7 +142,7 @@ struct m32c_gdbarch_tdep : gdbarch_tdep
>   static void
>   make_types (struct gdbarch *arch)
>   {
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>     unsigned long mach = gdbarch_bfd_arch_info (arch)->mach;
>     int data_addr_reg_bits, code_addr_reg_bits;
>     char type_name[50];
> @@ -215,7 +215,7 @@ make_types (struct gdbarch *arch)
>   static const char *
>   m32c_register_name (struct gdbarch *gdbarch, int num)
>   {
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
>     return tdep->regs[num].name;
>   }
>   
> @@ -223,7 +223,7 @@ m32c_register_name (struct gdbarch *gdbarch, int num)
>   static struct type *
>   m32c_register_type (struct gdbarch *arch, int reg_nr)
>   {
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>     return tdep->regs[reg_nr].type;
>   }
>   
> @@ -231,7 +231,7 @@ m32c_register_type (struct gdbarch *arch, int reg_nr)
>   static int
>   m32c_register_sim_regno (struct gdbarch *gdbarch, int reg_nr)
>   {
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
>     return tdep->regs[reg_nr].sim_num;
>   }
>   
> @@ -239,7 +239,7 @@ m32c_register_sim_regno (struct gdbarch *gdbarch, int reg_nr)
>   static int
>   m32c_debug_info_reg_to_regnum (struct gdbarch *gdbarch, int reg_nr)
>   {
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
>     if (0 <= reg_nr && reg_nr <= M32C_MAX_DWARF_REGNUM
>         && tdep->dwarf_regs[reg_nr])
>       return tdep->dwarf_regs[reg_nr]->num;
> @@ -254,7 +254,7 @@ static int
>   m32c_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
>   			  const struct reggroup *group)
>   {
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
>     struct m32c_reg *reg = &tdep->regs[regnum];
>   
>     /* The anonymous raw registers aren't in any groups.  */
> @@ -330,7 +330,7 @@ static int
>   m32c_read_flg (readable_regcache *cache)
>   {
>     gdbarch *arch = cache->arch ();
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>     ULONGEST flg;
>   
>     cache->raw_read (tdep->flg->num, &flg);
> @@ -530,7 +530,7 @@ static enum register_status
>   m32c_r3r2r1r0_read (struct m32c_reg *reg, readable_regcache *cache, gdb_byte *buf)
>   {
>     gdbarch *arch = reg->arch;
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>     int len = TYPE_LENGTH (tdep->r0->type);
>     enum register_status status;
>   
> @@ -567,7 +567,7 @@ m32c_r3r2r1r0_write (struct m32c_reg *reg, struct regcache *cache,
>   		     const gdb_byte *buf)
>   {
>     gdbarch *arch = reg->arch;
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>     int len = TYPE_LENGTH (tdep->r0->type);
>   
>     if (gdbarch_byte_order (reg->arch) == BFD_ENDIAN_BIG)
> @@ -595,7 +595,7 @@ m32c_pseudo_register_read (struct gdbarch *arch,
>   			   int cookednum,
>   			   gdb_byte *buf)
>   {
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>     struct m32c_reg *reg;
>   
>     gdb_assert (0 <= cookednum && cookednum < tdep->num_regs);
> @@ -613,7 +613,7 @@ m32c_pseudo_register_write (struct gdbarch *arch,
>   			    int cookednum,
>   			    const gdb_byte *buf)
>   {
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>     struct m32c_reg *reg;
>   
>     gdb_assert (0 <= cookednum && cookednum < tdep->num_regs);
> @@ -638,7 +638,7 @@ add_reg (struct gdbarch *arch,
>   	 struct m32c_reg *ry,
>   	 int n)
>   {
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>     struct m32c_reg *r = &tdep->regs[tdep->num_regs];
>   
>     gdb_assert (tdep->num_regs < M32C_MAX_NUM_REGS);
> @@ -678,7 +678,7 @@ set_dwarf_regnum (struct m32c_reg *reg, int num)
>   
>     /* Update the DWARF->reg mapping.  */
>     gdbarch *arch = reg->arch;
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>     tdep->dwarf_regs[num] = reg;
>   }
>   
> @@ -800,7 +800,7 @@ mark_save_restore (struct m32c_reg *reg)
>   static void
>   make_regs (struct gdbarch *arch)
>   {
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>     int mach = gdbarch_bfd_arch_info (arch)->mach;
>     int num_raw_regs;
>     int num_cooked_regs;
> @@ -1349,7 +1349,7 @@ m32c_pv_enter (struct m32c_pv_state *state, int size)
>       return 1;
>   
>     gdbarch *arch = state->arch;
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>     if (m32c_pv_push (state, state->fb, tdep->push_addr_bytes))
>       return 1;
>   
> @@ -1379,7 +1379,7 @@ static int
>   m32c_pv_pushm (struct m32c_pv_state *state, int src)
>   {
>     gdbarch *arch = state->arch;
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>   
>     /* The bits in SRC indicating which registers to save are:
>        r0 r1 r2 r3 a0 a1 sb fb */
> @@ -1400,7 +1400,7 @@ static int
>   m32c_is_1st_arg_reg (struct m32c_pv_state *state, pv_t value)
>   {
>     gdbarch *arch = state->arch;
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>   
>     return (value.kind == pvk_register
>   	  && (gdbarch_bfd_arch_info (state->arch)->mach == bfd_mach_m16c
> @@ -1415,7 +1415,7 @@ static int
>   m32c_is_arg_reg (struct m32c_pv_state *state, pv_t value)
>   {
>     gdbarch *arch = state->arch;
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>   
>     return (value.kind == pvk_register
>   	  && (gdbarch_bfd_arch_info (state->arch)->mach == bfd_mach_m16c
> @@ -1440,7 +1440,7 @@ m32c_is_arg_spill (struct m32c_pv_state *st,
>   		   pv_t value)
>   {
>     gdbarch *arch = st->arch;
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>   
>     return (m32c_is_arg_reg (st, value)
>   	  && loc.kind == srcdest_mem
> @@ -1464,7 +1464,7 @@ m32c_is_struct_return (struct m32c_pv_state *st,
>   		       pv_t value)
>   {
>     gdbarch *arch = st->arch;
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>   
>     return (m32c_is_1st_arg_reg (st, value)
>   	  && !st->stack->find_reg (st->arch, value.reg, 0)
> @@ -1482,7 +1482,7 @@ static int
>   m32c_pushm_is_reg_save (struct m32c_pv_state *st, int src)
>   {
>     gdbarch *arch = st->arch;
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>   
>     /* The bits in SRC indicating which registers to save are:
>        r0 r1 r2 r3 a0 a1 sb fb */
> @@ -1510,7 +1510,7 @@ check_for_saved (void *prologue_untyped, pv_t addr, CORE_ADDR size, pv_t value)
>   {
>     struct m32c_prologue *prologue = (struct m32c_prologue *) prologue_untyped;
>     struct gdbarch *arch = prologue->arch;
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>   
>     /* Is this the unchanged value of some register being saved on the
>        stack?  */
> @@ -1550,7 +1550,7 @@ m32c_analyze_prologue (struct gdbarch *arch,
>   		       CORE_ADDR start, CORE_ADDR limit,
>   		       struct m32c_prologue *prologue)
>   {
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>     unsigned long mach = gdbarch_bfd_arch_info (arch)->mach;
>     CORE_ADDR after_last_frame_related_insn;
>     struct m32c_pv_state st;
> @@ -1881,7 +1881,7 @@ m32c_frame_base (struct frame_info *this_frame,
>     struct m32c_prologue *p
>       = m32c_analyze_frame_prologue (this_frame, this_prologue_cache);
>     gdbarch *arch = get_frame_arch (this_frame);
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>   
>     /* In functions that use alloca, the distance between the stack
>        pointer and the frame base varies dynamically, so we can't use
> @@ -1932,7 +1932,7 @@ m32c_prev_register (struct frame_info *this_frame,
>   		    void **this_prologue_cache, int regnum)
>   {
>     gdbarch *arch = get_frame_arch (this_frame);
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
>     struct m32c_prologue *p
>       = m32c_analyze_frame_prologue (this_frame, this_prologue_cache);
>     CORE_ADDR frame_base = m32c_frame_base (this_frame, this_prologue_cache);
> @@ -2015,7 +2015,7 @@ m32c_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>   		      function_call_return_method return_method,
>   		      CORE_ADDR struct_addr)
>   {
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     unsigned long mach = gdbarch_bfd_arch_info (gdbarch)->mach;
>     CORE_ADDR cfa;
> @@ -2178,7 +2178,7 @@ m32c_return_value (struct gdbarch *gdbarch,
>   		   gdb_byte *readbuf,
>   		   const gdb_byte *writebuf)
>   {
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     enum return_value_convention conv;
>     ULONGEST valtype_len = TYPE_LENGTH (valtype);
> @@ -2309,7 +2309,7 @@ static CORE_ADDR
>   m32c_skip_trampoline_code (struct frame_info *frame, CORE_ADDR stop_pc)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (frame);
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>   
>     /* It would be nicer to simply look up the addresses of known
> @@ -2555,7 +2555,7 @@ m32c_virtual_frame_pointer (struct gdbarch *gdbarch, CORE_ADDR pc,
>     struct m32c_prologue p;
>   
>     struct regcache *regcache = get_current_regcache ();
> -  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
>     
>     if (!find_pc_partial_function (pc, &name, &func_addr, &func_end))
>       internal_error (__FILE__, __LINE__,
> diff --git a/gdb/m68hc11-tdep.c b/gdb/m68hc11-tdep.c
> index 98f1367423e..9eb18b937be 100644
> --- a/gdb/m68hc11-tdep.c
> +++ b/gdb/m68hc11-tdep.c
> @@ -146,14 +146,14 @@ struct m68gc11_gdbarch_tdep : gdbarch_tdep
>   static int
>   stack_correction (gdbarch *arch)
>   {
> -  m68gc11_gdbarch_tdep *tdep = (m68gc11_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m68gc11_gdbarch_tdep *tdep = gdbarch_tdep<m68gc11_gdbarch_tdep> (arch);
>     return tdep->stack_correction;
>   }
>   
>   static int
>   use_page_register (gdbarch *arch)
>   {
> -  m68gc11_gdbarch_tdep *tdep = (m68gc11_gdbarch_tdep *) gdbarch_tdep (arch);
> +  m68gc11_gdbarch_tdep *tdep = gdbarch_tdep<m68gc11_gdbarch_tdep> (arch);
>     return tdep->stack_correction;
>   }
>   
> @@ -642,7 +642,7 @@ m68hc11_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
>         return pc;
>       }
>   
> -  m68gc11_gdbarch_tdep *tdep = (m68gc11_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68gc11_gdbarch_tdep *tdep = gdbarch_tdep<m68gc11_gdbarch_tdep> (gdbarch);
>     seq_table = tdep->prologue;
>     
>     /* The 68hc11 stack is as follows:
> @@ -1020,7 +1020,7 @@ m68hc11_print_register (struct gdbarch *gdbarch, struct ui_file *file,
>     else
>       {
>         m68gc11_gdbarch_tdep *tdep
> -	= (m68gc11_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +	= gdbarch_tdep<m68gc11_gdbarch_tdep> (gdbarch);
>   
>         if (regno == HARD_PC_REGNUM && tdep->use_page_register)
>   	{
> @@ -1125,7 +1125,7 @@ m68hc11_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file,
>         gdb_printf (file, " Y=");
>         m68hc11_print_register (gdbarch, file, frame, HARD_Y_REGNUM);
>     
> -      m68gc11_gdbarch_tdep *tdep = (m68gc11_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      m68gc11_gdbarch_tdep *tdep = gdbarch_tdep<m68gc11_gdbarch_tdep> (gdbarch);
>   
>         if (tdep->use_page_register)
>   	{
> @@ -1417,7 +1417,7 @@ m68hc11_gdbarch_init (struct gdbarch_info info,
>          arches = gdbarch_list_lookup_by_info (arches->next, &info))
>       {
>         m68gc11_gdbarch_tdep *tdep
> -	= (m68gc11_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<m68gc11_gdbarch_tdep> (arches->gdbarch);
>   
>         if (tdep->elf_flags != elf_flags)
>   	continue;
> diff --git a/gdb/m68k-bsd-tdep.c b/gdb/m68k-bsd-tdep.c
> index 9ef70f0dda4..2614c223f8e 100644
> --- a/gdb/m68k-bsd-tdep.c
> +++ b/gdb/m68k-bsd-tdep.c
> @@ -133,7 +133,7 @@ m68kbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   static void
>   m68kbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     tdep->jb_pc = 5;
>     tdep->jb_elt_size = 4;
> diff --git a/gdb/m68k-linux-tdep.c b/gdb/m68k-linux-tdep.c
> index 85ad4741b1f..28401d3ecc6 100644
> --- a/gdb/m68k-linux-tdep.c
> +++ b/gdb/m68k-linux-tdep.c
> @@ -384,7 +384,7 @@ m68k_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   static void
>   m68k_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     linux_init_abi (info, gdbarch, 0);
>   
> diff --git a/gdb/m68k-tdep.c b/gdb/m68k-tdep.c
> index 568bde66f93..9e59f5904c3 100644
> --- a/gdb/m68k-tdep.c
> +++ b/gdb/m68k-tdep.c
> @@ -70,7 +70,7 @@ typedef BP_MANIPULATION (m68k_break_insn) m68k_breakpoint;
>   static struct type *
>   m68k_ps_type (struct gdbarch *gdbarch)
>   {
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->m68k_ps_type)
>       {
> @@ -99,7 +99,7 @@ m68k_ps_type (struct gdbarch *gdbarch)
>   static struct type *
>   m68881_ext_type (struct gdbarch *gdbarch)
>   {
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->m68881_ext_type)
>       tdep->m68881_ext_type
> @@ -120,7 +120,7 @@ m68881_ext_type (struct gdbarch *gdbarch)
>   static struct type *
>   m68k_register_type (struct gdbarch *gdbarch, int regnum)
>   {
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->fpregs_present)
>       {
> @@ -171,7 +171,7 @@ static const char * const m68k_register_names[] = {
>   static const char *
>   m68k_register_name (struct gdbarch *gdbarch, int regnum)
>   {
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     if (regnum < 0 || regnum >= ARRAY_SIZE (m68k_register_names))
>       internal_error (__FILE__, __LINE__,
> @@ -191,7 +191,7 @@ static int
>   m68k_convert_register_p (struct gdbarch *gdbarch,
>   			 int regnum, struct type *type)
>   {
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->fpregs_present)
>       return 0;
> @@ -300,7 +300,7 @@ m68k_extract_return_value (struct type *type, struct regcache *regcache,
>     if (type->code () == TYPE_CODE_PTR && len == 4)
>       {
>         struct gdbarch *gdbarch = regcache->arch ();
> -      m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>         regcache->raw_read (tdep->pointer_result_regnum, valbuf);
>       }
>     else if (len <= 4)
> @@ -325,7 +325,7 @@ m68k_svr4_extract_return_value (struct type *type, struct regcache *regcache,
>   {
>     gdb_byte buf[M68K_MAX_REGISTER_SIZE];
>     struct gdbarch *gdbarch = regcache->arch ();
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->float_return && type->code () == TYPE_CODE_FLT)
>       {
> @@ -348,7 +348,7 @@ m68k_store_return_value (struct type *type, struct regcache *regcache,
>     if (type->code () == TYPE_CODE_PTR && len == 4)
>       {
>         struct gdbarch *gdbarch = regcache->arch ();
> -      m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>         regcache->raw_write (tdep->pointer_result_regnum, valbuf);
>         /* gdb historically also set D0 in the SVR4 case.  */
>         if (tdep->pointer_result_regnum != M68K_D0_REGNUM)
> @@ -371,7 +371,7 @@ m68k_svr4_store_return_value (struct type *type, struct regcache *regcache,
>   			      const gdb_byte *valbuf)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->float_return && type->code () == TYPE_CODE_FLT)
>       {
> @@ -391,7 +391,7 @@ m68k_svr4_store_return_value (struct type *type, struct regcache *regcache,
>   static int
>   m68k_reg_struct_return_p (struct gdbarch *gdbarch, struct type *type)
>   {
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>     enum type_code code = type->code ();
>     int len = TYPE_LENGTH (type);
>   
> @@ -469,7 +469,7 @@ m68k_svr4_return_value (struct gdbarch *gdbarch, struct value *function,
>   			gdb_byte *readbuf, const gdb_byte *writebuf)
>   {
>     enum type_code code = type->code ();
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     /* Aggregates with a single member are always returned like their
>        sole element.  */
> @@ -541,7 +541,7 @@ m68k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>   		      function_call_return_method return_method,
>   		      CORE_ADDR struct_addr)
>   {
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     gdb_byte buf[4];
>     int i;
> @@ -596,7 +596,7 @@ m68k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>   static int
>   m68k_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int num)
>   {
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     if (num < 8)
>       /* d0..7 */
> @@ -766,7 +766,7 @@ m68k_analyze_register_saves (struct gdbarch *gdbarch, CORE_ADDR pc,
>   			     struct m68k_frame_cache *cache)
>   {
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     if (cache->locals >= 0)
>       {
> @@ -1058,7 +1058,7 @@ m68k_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
>     gdb_byte *buf;
>     CORE_ADDR sp, jb_addr;
>     struct gdbarch *gdbarch = get_frame_arch (frame);
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>   
>     if (tdep->jb_pc < 0)
> @@ -1104,7 +1104,7 @@ m68k_return_in_first_hidden_param_p (struct gdbarch *gdbarch,
>   void
>   m68k_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     /* SVR4 uses a different calling convention.  */
>     set_gdbarch_return_value (gdbarch, m68k_svr4_return_value);
> @@ -1122,7 +1122,7 @@ m68k_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   static void
>   m68k_embedded_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     m68k_svr4_init_abi (info, gdbarch);
>     tdep->pointer_result_regnum = M68K_D0_REGNUM;
> @@ -1237,7 +1237,7 @@ m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
>       {
>         m68k_gdbarch_tdep *tdep
> -	= (m68k_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
> +	= gdbarch_tdep<m68k_gdbarch_tdep> (best_arch->gdbarch);
>   
>         if (flavour != tdep->flavour)
>   	continue;
> @@ -1339,7 +1339,7 @@ m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>   static void
>   m68k_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
>   {
> -  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
>   
>     if (tdep == NULL)
>       return;
> diff --git a/gdb/mep-tdep.c b/gdb/mep-tdep.c
> index 6b3a62391c0..d5ba78c6df9 100644
> --- a/gdb/mep-tdep.c
> +++ b/gdb/mep-tdep.c
> @@ -260,7 +260,7 @@ me_module_register_set (CONFIG_ATTR me_module,
>          specifically excluding the generic coprocessor register sets.  */
>   
>     mep_gdbarch_tdep *tdep
> -    = (mep_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
> +    = gdbarch_tdep<mep_gdbarch_tdep> (target_gdbarch ());
>     CGEN_CPU_DESC desc = tdep->cpu_desc;
>     const CGEN_HW_ENTRY *hw;
>   
> @@ -856,7 +856,7 @@ current_me_module (void)
>     else
>       {
>         mep_gdbarch_tdep *tdep
> -	= (mep_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
> +	= gdbarch_tdep<mep_gdbarch_tdep> (target_gdbarch ());
>         return tdep->me_module;
>       }
>   }
> @@ -2391,7 +2391,7 @@ mep_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          arches = gdbarch_list_lookup_by_info (arches->next, &info))
>       {
>         mep_gdbarch_tdep *tdep
> -	= (mep_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<mep_gdbarch_tdep> (arches->gdbarch);
>   
>         if (tdep->me_module == me_module)
>   	return arches->gdbarch;
> diff --git a/gdb/mips-linux-tdep.c b/gdb/mips-linux-tdep.c
> index d8f90ccf881..ca313a28279 100644
> --- a/gdb/mips-linux-tdep.c
> +++ b/gdb/mips-linux-tdep.c
> @@ -1317,7 +1317,7 @@ mips_linux_get_syscall_number (struct gdbarch *gdbarch,
>   			       thread_info *thread)
>   {
>     struct regcache *regcache = get_thread_regcache (thread);
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     int regsize = register_size (gdbarch, MIPS_V0_REGNUM);
>     /* The content of a register */
> @@ -1527,7 +1527,7 @@ static void
>   mips_linux_init_abi (struct gdbarch_info info,
>   		     struct gdbarch *gdbarch)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>     enum mips_abi abi = mips_abi (gdbarch);
>     struct tdesc_arch_data *tdesc_data = info.tdesc_data;
>   
> diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
> index fc1cb46de84..1ea16767e54 100644
> --- a/gdb/mips-tdep.c
> +++ b/gdb/mips-tdep.c
> @@ -227,7 +227,7 @@ static const char mips_disassembler_options_n64[] = "gpr-names=64";
>   const struct mips_regnum *
>   mips_regnum (struct gdbarch *gdbarch)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>     return tdep->regnum;
>   }
>   
> @@ -252,7 +252,7 @@ mips_float_register_p (struct gdbarch *gdbarch, int regnum)
>   static bool
>   mips_eabi (gdbarch *arch)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (arch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (arch);
>     return (tdep->mips_abi == MIPS_ABI_EABI32 \
>   	  || tdep->mips_abi == MIPS_ABI_EABI64);
>   }
> @@ -260,21 +260,21 @@ mips_eabi (gdbarch *arch)
>   static int
>   mips_last_fp_arg_regnum (gdbarch *arch)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (arch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (arch);
>     return tdep->mips_last_fp_arg_regnum;
>   }
>   
>   static int
>   mips_last_arg_regnum (gdbarch *arch)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (arch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (arch);
>     return tdep->mips_last_arg_regnum;
>   }
>   
>   static enum mips_fpu_type
>   mips_get_fpu_type (gdbarch *arch)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (arch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (arch);
>     return tdep->mips_fpu_type;
>   }
>   
> @@ -282,14 +282,14 @@ mips_get_fpu_type (gdbarch *arch)
>   enum mips_abi
>   mips_abi (struct gdbarch *gdbarch)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>     return tdep->mips_abi;
>   }
>   
>   int
>   mips_isa_regsize (struct gdbarch *gdbarch)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>   
>     /* If we know how big the registers are, use that size.  */
>     if (tdep->register_size_valid_p)
> @@ -335,7 +335,7 @@ mips_abi_regsize (struct gdbarch *gdbarch)
>   static int
>   is_mips16_isa (struct gdbarch *gdbarch)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>     return tdep->mips_isa == ISA_MIPS16;
>   }
>   
> @@ -344,7 +344,7 @@ is_mips16_isa (struct gdbarch *gdbarch)
>   static int
>   is_micromips_isa (struct gdbarch *gdbarch)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>     return tdep->mips_isa == ISA_MICROMIPS;
>   }
>   
> @@ -636,7 +636,7 @@ static const char * const mips_linux_reg_names[NUM_MIPS_PROCESSOR_REGS] = {
>   static const char *
>   mips_register_name (struct gdbarch *gdbarch, int regno)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>     /* GPR names for all ABIs other than n32/n64.  */
>     static const char *mips_gpr_names[] = {
>       "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
> @@ -777,7 +777,7 @@ mips_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
>     else if (register_size (gdbarch, rawnum) >
>   	   register_size (gdbarch, cookednum))
>       {
> -      mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>   
>         if (tdep->mips64_transfers_32bit_regs_p)
>   	return regcache->raw_read_part (rawnum, 0, 4, buf);
> @@ -810,7 +810,7 @@ mips_pseudo_register_write (struct gdbarch *gdbarch,
>     else if (register_size (gdbarch, rawnum) >
>   	   register_size (gdbarch, cookednum))
>       {
> -      mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>   
>         if (tdep->mips64_transfers_32bit_regs_p)
>   	regcache->raw_write_part (rawnum, 0, 4, buf);
> @@ -855,7 +855,7 @@ mips_ax_pseudo_register_push_stack (struct gdbarch *gdbarch,
>         if (register_size (gdbarch, rawnum) > register_size (gdbarch, reg))
>   	{
>   	  mips_gdbarch_tdep *tdep
> -	    = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +	    = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>   
>   	  if (!tdep->mips64_transfers_32bit_regs_p
>   	      || gdbarch_byte_order (gdbarch) != BFD_ENDIAN_BIG)
> @@ -1059,7 +1059,7 @@ mips_register_type (struct gdbarch *gdbarch, int regnum)
>     else
>       {
>         int rawnum = regnum - gdbarch_num_regs (gdbarch);
> -      mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>   
>         /* The cooked or ABI registers.  These are sized according to
>   	 the ABI (with a few complications).  */
> @@ -1191,7 +1191,7 @@ show_mask_address (struct ui_file *file, int from_tty,
>         else
>   	{
>   	  mips_gdbarch_tdep *tdep
> -	    = (mips_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
> +	    = gdbarch_tdep<mips_gdbarch_tdep> (target_gdbarch ());
>   
>   	  if (mips_mask_address_p (tdep))
>   	    additional_text = _(" (currently \"on\")");
> @@ -1727,7 +1727,7 @@ mips32_next_pc (struct regcache *regcache, CORE_ADDR pc)
>   	    case 12:            /* SYSCALL */
>   	      {
>   		mips_gdbarch_tdep *tdep
> -		  = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +		  = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>   
>   		if (tdep->syscall_next_pc != NULL)
>   		  pc = tdep->syscall_next_pc (get_current_frame ());
> @@ -1938,7 +1938,7 @@ micromips_next_pc (struct regcache *regcache, CORE_ADDR pc)
>   		case 0x22d: /* SYSCALL:  000000 1000101101 111100 */
>   		  {
>   		    mips_gdbarch_tdep *tdep
> -		      = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +		      = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>   
>   		    if (tdep->syscall_next_pc != NULL)
>   		      pc = tdep->syscall_next_pc (get_current_frame ());
> @@ -3901,7 +3901,7 @@ mips_stub_frame_base_sniffer (struct frame_info *this_frame)
>   static CORE_ADDR
>   mips_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>   
>     if (mips_mask_address_p (tdep) && (((ULONGEST) addr) >> 32 == 0xffffffffUL))
>       /* This hack is a work-around for existing boards using PMON, the
> @@ -4804,7 +4804,7 @@ mips_eabi_return_value (struct gdbarch *gdbarch, struct value *function,
>   			struct type *type, struct regcache *regcache,
>   			gdb_byte *readbuf, const gdb_byte *writebuf)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>     int fp_return_type = 0;
>     int offset, regnum, xfer;
>   
> @@ -5195,7 +5195,7 @@ mips_n32n64_return_value (struct gdbarch *gdbarch, struct value *function,
>   			  struct type *type, struct regcache *regcache,
>   			  gdb_byte *readbuf, const gdb_byte *writebuf)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>   
>     /* From MIPSpro N32 ABI Handbook, Document Number: 007-2816-004
>   
> @@ -5704,7 +5704,7 @@ mips_o32_return_value (struct gdbarch *gdbarch, struct value *function,
>   {
>     CORE_ADDR func_addr = function ? find_function_addr (function, NULL) : 0;
>     int mips16 = mips_pc_is_mips16 (gdbarch, func_addr);
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>     enum mips_fval_reg fval_reg;
>   
>     fval_reg = readbuf ? mips16 ? mips_fval_gpr : mips_fval_fpr : mips_fval_both;
> @@ -8101,7 +8101,7 @@ mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>     else if (arches != NULL)
>       {
>         mips_gdbarch_tdep *tdep
> -	= (mips_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<mips_gdbarch_tdep> (arches->gdbarch);
>         elf_flags = tdep->elf_flags;
>       }
>     else
> @@ -8142,7 +8142,7 @@ mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>     if (found_abi == MIPS_ABI_UNKNOWN && info.abfd == NULL && arches != NULL)
>       {
>         mips_gdbarch_tdep *tdep
> -	= (mips_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<mips_gdbarch_tdep> (arches->gdbarch);
>         found_abi = tdep->found_abi;
>       }
>   
> @@ -8459,7 +8459,7 @@ mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          arches = gdbarch_list_lookup_by_info (arches->next, &info))
>       {
>         mips_gdbarch_tdep *tdep
> -        = (mips_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +        = gdbarch_tdep<mips_gdbarch_tdep> (arches->gdbarch);
>   
>         /* MIPS needs to be pedantic about which ABI and the compressed
>   	 ISA variation the object is using.  */
> @@ -8917,7 +8917,7 @@ mips_fpu_type_str (enum mips_fpu_type fpu_type)
>   static void
>   mips_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
>   {
> -  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
>     if (tdep != NULL)
>       {
>         int ef_mips_arch;
> diff --git a/gdb/mn10300-tdep.c b/gdb/mn10300-tdep.c
> index 7a41070bb30..22511d894d4 100644
> --- a/gdb/mn10300-tdep.c
> +++ b/gdb/mn10300-tdep.c
> @@ -1412,7 +1412,7 @@ mn10300_gdbarch_init (struct gdbarch_info info,
>   static void
>   mn10300_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
>   {
> -  mn10300_gdbarch_tdep *tdep = (mn10300_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  mn10300_gdbarch_tdep *tdep = gdbarch_tdep<mn10300_gdbarch_tdep> (gdbarch);
>     gdb_printf (file, "mn10300_dump_tdep: am33_mode = %d\n",
>   	      tdep->am33_mode);
>   }
> diff --git a/gdb/mn10300-tdep.h b/gdb/mn10300-tdep.h
> index 10fef99c5d7..87b861ead90 100644
> --- a/gdb/mn10300-tdep.h
> +++ b/gdb/mn10300-tdep.h
> @@ -84,7 +84,7 @@ struct mn10300_gdbarch_tdep : gdbarch_tdep
>   static inline int
>   get_am33_mode (gdbarch *arch)
>   {
> -  mn10300_gdbarch_tdep *tdep = (mn10300_gdbarch_tdep *) gdbarch_tdep (arch);
> +  mn10300_gdbarch_tdep *tdep = gdbarch_tdep<mn10300_gdbarch_tdep> (arch);
>     return tdep->am33_mode;
>   }
>   
> diff --git a/gdb/msp430-tdep.c b/gdb/msp430-tdep.c
> index 28268a95139..4ae8b3d5626 100644
> --- a/gdb/msp430-tdep.c
> +++ b/gdb/msp430-tdep.c
> @@ -341,7 +341,7 @@ msp430_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc,
>     int rn;
>     pv_t reg[MSP430_NUM_TOTAL_REGS];
>     CORE_ADDR after_last_frame_setup_insn = start_pc;
> -  msp430_gdbarch_tdep *tdep = (msp430_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  msp430_gdbarch_tdep *tdep = gdbarch_tdep<msp430_gdbarch_tdep> (gdbarch);
>     int code_model = tdep->code_model;
>     int sz;
>   
> @@ -570,7 +570,7 @@ msp430_return_value (struct gdbarch *gdbarch,
>   {
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     LONGEST valtype_len = TYPE_LENGTH (valtype);
> -  msp430_gdbarch_tdep *tdep = (msp430_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  msp430_gdbarch_tdep *tdep = gdbarch_tdep<msp430_gdbarch_tdep> (gdbarch);
>     int code_model = tdep->code_model;
>   
>     if (TYPE_LENGTH (valtype) > 8
> @@ -651,7 +651,7 @@ msp430_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>     int write_pass;
>     int sp_off = 0;
>     CORE_ADDR cfa;
> -  msp430_gdbarch_tdep *tdep = (msp430_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  msp430_gdbarch_tdep *tdep = gdbarch_tdep<msp430_gdbarch_tdep> (gdbarch);
>     int code_model = tdep->code_model;
>   
>     struct type *func_type = value_type (function);
> @@ -814,7 +814,7 @@ msp430_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
>   
>     stub_name = bms.minsym->linkage_name ();
>   
> -  msp430_gdbarch_tdep *tdep = (msp430_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  msp430_gdbarch_tdep *tdep = gdbarch_tdep<msp430_gdbarch_tdep> (gdbarch);
>     if (tdep->code_model == MSP_SMALL_CODE_MODEL
>         && msp430_in_return_stub (gdbarch, pc, stub_name))
>       {
> @@ -877,7 +877,7 @@ msp430_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>   	  if (ca && gdbarch_bfd_arch_info (ca)->arch == bfd_arch_msp430)
>   	    {
>   	      msp430_gdbarch_tdep *ca_tdep
> -		= (msp430_gdbarch_tdep *) gdbarch_tdep (ca);
> +		= gdbarch_tdep<msp430_gdbarch_tdep> (ca);
>   
>   	      elf_flags = ca_tdep->elf_flags;
>   	      isa = ca_tdep->isa;
> @@ -904,7 +904,7 @@ msp430_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          arches = gdbarch_list_lookup_by_info (arches->next, &info))
>       {
>         msp430_gdbarch_tdep *candidate_tdep
> -	= (msp430_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<msp430_gdbarch_tdep> (arches->gdbarch);
>   
>         if (candidate_tdep->elf_flags != elf_flags
>   	  || candidate_tdep->isa != isa
> diff --git a/gdb/nds32-tdep.c b/gdb/nds32-tdep.c
> index e95ad7cc662..11bfd2d1f54 100644
> --- a/gdb/nds32-tdep.c
> +++ b/gdb/nds32-tdep.c
> @@ -289,7 +289,7 @@ typedef BP_MANIPULATION (nds32_break_insn) nds32_breakpoint;
>   static int
>   nds32_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int num)
>   {
> -  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
>     const int FSR = 38;
>     const int FDR = FSR + 32;
>   
> @@ -432,7 +432,7 @@ nds32_pseudo_register_read (struct gdbarch *gdbarch,
>   			    readable_regcache *regcache, int regnum,
>   			    gdb_byte *buf)
>   {
> -  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
>     gdb_byte reg_buf[8];
>     int offset, fdr_regnum;
>     enum register_status status;
> @@ -471,7 +471,7 @@ nds32_pseudo_register_write (struct gdbarch *gdbarch,
>   			     struct regcache *regcache, int regnum,
>   			     const gdb_byte *buf)
>   {
> -  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
>     gdb_byte reg_buf[8];
>     int offset, fdr_regnum;
>   
> @@ -608,7 +608,7 @@ static CORE_ADDR
>   nds32_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
>   			CORE_ADDR limit_pc, struct nds32_frame_cache *cache)
>   {
> -  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
>     int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
>     /* Current scanning status.  */
>     int in_prologue_bb = 0;
> @@ -1169,7 +1169,7 @@ static int
>   nds32_analyze_epilogue (struct gdbarch *gdbarch, CORE_ADDR pc,
>   			struct nds32_frame_cache *cache)
>   {
> -  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
>     int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
>     CORE_ADDR limit_pc;
>     uint32_t insn, insn_len;
> @@ -1220,7 +1220,7 @@ nds32_analyze_epilogue (struct gdbarch *gdbarch, CORE_ADDR pc,
>   static int
>   nds32_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR addr)
>   {
> -  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
>     int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
>     int insn_type = INSN_NORMAL;
>     int ret_found = 0;
> @@ -1424,7 +1424,7 @@ nds32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>     int i;
>     ULONGEST regval;
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
>     struct type *func_type = value_type (function);
>     int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
>     int abi_split = nds32_abi_split (tdep->elf_abi);
> @@ -1652,7 +1652,7 @@ nds32_extract_return_value (struct gdbarch *gdbarch, struct type *type,
>   			    struct regcache *regcache, gdb_byte *valbuf)
>   {
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
>     int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
>     int calling_use_fpr;
>     int len;
> @@ -1742,7 +1742,7 @@ nds32_store_return_value (struct gdbarch *gdbarch, struct type *type,
>   			  struct regcache *regcache, const gdb_byte *valbuf)
>   {
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
>     int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
>     int calling_use_fpr;
>     int len;
> @@ -1965,7 +1965,7 @@ nds32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
>       {
>         nds32_gdbarch_tdep *idep
> -	= (nds32_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
> +	= gdbarch_tdep<nds32_gdbarch_tdep> (best_arch->gdbarch);
>   
>         if (idep->elf_abi != elf_abi)
>   	continue;
> diff --git a/gdb/nios2-linux-tdep.c b/gdb/nios2-linux-tdep.c
> index a32f79aa28a..da69638b20b 100644
> --- a/gdb/nios2-linux-tdep.c
> +++ b/gdb/nios2-linux-tdep.c
> @@ -217,7 +217,7 @@ nios2_linux_is_kernel_helper (CORE_ADDR pc)
>   static void
>   nios2_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  nios2_gdbarch_tdep *tdep = (nios2_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  nios2_gdbarch_tdep *tdep = gdbarch_tdep<nios2_gdbarch_tdep> (gdbarch);
>   
>     linux_init_abi (info, gdbarch, 0);
>   
> diff --git a/gdb/nios2-tdep.c b/gdb/nios2-tdep.c
> index 159d31b2d0f..0bad229b44a 100644
> --- a/gdb/nios2-tdep.c
> +++ b/gdb/nios2-tdep.c
> @@ -2098,7 +2098,7 @@ static CORE_ADDR
>   nios2_get_next_pc (struct regcache *regcache, CORE_ADDR pc)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  nios2_gdbarch_tdep *tdep = (nios2_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  nios2_gdbarch_tdep *tdep = gdbarch_tdep<nios2_gdbarch_tdep> (gdbarch);
>     unsigned long mach = gdbarch_bfd_arch_info (gdbarch)->mach;
>     unsigned int insn;
>     const struct nios2_opcode *op = nios2_fetch_insn (gdbarch, pc, &insn);
> @@ -2221,7 +2221,7 @@ static int
>   nios2_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (frame);
> -  nios2_gdbarch_tdep *tdep = (nios2_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  nios2_gdbarch_tdep *tdep = gdbarch_tdep<nios2_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     CORE_ADDR jb_addr = get_frame_register_unsigned (frame, NIOS2_R4_REGNUM);
>     gdb_byte buf[4];
> diff --git a/gdb/or1k-tdep.c b/gdb/or1k-tdep.c
> index 2b906fa69d3..4699b755d42 100644
> --- a/gdb/or1k-tdep.c
> +++ b/gdb/or1k-tdep.c
> @@ -248,7 +248,7 @@ or1k_return_value (struct gdbarch *gdbarch, struct value *functype,
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     enum type_code rv_type = valtype->code ();
>     unsigned int rv_size = TYPE_LENGTH (valtype);
> -  or1k_gdbarch_tdep *tdep = (or1k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  or1k_gdbarch_tdep *tdep = gdbarch_tdep<or1k_gdbarch_tdep> (gdbarch);
>     int bpw = tdep->bytes_per_word;
>   
>     /* Deal with struct/union as addresses.  If an array won't fit in a
> @@ -353,7 +353,7 @@ or1k_delay_slot_p (struct gdbarch *gdbarch, CORE_ADDR pc)
>   {
>     const CGEN_INSN *insn;
>     CGEN_FIELDS tmp_fields;
> -  or1k_gdbarch_tdep *tdep = (or1k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  or1k_gdbarch_tdep *tdep = gdbarch_tdep<or1k_gdbarch_tdep> (gdbarch);
>   
>     insn = cgen_lookup_insn (tdep->gdb_cgen_cpu_desc,
>   			   NULL,
> @@ -635,7 +635,7 @@ or1k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>     int heap_offset = 0;
>     CORE_ADDR heap_sp = sp - 128;
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  or1k_gdbarch_tdep *tdep = (or1k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  or1k_gdbarch_tdep *tdep = gdbarch_tdep<or1k_gdbarch_tdep> (gdbarch);
>     int bpa = tdep->bytes_per_address;
>     int bpw = tdep->bytes_per_word;
>     struct type *func_type = value_type (function);
> @@ -1273,7 +1273,7 @@ or1k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>   static void
>   or1k_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
>   {
> -  or1k_gdbarch_tdep *tdep = (or1k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  or1k_gdbarch_tdep *tdep = gdbarch_tdep<or1k_gdbarch_tdep> (gdbarch);
>   
>     if (NULL == tdep)
>       return; /* Nothing to report */
> diff --git a/gdb/ppc-fbsd-nat.c b/gdb/ppc-fbsd-nat.c
> index ce045ac55ab..d0a5778e2d3 100644
> --- a/gdb/ppc-fbsd-nat.c
> +++ b/gdb/ppc-fbsd-nat.c
> @@ -100,7 +100,7 @@ fill_fpregset (const struct regcache *regcache,
>   static int
>   getfpregs_supplies (struct gdbarch *gdbarch, int regno)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
>   	 point registers.  Traditionally, GDB's register set has still
> @@ -185,7 +185,7 @@ static int
>   ppcfbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int i, regnum;
>   
>     /* The stack pointer shouldn't be zero.  */
> diff --git a/gdb/ppc-fbsd-tdep.c b/gdb/ppc-fbsd-tdep.c
> index 4afcc3019a4..f5b482921a7 100644
> --- a/gdb/ppc-fbsd-tdep.c
> +++ b/gdb/ppc-fbsd-tdep.c
> @@ -126,7 +126,7 @@ ppcfbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   				      void *cb_data,
>   				      const struct regcache *regcache)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->wordsize == 4)
>       cb (".reg", 148, 148, &ppc32_fbsd_gregset, NULL, cb_data);
> @@ -200,7 +200,7 @@ static struct trad_frame_cache *
>   ppcfbsd_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     struct trad_frame_cache *cache;
>     CORE_ADDR addr, base, func;
>     gdb_byte buf[PPC_INSN_SIZE];
> @@ -287,7 +287,7 @@ static CORE_ADDR
>   ppcfbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
>   				  CORE_ADDR lm_addr, CORE_ADDR offset)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     struct regcache *regcache;
>     int tp_offset, tp_regnum;
>   
> @@ -319,7 +319,7 @@ ppcfbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
>   static void
>   ppcfbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     /* Generic FreeBSD support. */
>     fbsd_init_abi (info, gdbarch);
> diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c
> index f959bb0c1ad..de4158c411a 100644
> --- a/gdb/ppc-linux-nat.c
> +++ b/gdb/ppc-linux-nat.c
> @@ -649,7 +649,7 @@ static int
>   ppc_register_u_addr (struct gdbarch *gdbarch, int regno)
>   {
>     int u_addr = -1;
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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 +802,7 @@ static void
>   fetch_spe_register (struct regcache *regcache, int tid, int regno)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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 +911,7 @@ static void
>   fetch_register (struct regcache *regcache, int tid, int regno)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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;
> @@ -1156,7 +1156,7 @@ static void
>   fetch_gp_regs (struct regcache *regcache, int tid)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int i;
>   
>     if (have_ptrace_getsetregs)
> @@ -1208,7 +1208,7 @@ static void
>   fetch_fp_regs (struct regcache *regcache, int tid)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int i;
>   
>     if (have_ptrace_getsetfpregs)
> @@ -1226,7 +1226,7 @@ static void
>   fetch_ppc_registers (struct regcache *regcache, int tid)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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 +1425,7 @@ static void
>   store_spe_register (const struct regcache *regcache, int tid, int regno)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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 +1477,7 @@ static void
>   store_register (const struct regcache *regcache, int tid, int regno)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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;
> @@ -1718,7 +1718,7 @@ static void
>   store_gp_regs (const struct regcache *regcache, int tid, int regno)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int i;
>   
>     if (have_ptrace_getsetregs)
> @@ -1780,7 +1780,7 @@ static void
>   store_fp_regs (const struct regcache *regcache, int tid, int regno)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int i;
>   
>     if (have_ptrace_getsetfpregs)
> @@ -1798,7 +1798,7 @@ static void
>   store_ppc_registers (const struct regcache *regcache, int tid)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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)
> diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c
> index 4c5f8b7a281..5a8ba239343 100644
> --- a/gdb/ppc-linux-tdep.c
> +++ b/gdb/ppc-linux-tdep.c
> @@ -332,7 +332,7 @@ ppc_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
>   {
>     unsigned int insnbuf[POWERPC32_PLT_CHECK_LEN];
>     struct gdbarch *gdbarch = get_frame_arch (frame);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     CORE_ADDR target = 0;
>     int scan_limit, i;
> @@ -898,7 +898,7 @@ ppc_linux_vsxregset (void)
>   const struct regset *
>   ppc_linux_cgprregset (struct gdbarch *gdbarch)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->wordsize == 4)
>       {
> @@ -938,7 +938,7 @@ ppc_linux_collect_core_cpgrregset (const struct regset *regset,
>   				   int regnum, void *buf, size_t len)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     const struct regset *cgprregset = ppc_linux_cgprregset (gdbarch);
>   
> @@ -985,7 +985,7 @@ ppc_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   					void *cb_data,
>   					const struct regcache *regcache)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int have_altivec = tdep->ppc_vr0_regnum != -1;
>     int have_vsx = tdep->ppc_vsr0_upper_regnum != -1;
>     int have_ppr = tdep->ppc_ppr_regnum != -1;
> @@ -1170,7 +1170,7 @@ ppc_linux_sigtramp_cache (struct frame_info *this_frame,
>     CORE_ADDR fpregs;
>     int i;
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>   
>     base = get_frame_register_unsigned (this_frame,
> @@ -1341,7 +1341,7 @@ ppc_linux_get_syscall_number (struct gdbarch *gdbarch,
>   			      thread_info *thread)
>   {
>     struct regcache *regcache = get_thread_regcache (thread);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>   
>     /* Make sure we're in a 32- or 64-bit machine */
> @@ -1417,7 +1417,7 @@ static int
>   ppc_linux_syscall_record (struct regcache *regcache)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     ULONGEST scnum;
>     enum gdb_syscall syscall_gdb;
>     int ret;
> @@ -1507,7 +1507,7 @@ ppc_linux_record_signal (struct gdbarch *gdbarch, struct regcache *regcache,
>     const int SIGNAL_FRAMESIZE = 128;
>     const int sizeof_rt_sigframe = 1440 * 2 + 8 * 2 + 4 * 6 + 8 + 8 + 128 + 512;
>     ULONGEST sp;
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int i;
>   
>     for (i = 3; i <= 12; i++)
> @@ -2036,7 +2036,7 @@ static void
>   ppc_linux_init_abi (struct gdbarch_info info,
>   		    struct gdbarch *gdbarch)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     struct tdesc_arch_data *tdesc_data = info.tdesc_data;
>     static const char *const stap_integer_prefixes[] = { "i", NULL };
>     static const char *const stap_register_indirection_prefixes[] = { "(",
> diff --git a/gdb/ppc-netbsd-nat.c b/gdb/ppc-netbsd-nat.c
> index fb2dce501a4..91f18fbb83f 100644
> --- a/gdb/ppc-netbsd-nat.c
> +++ b/gdb/ppc-netbsd-nat.c
> @@ -52,7 +52,7 @@ static ppc_nbsd_nat_target the_ppc_nbsd_nat_target;
>   static int
>   getregs_supplies (struct gdbarch *gdbarch, int regnum)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     return ((regnum >= tdep->ppc_gp0_regnum
>   	   && regnum < tdep->ppc_gp0_regnum + ppc_num_gprs)
> @@ -68,7 +68,7 @@ getregs_supplies (struct gdbarch *gdbarch, int regnum)
>   static int
>   getfpregs_supplies (struct gdbarch *gdbarch, int regnum)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
>        point registers.  Traditionally, GDB's register set has still
> @@ -159,7 +159,7 @@ ppcnbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
>     struct switchframe sf;
>     struct callframe cf;
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int i;
>   
>     /* The stack pointer shouldn't be zero.  */
> diff --git a/gdb/ppc-netbsd-tdep.c b/gdb/ppc-netbsd-tdep.c
> index cb3d8d5e5df..d8dc494979a 100644
> --- a/gdb/ppc-netbsd-tdep.c
> +++ b/gdb/ppc-netbsd-tdep.c
> @@ -102,7 +102,7 @@ ppcnbsd_sigtramp_cache_init (const struct tramp_frame *self,
>   			     CORE_ADDR func)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     CORE_ADDR addr, base;
>     int i;
>   
> diff --git a/gdb/ppc-obsd-nat.c b/gdb/ppc-obsd-nat.c
> index 93e1024b589..e480f19dc73 100644
> --- a/gdb/ppc-obsd-nat.c
> +++ b/gdb/ppc-obsd-nat.c
> @@ -54,7 +54,7 @@ static ppc_obsd_nat_target the_ppc_obsd_nat_target;
>   static int
>   getfpregs_supplies (struct gdbarch *gdbarch, int regnum)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
>        point registers.  Traditionally, GDB's register set has still
> @@ -154,7 +154,7 @@ static int
>   ppcobsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     struct switchframe sf;
>     struct callframe cf;
>     int i, regnum;
> diff --git a/gdb/ppc-obsd-tdep.c b/gdb/ppc-obsd-tdep.c
> index a2924e35bbc..90fb5e3a399 100644
> --- a/gdb/ppc-obsd-tdep.c
> +++ b/gdb/ppc-obsd-tdep.c
> @@ -161,7 +161,7 @@ static struct trad_frame_cache *
>   ppcobsd_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     struct trad_frame_cache *cache;
>     CORE_ADDR addr, base, func;
> diff --git a/gdb/ppc-sysv-tdep.c b/gdb/ppc-sysv-tdep.c
> index 6c2fd1bfc99..ed6c2d4449d 100644
> --- a/gdb/ppc-sysv-tdep.c
> +++ b/gdb/ppc-sysv-tdep.c
> @@ -65,7 +65,7 @@ ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>   			      function_call_return_method return_method,
>   			      CORE_ADDR struct_addr)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     int opencl_abi = ppc_sysv_use_opencl_abi (value_type (function));
>     ULONGEST saved_sp;
> @@ -597,7 +597,7 @@ get_decimal_float_return_value (struct gdbarch *gdbarch, struct type *valtype,
>   				struct regcache *regcache, gdb_byte *readbuf,
>   				const gdb_byte *writebuf)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     gdb_assert (valtype->code () == TYPE_CODE_DECFLOAT);
>   
> @@ -675,7 +675,7 @@ do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *func_type,
>   			  gdb_byte *readbuf, const gdb_byte *writebuf,
>   			  int broken_gcc)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     int opencl_abi = func_type? ppc_sysv_use_opencl_abi (func_type) : 0;
>   
> @@ -1250,7 +1250,7 @@ ppc64_sysv_abi_push_val (struct gdbarch *gdbarch,
>   			 const bfd_byte *val, int len, int align,
>   			 struct ppc64_sysv_argpos *argpos)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int offset = 0;
>   
>     /* Enforce alignment of stack location, if requested.  */
> @@ -1300,7 +1300,7 @@ static void
>   ppc64_sysv_abi_push_integer (struct gdbarch *gdbarch, ULONGEST val,
>   			     struct ppc64_sysv_argpos *argpos)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     gdb_byte buf[PPC_MAX_REGISTER_SIZE];
>   
> @@ -1318,7 +1318,7 @@ ppc64_sysv_abi_push_freg (struct gdbarch *gdbarch,
>   			  struct type *type, const bfd_byte *val,
>   			  struct ppc64_sysv_argpos *argpos)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     if (tdep->soft_float)
>       return;
>   
> @@ -1403,7 +1403,7 @@ static void
>   ppc64_sysv_abi_push_vreg (struct gdbarch *gdbarch, const bfd_byte *val,
>   			  struct ppc64_sysv_argpos *argpos)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (argpos->regcache && argpos->vreg <= 13)
>       argpos->regcache->cooked_write (tdep->ppc_vr0_regnum + argpos->vreg, val);
> @@ -1419,7 +1419,7 @@ ppc64_sysv_abi_push_param (struct gdbarch *gdbarch,
>   			   struct type *type, const bfd_byte *val,
>   			   struct ppc64_sysv_argpos *argpos)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (type->code () == TYPE_CODE_FLT
>         || type->code () == TYPE_CODE_DECFLOAT)
> @@ -1545,7 +1545,7 @@ ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch,
>   				CORE_ADDR struct_addr)
>   {
>     CORE_ADDR func_addr = find_function_addr (function, NULL);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     int opencl_abi = ppc_sysv_use_opencl_abi (value_type (function));
>     ULONGEST back_chain;
> @@ -1739,7 +1739,7 @@ ppc64_sysv_abi_return_value_base (struct gdbarch *gdbarch, struct type *valtype,
>   				  struct regcache *regcache, gdb_byte *readbuf,
>   				  const gdb_byte *writebuf, int index)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     /* Integers live in GPRs starting at r3.  */
>     if ((valtype->code () == TYPE_CODE_INT
> @@ -1922,7 +1922,7 @@ ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct value *function,
>   			     struct type *valtype, struct regcache *regcache,
>   			     gdb_byte *readbuf, const gdb_byte *writebuf)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     struct type *func_type = function ? value_type (function) : NULL;
>     int opencl_abi = func_type? ppc_sysv_use_opencl_abi (func_type) : 0;
>     struct type *eltype;
> diff --git a/gdb/ppc64-tdep.c b/gdb/ppc64-tdep.c
> index 32931f72691..0437ca7e3f3 100644
> --- a/gdb/ppc64-tdep.c
> +++ b/gdb/ppc64-tdep.c
> @@ -89,7 +89,7 @@ ppc64_plt_entry_point (struct frame_info *frame, CORE_ADDR plt_off)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (frame);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     CORE_ADDR tocp;
>   
>     if (execution_direction == EXEC_REVERSE)
> diff --git a/gdb/riscv-linux-tdep.c b/gdb/riscv-linux-tdep.c
> index 387b8bdbc2f..5bda2e5c824 100644
> --- a/gdb/riscv-linux-tdep.c
> +++ b/gdb/riscv-linux-tdep.c
> @@ -179,7 +179,7 @@ riscv_linux_syscall_next_pc (struct frame_info *frame)
>   static void
>   riscv_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
>   
>     linux_init_abi (info, gdbarch, 0);
>   
> diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
> index 69f2123dcdb..2d41be96b20 100644
> --- a/gdb/riscv-tdep.c
> +++ b/gdb/riscv-tdep.c
> @@ -733,7 +733,7 @@ show_riscv_debug_variable (struct ui_file *file, int from_tty,
>   int
>   riscv_isa_xlen (struct gdbarch *gdbarch)
>   {
> -  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
>     return tdep->isa_features.xlen;
>   }
>   
> @@ -742,7 +742,7 @@ riscv_isa_xlen (struct gdbarch *gdbarch)
>   int
>   riscv_abi_xlen (struct gdbarch *gdbarch)
>   {
> -  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
>     return tdep->abi_features.xlen;
>   }
>   
> @@ -751,7 +751,7 @@ riscv_abi_xlen (struct gdbarch *gdbarch)
>   int
>   riscv_isa_flen (struct gdbarch *gdbarch)
>   {
> -  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
>     return tdep->isa_features.flen;
>   }
>   
> @@ -760,7 +760,7 @@ riscv_isa_flen (struct gdbarch *gdbarch)
>   int
>   riscv_abi_flen (struct gdbarch *gdbarch)
>   {
> -  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
>     return tdep->abi_features.flen;
>   }
>   
> @@ -769,7 +769,7 @@ riscv_abi_flen (struct gdbarch *gdbarch)
>   bool
>   riscv_abi_embedded (struct gdbarch *gdbarch)
>   {
> -  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
>     return tdep->abi_features.embedded;
>   }
>   
> @@ -786,7 +786,7 @@ riscv_has_fp_regs (struct gdbarch *gdbarch)
>   static bool
>   riscv_has_fp_abi (struct gdbarch *gdbarch)
>   {
> -  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
>     return tdep->abi_features.flen > 0;
>   }
>   
> @@ -910,7 +910,7 @@ riscv_register_name (struct gdbarch *gdbarch, int regnum)
>        will show up in 'info register all'.  Unless, we identify the
>        duplicate copies of these registers (in riscv_tdesc_unknown_reg) and
>        then hide the registers here by giving them no name.  */
> -  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
>     if (tdep->duplicate_fflags_regnum == regnum)
>       return NULL;
>     if (tdep->duplicate_frm_regnum == regnum)
> @@ -938,7 +938,7 @@ riscv_register_name (struct gdbarch *gdbarch, int regnum)
>   static struct type *
>   riscv_fpreg_d_type (struct gdbarch *gdbarch)
>   {
> -  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->riscv_fpreg_d_type == nullptr)
>       {
> @@ -1260,7 +1260,7 @@ riscv_is_regnum_a_named_csr (int regnum)
>   static bool
>   riscv_is_unknown_csr (struct gdbarch *gdbarch, int regnum)
>   {
> -  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
>     return (regnum >= tdep->unknown_csrs_first_regnum
>   	  && regnum < (tdep->unknown_csrs_first_regnum
>   		       + tdep->unknown_csrs_count));
> @@ -3600,7 +3600,7 @@ riscv_tdesc_unknown_reg (struct gdbarch *gdbarch, tdesc_feature *feature,
>        record their register numbers here.  */
>     if (strcmp (tdesc_feature_name (feature), riscv_freg_feature.name ()) == 0)
>       {
> -      riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
>         int *regnum_ptr = nullptr;
>   
>         if (strcmp (reg_name, "fflags") == 0)
> @@ -3631,7 +3631,7 @@ riscv_tdesc_unknown_reg (struct gdbarch *gdbarch, tdesc_feature *feature,
>        about register groups in riscv_register_reggroup_p.  */
>     if (strcmp (tdesc_feature_name (feature), riscv_csr_feature.name ()) == 0)
>       {
> -      riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
>         if (tdep->unknown_csrs_first_regnum == -1)
>   	tdep->unknown_csrs_first_regnum = possible_regnum;
>         gdb_assert (tdep->unknown_csrs_first_regnum
> @@ -3733,7 +3733,7 @@ riscv_gdbarch_init (struct gdbarch_info info,
>   	 we are looking for.  If it doesn't then we can't reuse this
>   	 gdbarch.  */
>         riscv_gdbarch_tdep *other_tdep
> -	= (riscv_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<riscv_gdbarch_tdep> (arches->gdbarch);
>   
>         if (other_tdep->isa_features != features
>   	  || other_tdep->abi_features != abi_features)
> @@ -3858,7 +3858,7 @@ riscv_next_pc (struct regcache *regcache, CORE_ADDR pc)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
>     const riscv_gdbarch_tdep *tdep
> -    = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +    = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
>     struct riscv_insn insn;
>     CORE_ADDR next_pc;
>   
> diff --git a/gdb/rl78-tdep.c b/gdb/rl78-tdep.c
> index 6ea0473081d..2462e7a191d 100644
> --- a/gdb/rl78-tdep.c
> +++ b/gdb/rl78-tdep.c
> @@ -267,7 +267,7 @@ struct rl78_prologue
>   static struct type *
>   rl78_psw_type (struct gdbarch *gdbarch)
>   {
> -  rl78_gdbarch_tdep *tdep = (rl78_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  rl78_gdbarch_tdep *tdep = gdbarch_tdep<rl78_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->rl78_psw_type == NULL)
>       {
> @@ -291,7 +291,7 @@ rl78_psw_type (struct gdbarch *gdbarch)
>   static struct type *
>   rl78_register_type (struct gdbarch *gdbarch, int reg_nr)
>   {
> -  rl78_gdbarch_tdep *tdep = (rl78_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  rl78_gdbarch_tdep *tdep = gdbarch_tdep<rl78_gdbarch_tdep> (gdbarch);
>   
>     if (reg_nr == RL78_PC_REGNUM)
>       return tdep->rl78_code_pointer;
> @@ -1248,7 +1248,7 @@ rl78_return_value (struct gdbarch *gdbarch,
>   {
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     ULONGEST valtype_len = TYPE_LENGTH (valtype);
> -  rl78_gdbarch_tdep *tdep = (rl78_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  rl78_gdbarch_tdep *tdep = gdbarch_tdep<rl78_gdbarch_tdep> (gdbarch);
>     int is_g10 = tdep->elf_flags & E_FLAG_RL78_G10;
>   
>     if (valtype_len > 8)
> @@ -1394,7 +1394,7 @@ rl78_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          arches = gdbarch_list_lookup_by_info (arches->next, &info))
>       {
>         rl78_gdbarch_tdep *tdep
> -	= (rl78_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<rl78_gdbarch_tdep> (arches->gdbarch);
>   
>         if (tdep->elf_flags != elf_flags)
>   	continue;
> diff --git a/gdb/rs6000-aix-nat.c b/gdb/rs6000-aix-nat.c
> index 8563aea313a..8697d27b4ed 100644
> --- a/gdb/rs6000-aix-nat.c
> +++ b/gdb/rs6000-aix-nat.c
> @@ -115,7 +115,7 @@ static rs6000_nat_target the_rs6000_nat_target;
>   static int
>   regmap (struct gdbarch *gdbarch, int regno, int *isfloat)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     *isfloat = 0;
>     if (tdep->ppc_gp0_regnum <= regno
> @@ -317,7 +317,7 @@ rs6000_nat_target::fetch_registers (struct regcache *regcache, int regno)
>   
>     else
>       {
> -      ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>         /* Read 32 general purpose registers.  */
>         for (regno = tdep->ppc_gp0_regnum;
> @@ -359,7 +359,7 @@ rs6000_nat_target::store_registers (struct regcache *regcache, int regno)
>   
>     else
>       {
> -      ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>         /* Write general purpose registers first.  */
>         for (regno = tdep->ppc_gp0_regnum;
> diff --git a/gdb/rs6000-aix-tdep.c b/gdb/rs6000-aix-tdep.c
> index 867f21dc634..41384993c26 100644
> --- a/gdb/rs6000-aix-tdep.c
> +++ b/gdb/rs6000-aix-tdep.c
> @@ -75,7 +75,7 @@ aix_sighandle_frame_cache (struct frame_info *this_frame,
>     LONGEST backchain;
>     CORE_ADDR base, base_orig, func;
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     struct trad_frame_cache *this_trad_cache;
>   
> @@ -261,7 +261,7 @@ rs6000_aix_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   					 void *cb_data,
>   					 const struct regcache *regcache)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     if (tdep->wordsize == 4)
>       cb (".reg", 592, 592, &rs6000_aix32_regset, NULL, cb_data);
>     else
> @@ -292,7 +292,7 @@ rs6000_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>   			function_call_return_method return_method,
>   			CORE_ADDR struct_addr)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     int ii;
>     int len = 0;
> @@ -522,7 +522,7 @@ rs6000_return_value (struct gdbarch *gdbarch, struct value *function,
>   		     struct type *valtype, struct regcache *regcache,
>   		     gdb_byte *readbuf, const gdb_byte *writebuf)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>   
>     /* The calling convention this function implements assumes the
> @@ -660,7 +660,7 @@ rs6000_convert_from_func_ptr_addr (struct gdbarch *gdbarch,
>   				   CORE_ADDR addr,
>   				   struct target_ops *targ)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     struct obj_section *s;
>   
> @@ -704,7 +704,7 @@ branch_dest (struct regcache *regcache, int opcode, int instr,
>   	     CORE_ADDR pc, CORE_ADDR safety)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     CORE_ADDR dest;
>     int immediate;
> @@ -972,7 +972,7 @@ static struct ld_info
>   rs6000_aix_extract_ld_info (struct gdbarch *gdbarch,
>   			    const gdb_byte *ldi_buf)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
>     const struct ld_info_desc desc
> @@ -1131,7 +1131,7 @@ rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch,
>   static void
>   rs6000_aix_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     /* RS6000/AIX does not support PT_STEP.  Has to be simulated.  */
>     set_gdbarch_software_single_step (gdbarch, rs6000_software_single_step);
> diff --git a/gdb/rs6000-lynx178-tdep.c b/gdb/rs6000-lynx178-tdep.c
> index 844d0a4ede2..dc13dd3fa73 100644
> --- a/gdb/rs6000-lynx178-tdep.c
> +++ b/gdb/rs6000-lynx178-tdep.c
> @@ -36,7 +36,7 @@ rs6000_lynx178_push_dummy_call (struct gdbarch *gdbarch,
>   				function_call_return_method return_method,
>   				CORE_ADDR struct_addr)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     int ii;
>     int len = 0;
> @@ -265,7 +265,7 @@ rs6000_lynx178_return_value (struct gdbarch *gdbarch, struct value *function,
>   			     struct type *valtype, struct regcache *regcache,
>   			     gdb_byte *readbuf, const gdb_byte *writebuf)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>   
>     /* The calling convention this function implements assumes the
> diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
> index 6815dfaa820..640459f1c28 100644
> --- a/gdb/rs6000-tdep.c
> +++ b/gdb/rs6000-tdep.c
> @@ -201,7 +201,7 @@ struct rs6000_framedata
>   int
>   vsx_register_p (struct gdbarch *gdbarch, int regno)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     if (tdep->ppc_vsr0_regnum < 0)
>       return 0;
>     else
> @@ -213,7 +213,7 @@ vsx_register_p (struct gdbarch *gdbarch, int regno)
>   int
>   altivec_register_p (struct gdbarch *gdbarch, int regno)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     if (tdep->ppc_vr0_regnum < 0 || tdep->ppc_vrsave_regnum < 0)
>       return 0;
>     else
> @@ -225,7 +225,7 @@ altivec_register_p (struct gdbarch *gdbarch, int regno)
>   int
>   spe_register_p (struct gdbarch *gdbarch, int regno)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     
>     /* Is it a reference to EV0 -- EV31, and do we have those?  */
>     if (IS_SPE_PSEUDOREG (tdep, regno))
> @@ -257,7 +257,7 @@ spe_register_p (struct gdbarch *gdbarch, int regno)
>   int
>   ppc_floating_point_unit_p (struct gdbarch *gdbarch)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     return (tdep->ppc_fp0_regnum >= 0
>   	  && tdep->ppc_fpscr_regnum >= 0);
> @@ -268,7 +268,7 @@ ppc_floating_point_unit_p (struct gdbarch *gdbarch)
>   int
>   ppc_altivec_support_p (struct gdbarch *gdbarch)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     return (tdep->ppc_vr0_regnum >= 0
>   	  && tdep->ppc_vrsave_regnum >= 0);
> @@ -297,7 +297,7 @@ set_sim_regno (int *table, int gdb_regno, int sim_regno)
>   static void
>   init_sim_regno_table (struct gdbarch *arch)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (arch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (arch);
>     int total_regs = gdbarch_num_regs (arch);
>     int *sim_regno = GDBARCH_OBSTACK_CALLOC (arch, total_regs, int);
>     int i;
> @@ -391,7 +391,7 @@ init_sim_regno_table (struct gdbarch *arch)
>   static int
>   rs6000_register_sim_regno (struct gdbarch *gdbarch, int reg)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int sim_regno;
>   
>     if (tdep->sim_regno == NULL)
> @@ -522,7 +522,7 @@ ppc_supply_gregset (const struct regset *regset, struct regcache *regcache,
>   		    int regnum, const void *gregs, size_t len)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     const struct ppc_reg_offsets *offsets
>       = (const struct ppc_reg_offsets *) regset->regmap;
>     size_t offset;
> @@ -578,7 +578,7 @@ ppc_supply_fpregset (const struct regset *regset, struct regcache *regcache,
>     if (!ppc_floating_point_unit_p (gdbarch))
>       return;
>   
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     offsets = (const struct ppc_reg_offsets *) regset->regmap;
>     if (regnum == -1)
>       {
> @@ -611,7 +611,7 @@ ppc_collect_gregset (const struct regset *regset,
>   		     int regnum, void *gregs, size_t len)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     const struct ppc_reg_offsets *offsets
>       = (const struct ppc_reg_offsets *) regset->regmap;
>     size_t offset;
> @@ -668,7 +668,7 @@ ppc_collect_fpregset (const struct regset *regset,
>     if (!ppc_floating_point_unit_p (gdbarch))
>       return;
>   
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     offsets = (const struct ppc_reg_offsets *) regset->regmap;
>     if (regnum == -1)
>       {
> @@ -746,7 +746,7 @@ static int
>   rs6000_in_function_epilogue_frame_p (struct frame_info *curfrm,
>   				     struct gdbarch *gdbarch, CORE_ADDR pc)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     bfd_byte insn_buf[PPC_INSN_SIZE];
>     CORE_ADDR scan_pc, func_start, func_end, epilogue_start, epilogue_end;
> @@ -1042,7 +1042,7 @@ ppc_displaced_step_fixup (struct gdbarch *gdbarch,
>         if (insn & 0x1)
>   	{
>   	  /* Link register needs to be set to the next instruction's PC.  */
> -	  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +	  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   	  regcache_cooked_write_unsigned (regs,
>   					  tdep->ppc_lr_regnum,
>   					  from + PPC_INSN_SIZE);
> @@ -1590,7 +1590,7 @@ skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc, CORE_ADDR lim_pc,
>     int num_skip_non_prologue_insns = 0;
>     int r0_contains_arg = 0;
>     const struct bfd_arch_info *arch_info = gdbarch_bfd_arch_info (gdbarch);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>   
>     memset (fdata, 0, sizeof (struct rs6000_framedata));
> @@ -2310,7 +2310,7 @@ static CORE_ADDR
>   rs6000_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (frame);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     unsigned int ii, op;
>     int rel;
> @@ -2368,7 +2368,7 @@ rs6000_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
>   static struct type *
>   rs6000_builtin_type_vec64 (struct gdbarch *gdbarch)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->ppc_builtin_type_vec64)
>       {
> @@ -2413,7 +2413,7 @@ rs6000_builtin_type_vec64 (struct gdbarch *gdbarch)
>   static struct type *
>   rs6000_builtin_type_vec128 (struct gdbarch *gdbarch)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->ppc_builtin_type_vec128)
>       {
> @@ -2467,7 +2467,7 @@ rs6000_builtin_type_vec128 (struct gdbarch *gdbarch)
>   static const char *
>   rs6000_register_name (struct gdbarch *gdbarch, int regno)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     /* The upper half "registers" have names in the XML description,
>        but we present only the low GPRs and the full 64-bit registers
> @@ -2605,7 +2605,7 @@ rs6000_register_name (struct gdbarch *gdbarch, int regno)
>   static struct type *
>   rs6000_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     /* These are the e500 pseudo-registers.  */
>     if (IS_SPE_PSEUDOREG (tdep, regnum))
> @@ -2644,7 +2644,7 @@ static int
>   rs6000_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
>   				   const struct reggroup *group)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (IS_V_ALIAS_PSEUDOREG (tdep, regnum))
>       return 0;
> @@ -2659,7 +2659,7 @@ static int
>   rs6000_convert_register_p (struct gdbarch *gdbarch, int regnum,
>   			   struct type *type)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     return (tdep->ppc_fp0_regnum >= 0
>   	  && regnum >= tdep->ppc_fp0_regnum
> @@ -2744,7 +2744,7 @@ e500_move_ev_register (move_ev_register_func move,
>   		       struct regcache *regcache, int ev_reg, void *buffer)
>   {
>     struct gdbarch *arch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (arch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (arch);
>     int reg_index;
>     gdb_byte *byte_buffer = (gdb_byte *) buffer;
>     enum register_status status;
> @@ -2785,7 +2785,7 @@ e500_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
>   			   int ev_reg, gdb_byte *buffer)
>   {
>     struct gdbarch *arch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int reg_index;
>     enum register_status status;
>   
> @@ -2826,7 +2826,7 @@ static enum register_status
>   dfp_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
>   			   int reg_nr, gdb_byte *buffer)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int reg_index, fp0;
>     enum register_status status;
>   
> @@ -2866,7 +2866,7 @@ static void
>   dfp_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
>   			    int reg_nr, const gdb_byte *buffer)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int reg_index, fp0;
>   
>     if (IS_DFP_PSEUDOREG (tdep, reg_nr))
> @@ -2903,7 +2903,7 @@ v_alias_pseudo_register_read (struct gdbarch *gdbarch,
>   			      readable_regcache *regcache, int reg_nr,
>   			      gdb_byte *buffer)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     gdb_assert (IS_V_ALIAS_PSEUDOREG (tdep, reg_nr));
>   
>     return regcache->raw_read (tdep->ppc_vr0_regnum
> @@ -2918,7 +2918,7 @@ v_alias_pseudo_register_write (struct gdbarch *gdbarch,
>   			       struct regcache *regcache,
>   			       int reg_nr, const gdb_byte *buffer)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     gdb_assert (IS_V_ALIAS_PSEUDOREG (tdep, reg_nr));
>   
>     regcache->raw_write (tdep->ppc_vr0_regnum
> @@ -2930,7 +2930,7 @@ static enum register_status
>   vsx_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
>   			   int reg_nr, gdb_byte *buffer)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int reg_index, vr0, fp0, vsr0_upper;
>     enum register_status status;
>   
> @@ -2978,7 +2978,7 @@ static void
>   vsx_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
>   			    int reg_nr, const gdb_byte *buffer)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int reg_index, vr0, fp0, vsr0_upper;
>   
>     if (IS_VSX_PSEUDOREG (tdep, reg_nr))
> @@ -3020,7 +3020,7 @@ static enum register_status
>   efp_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
>   			   int reg_nr, gdb_byte *buffer)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int reg_index, vr0;
>   
>     if (IS_EFP_PSEUDOREG (tdep, reg_nr))
> @@ -3049,7 +3049,7 @@ static void
>   efp_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
>   			    int reg_nr, const gdb_byte *buffer)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int reg_index, vr0;
>     int offset = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG ? 0 : 8;
>   
> @@ -3085,7 +3085,7 @@ rs6000_pseudo_register_read (struct gdbarch *gdbarch,
>   			     int reg_nr, gdb_byte *buffer)
>   {
>     struct gdbarch *regcache_arch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     gdb_assert (regcache_arch == gdbarch);
>   
> @@ -3116,7 +3116,7 @@ rs6000_pseudo_register_write (struct gdbarch *gdbarch,
>   			      int reg_nr, const gdb_byte *buffer)
>   {
>     struct gdbarch *regcache_arch = regcache->arch ();
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     gdb_assert (regcache_arch == gdbarch);
>   
> @@ -3147,7 +3147,7 @@ static void
>   dfp_ax_pseudo_register_collect (struct gdbarch *gdbarch,
>   				struct agent_expr *ax, int reg_nr)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int reg_index, fp0;
>   
>     if (IS_DFP_PSEUDOREG (tdep, reg_nr))
> @@ -3174,7 +3174,7 @@ static void
>   v_alias_pseudo_register_collect (struct gdbarch *gdbarch,
>   				 struct agent_expr *ax, int reg_nr)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     gdb_assert (IS_V_ALIAS_PSEUDOREG (tdep, reg_nr));
>   
>     ax_reg_mask (ax, tdep->ppc_vr0_regnum
> @@ -3188,7 +3188,7 @@ static void
>   vsx_ax_pseudo_register_collect (struct gdbarch *gdbarch,
>   				struct agent_expr *ax, int reg_nr)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int reg_index, vr0, fp0, vsr0_upper;
>   
>     if (IS_VSX_PSEUDOREG (tdep, reg_nr))
> @@ -3226,7 +3226,7 @@ static void
>   efp_ax_pseudo_register_collect (struct gdbarch *gdbarch,
>   				struct agent_expr *ax, int reg_nr)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int reg_index, vr0;
>   
>     if (IS_EFP_PSEUDOREG (tdep, reg_nr))
> @@ -3249,7 +3249,7 @@ static int
>   rs6000_ax_pseudo_register_collect (struct gdbarch *gdbarch,
>   				   struct agent_expr *ax, int reg_nr)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     if (IS_SPE_PSEUDOREG (tdep, reg_nr))
>       {
>         int reg_index = reg_nr - tdep->ppc_ev0_regnum;
> @@ -3289,7 +3289,7 @@ rs6000_gen_return_address (struct gdbarch *gdbarch,
>   			   struct agent_expr *ax, struct axs_value *value,
>   			   CORE_ADDR scope)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     value->type = register_type (gdbarch, tdep->ppc_lr_regnum);
>     value->kind = axs_lvalue_register;
>     value->u.reg = tdep->ppc_lr_regnum;
> @@ -3300,7 +3300,7 @@ rs6000_gen_return_address (struct gdbarch *gdbarch,
>   static int
>   rs6000_stab_reg_to_regnum (struct gdbarch *gdbarch, int num)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (0 <= num && num <= 31)
>       return tdep->ppc_gp0_regnum + num;
> @@ -3342,7 +3342,7 @@ rs6000_stab_reg_to_regnum (struct gdbarch *gdbarch, int num)
>   static int
>   rs6000_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int num)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (0 <= num && num <= 31)
>       return tdep->ppc_gp0_regnum + num;
> @@ -3561,7 +3561,7 @@ rs6000_frame_cache (struct frame_info *this_frame, void **this_cache)
>   {
>     struct rs6000_frame_cache *cache;
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     struct rs6000_framedata fdata;
>     int wordsize = tdep->wordsize;
> @@ -3797,7 +3797,7 @@ rs6000_epilogue_frame_cache (struct frame_info *this_frame, void **this_cache)
>   {
>     struct rs6000_frame_cache *cache;
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (*this_cache)
>       return (struct rs6000_frame_cache *) *this_cache;
> @@ -3918,7 +3918,7 @@ ppc_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
>   			    struct dwarf2_frame_state_reg *reg,
>   			    struct frame_info *this_frame)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     /* PPC32 and PPC64 ABI's are the same regarding volatile and
>        non-volatile registers.  We will use the same code for both.  */
> @@ -4229,7 +4229,7 @@ static int
>   ppc_process_record_op4 (struct gdbarch *gdbarch, struct regcache *regcache,
>   			CORE_ADDR addr, uint32_t insn)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int ext = PPC_FIELD (insn, 21, 11);
>     int vra = PPC_FIELD (insn, 11, 5);
>   
> @@ -4771,7 +4771,7 @@ static int
>   ppc_process_record_op6 (struct gdbarch *gdbarch, struct regcache *regcache,
>   			CORE_ADDR addr, uint32_t insn)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int subtype = PPC_FIELD (insn, 28, 4);
>     CORE_ADDR ea = 0;
>   
> @@ -4799,7 +4799,7 @@ static int
>   ppc_process_record_op19 (struct gdbarch *gdbarch, struct regcache *regcache,
>   			   CORE_ADDR addr, uint32_t insn)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int ext = PPC_EXTOP (insn);
>   
>     switch (ext & 0x01f)
> @@ -4855,7 +4855,7 @@ ppc_process_record_op31_177 (struct gdbarch *gdbarch,
>   {
>     int RA_opcode = PPC_RA(insn);
>     int as = PPC_FIELD (insn, 6, 3);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     switch (RA_opcode)
>       {
> @@ -4875,7 +4875,7 @@ static int
>   ppc_process_record_op31 (struct gdbarch *gdbarch, struct regcache *regcache,
>   			   CORE_ADDR addr, uint32_t insn)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int ext = PPC_EXTOP (insn);
>     int tmp, nr, nb = 0, i;
>     CORE_ADDR at_dcsz, ea = 0;
> @@ -5536,7 +5536,7 @@ static int
>   ppc_process_record_op59 (struct gdbarch *gdbarch, struct regcache *regcache,
>   			 CORE_ADDR addr, uint32_t insn)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int ext = PPC_EXTOP (insn);
>     int at = PPC_FIELD (insn, 6, 3);
>   
> @@ -5701,7 +5701,7 @@ ppc_process_record_op60_XX2 (struct gdbarch *gdbarch,
>   			     struct regcache *regcache,
>   			     CORE_ADDR addr, uint32_t insn)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int RA_opcode = PPC_RA(insn);
>   
>     switch (RA_opcode)
> @@ -5742,7 +5742,7 @@ static int
>   ppc_process_record_op60 (struct gdbarch *gdbarch, struct regcache *regcache,
>   			   CORE_ADDR addr, uint32_t insn)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int ext = PPC_EXTOP (insn);
>   
>     switch (ext >> 2)
> @@ -6097,7 +6097,7 @@ static int
>   ppc_process_record_op61 (struct gdbarch *gdbarch, struct regcache *regcache,
>   			   CORE_ADDR addr, uint32_t insn)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     ULONGEST ea = 0;
>     int size;
>   
> @@ -6156,7 +6156,7 @@ static int
>   ppc_process_record_op63 (struct gdbarch *gdbarch, struct regcache *regcache,
>   			   CORE_ADDR addr, uint32_t insn)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int ext = PPC_EXTOP (insn);
>     int tmp;
>   
> @@ -6453,7 +6453,7 @@ ppc_process_record_prefix_op42 (struct gdbarch *gdbarch,
>   				struct regcache *regcache,
>   				uint32_t insn_prefix, uint32_t insn_suffix)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int type = PPC_FIELD (insn_prefix, 6, 2);
>     int ST1 = PPC_FIELD (insn_prefix, 8, 1);
>   
> @@ -6489,7 +6489,7 @@ ppc_process_record_prefix_op59_XX3 (struct gdbarch *gdbarch,
>     int type = PPC_FIELD (insn_prefix, 6, 2);
>     int ST4 = PPC_FIELD (insn_prefix, 8, 4);
>     int at = PPC_FIELD (insn_suffix, 6, 3);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (type == 3)
>       {
> @@ -6603,7 +6603,7 @@ ppc_process_record_prefix_store (struct gdbarch *gdbarch,
>   				 CORE_ADDR addr, uint32_t insn_prefix,
>   				 uint32_t insn_suffix)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     ULONGEST iaddr = 0;
>     int size;
>     int R = PPC_BIT (insn_prefix, 11);
> @@ -6659,7 +6659,7 @@ ppc_process_record_prefix_op32 (struct gdbarch *gdbarch,
>     int type = PPC_FIELD (insn_prefix, 6, 2);
>     int ST1 = PPC_FIELD (insn_prefix, 8, 1);
>     int ST4 = PPC_FIELD (insn_prefix, 8, 4);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (type == 1)
>       {
> @@ -6713,7 +6713,7 @@ ppc_process_record_prefix_op33 (struct gdbarch *gdbarch,
>   {
>     int type = PPC_FIELD (insn_prefix, 6, 2);
>     int ST4 = PPC_FIELD (insn_prefix, 8, 4);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (type == 1)
>       {
> @@ -6751,7 +6751,7 @@ ppc_process_record_prefix_op34 (struct gdbarch *gdbarch,
>     int type = PPC_FIELD (insn_prefix, 6, 2);
>     int ST1 = PPC_FIELD (insn_prefix, 8, 1);
>     int ST4 = PPC_FIELD (insn_prefix, 8, 4);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (type == 1)
>       {
> @@ -6797,7 +6797,7 @@ ppc_process_record_prefix_store_vsx_ds_form (struct gdbarch *gdbarch,
>   					     uint32_t insn_prefix,
>   					     uint32_t insn_suffix)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     ULONGEST ea = 0;
>     int size;
>     int R = PPC_BIT (insn_prefix, 11);
> @@ -6850,7 +6850,7 @@ ppc_process_record_prefix_vsx_d_form (struct gdbarch *gdbarch,
>   				      uint32_t insn_prefix,
>   				      uint32_t insn_suffix)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     ULONGEST ea = 0;
>     int size;
>     int R = PPC_BIT (insn_prefix, 11);
> @@ -6907,7 +6907,7 @@ ppc_process_prefix_instruction (int insn_prefix, int insn_suffix,
>   {
>     int type = PPC_FIELD (insn_prefix, 6, 2);
>     int ST1 = PPC_FIELD (insn_prefix, 8, 1);
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     int op6;
>   
>     /* D-form has uses a 5-bit opcode in the instruction suffix */
> @@ -7086,7 +7086,7 @@ int
>   ppc_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
>   		      CORE_ADDR addr)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     uint32_t insn, insn_suffix;
>     int op6, tmp, i;
> @@ -8150,7 +8150,7 @@ rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>   	 meaningful, because 64-bit CPUs can run in 32-bit mode.  So, perform
>   	 separate word size check.  */
>         ppc_gdbarch_tdep *tdep
> -	= (ppc_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<ppc_gdbarch_tdep> (arches->gdbarch);
>         if (tdep && tdep->elf_abi != elf_abi)
>   	continue;
>         if (tdep && tdep->soft_float != soft_float)
> @@ -8452,7 +8452,7 @@ rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>   static void
>   rs6000_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
>   {
> -  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
>   
>     if (tdep == NULL)
>       return;
> diff --git a/gdb/rx-tdep.c b/gdb/rx-tdep.c
> index 2a24ebba2b6..c67d4057195 100644
> --- a/gdb/rx-tdep.c
> +++ b/gdb/rx-tdep.c
> @@ -964,7 +964,7 @@ rx_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          arches = gdbarch_list_lookup_by_info (arches->next, &info))
>       {
>         rx_gdbarch_tdep *tdep
> -	= (rx_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<rx_gdbarch_tdep> (arches->gdbarch);
>   
>         if (tdep->elf_flags != elf_flags)
>   	continue;
> diff --git a/gdb/s390-linux-tdep.c b/gdb/s390-linux-tdep.c
> index 9d4e2d09f2a..03611fe1d23 100644
> --- a/gdb/s390-linux-tdep.c
> +++ b/gdb/s390-linux-tdep.c
> @@ -79,7 +79,7 @@ static void
>   s390_write_pc (struct regcache *regcache, CORE_ADDR pc)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>   
>     regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
>   
> @@ -269,7 +269,7 @@ s390_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   				   void *cb_data,
>   				   const struct regcache *regcache)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     const int gregset_size = (tdep->abi == ABI_LINUX_S390 ?
>   			    s390_sizeof_gregset : s390x_sizeof_gregset);
>   
> @@ -390,7 +390,7 @@ s390_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
>   				  void **this_prologue_cache)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     int word_size = gdbarch_ptr_bit (gdbarch) / 8;
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     struct s390_sigtramp_unwind_cache *info;
> @@ -561,7 +561,7 @@ s390_linux_get_syscall_number (struct gdbarch *gdbarch,
>   			       thread_info *thread)
>   {
>     struct regcache *regs = get_thread_regcache (thread);
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     ULONGEST pc;
>     ULONGEST svc_number = -1;
> @@ -594,7 +594,7 @@ static int
>   s390_all_but_pc_registers_record (struct regcache *regcache)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     int i;
>   
>     for (i = 0; i < 16; i++)
> @@ -802,7 +802,7 @@ static int
>   s390_linux_syscall_record (struct regcache *regcache, LONGEST syscall_native)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     int ret;
>     enum gdb_syscall syscall_gdb;
>   
> @@ -853,7 +853,7 @@ static int
>   s390_linux_record_signal (struct gdbarch *gdbarch, struct regcache *regcache,
>   			  enum gdb_signal signal)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     /* There are two kinds of signal frames on s390. rt_sigframe is always
>        the larger one, so don't even bother with sigframe.  */
>     const int sizeof_rt_sigframe = (tdep->abi == ABI_LINUX_ZSERIES ?
> @@ -1117,7 +1117,7 @@ s390_init_linux_record_tdep (struct linux_record_tdep *record_tdep,
>   static void
>   s390_linux_init_abi_any (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>   
>     tdep->s390_syscall_record = s390_linux_syscall_record;
>   
> @@ -1152,7 +1152,7 @@ s390_linux_init_abi_any (struct gdbarch_info info, struct gdbarch *gdbarch)
>   static void
>   s390_linux_init_abi_31 (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>   
>     tdep->abi = ABI_LINUX_S390;
>   
> @@ -1168,7 +1168,7 @@ s390_linux_init_abi_31 (struct gdbarch_info info, struct gdbarch *gdbarch)
>   static void
>   s390_linux_init_abi_64 (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>   
>     tdep->abi = ABI_LINUX_ZSERIES;
>   
> diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c
> index 14b03a167d7..2aeb3a14637 100644
> --- a/gdb/s390-tdep.c
> +++ b/gdb/s390-tdep.c
> @@ -1045,7 +1045,7 @@ s390_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
>   static int
>   s390_register_call_saved (struct gdbarch *gdbarch, int regnum)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>   
>     switch (tdep->abi)
>       {
> @@ -1076,7 +1076,7 @@ s390_guess_tracepoint_registers (struct gdbarch *gdbarch,
>   				 struct regcache *regcache,
>   				 CORE_ADDR addr)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     int sz = register_size (gdbarch, S390_PSWA_REGNUM);
>     gdb_byte *reg = (gdb_byte *) alloca (sz);
>     ULONGEST pswm, pswa;
> @@ -1172,7 +1172,7 @@ enum { s390_dwarf_reg_r0l = ARRAY_SIZE (s390_dwarf_regmap) - 16 };
>   static int
>   s390_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     int gdb_reg = -1;
>   
>     /* In a 32-on-64 debug scenario, debug info refers to the full
> @@ -1231,7 +1231,7 @@ static struct value *
>   s390_value_from_register (struct gdbarch *gdbarch, struct type *type,
>   			  int regnum, struct frame_id frame_id)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     struct value *value = default_value_from_register (gdbarch, type,
>   						     regnum, frame_id);
>     check_typedef (type);
> @@ -1250,7 +1250,7 @@ s390_value_from_register (struct gdbarch *gdbarch, struct type *type,
>   static const char *
>   s390_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>   
>     if (regnum == tdep->pc_regnum)
>       return "pc";
> @@ -1284,7 +1284,7 @@ s390_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
>   static struct type *
>   s390_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>   
>     if (regnum == tdep->pc_regnum)
>       return builtin_type (gdbarch)->builtin_func_ptr;
> @@ -1308,7 +1308,7 @@ static enum register_status
>   s390_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
>   			   int regnum, gdb_byte *buf)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     int regsize = register_size (gdbarch, regnum);
>     ULONGEST val;
> @@ -1383,7 +1383,7 @@ static void
>   s390_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
>   			    int regnum, const gdb_byte *buf)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     int regsize = register_size (gdbarch, regnum);
>     ULONGEST val, psw;
> @@ -1442,7 +1442,7 @@ static int
>   s390_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
>   				 const struct reggroup *group)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>   
>     /* We usually save/restore the whole PSW, which includes PC and CC.
>        However, some older gdbservers may not support saving/restoring
> @@ -1470,7 +1470,7 @@ static int
>   s390_ax_pseudo_register_collect (struct gdbarch *gdbarch,
>   				 struct agent_expr *ax, int regnum)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     if (regnum == tdep->pc_regnum)
>       {
>         ax_reg_mask (ax, S390_PSWA_REGNUM);
> @@ -1504,7 +1504,7 @@ static int
>   s390_ax_pseudo_register_push_stack (struct gdbarch *gdbarch,
>   				    struct agent_expr *ax, int regnum)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     if (regnum == tdep->pc_regnum)
>       {
>         ax_reg (ax, S390_PSWA_REGNUM);
> @@ -1905,7 +1905,7 @@ s390_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
>   		      function_call_return_method return_method,
>   		      CORE_ADDR struct_addr)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     int word_size = gdbarch_ptr_bit (gdbarch) / 8;
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     int i;
> @@ -2084,7 +2084,7 @@ s390_return_value (struct gdbarch *gdbarch, struct value *function,
>         break;
>       case TYPE_CODE_ARRAY:
>         {
> -	s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +	s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>   	rvc = (tdep->vector_abi == S390_VECTOR_ABI_128
>   	       && TYPE_LENGTH (type) <= 16 && type->is_vector ())
>   	  ? RETURN_VALUE_REGISTER_CONVENTION
> @@ -2168,7 +2168,7 @@ s390_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
>   static CORE_ADDR
>   s390_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     ULONGEST pc;
>     pc = frame_unwind_register_unsigned (next_frame, tdep->pc_regnum);
>     return gdbarch_addr_bits_remove (gdbarch, pc);
> @@ -2190,7 +2190,7 @@ static struct value *
>   s390_unwind_pseudo_register (struct frame_info *this_frame, int regnum)
>   {
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     struct type *type = register_type (gdbarch, regnum);
>   
>     /* Unwind PC via PSW address.  */
> @@ -2775,7 +2775,7 @@ static CORE_ADDR
>   s390_record_address_mask (struct gdbarch *gdbarch, struct regcache *regcache,
>   			  CORE_ADDR val)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     ULONGEST pswm, pswa;
>     int am;
>     if (tdep->abi == ABI_LINUX_S390)
> @@ -2842,7 +2842,7 @@ s390_record_calc_disp_vsce (struct gdbarch *gdbarch, struct regcache *regcache,
>   			    uint8_t vx, uint8_t el, uint8_t es, uint16_t bd,
>   			    int8_t dh, CORE_ADDR *res)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     ULONGEST x;
>     gdb_byte buf[16];
> @@ -2885,7 +2885,7 @@ static int s390_popcnt (unsigned int x) {
>   static int
>   s390_record_gpr_g (struct gdbarch *gdbarch, struct regcache *regcache, int i)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + i))
>       return -1;
>     if (tdep->abi == ABI_LINUX_S390)
> @@ -2899,7 +2899,7 @@ s390_record_gpr_g (struct gdbarch *gdbarch, struct regcache *regcache, int i)
>   static int
>   s390_record_gpr_h (struct gdbarch *gdbarch, struct regcache *regcache, int i)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     if (tdep->abi == ABI_LINUX_S390)
>       {
>         if (record_full_arch_list_add_reg (regcache, S390_R0_UPPER_REGNUM + i))
> @@ -2939,7 +2939,7 @@ static int
>   s390_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
>   		     CORE_ADDR addr)
>   {
> -  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
>     uint16_t insn[3] = {0};
>     /* Instruction as bytes.  */
>     uint8_t ibyte[6];
> @@ -7178,7 +7178,7 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          arches = gdbarch_list_lookup_by_info (arches->next, &info))
>       {
>         s390_gdbarch_tdep *tmp
> -	= (s390_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<s390_gdbarch_tdep> (arches->gdbarch);
>   
>         if (!tmp)
>   	continue;
> diff --git a/gdb/sh-linux-tdep.c b/gdb/sh-linux-tdep.c
> index 2975a8f5d3d..f146f023add 100644
> --- a/gdb/sh-linux-tdep.c
> +++ b/gdb/sh-linux-tdep.c
> @@ -195,7 +195,7 @@ sh_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>     set_gdbarch_fetch_tls_load_module_address (gdbarch,
>   					     svr4_fetch_objfile_link_map);
>   
> -  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
>   
>     /* Remember regset characteristics.  The sizes should match
>        elf_gregset_t and elf_fpregset_t from Linux.  */
> diff --git a/gdb/sh-netbsd-tdep.c b/gdb/sh-netbsd-tdep.c
> index 4fbb53b49ff..49760337c4b 100644
> --- a/gdb/sh-netbsd-tdep.c
> +++ b/gdb/sh-netbsd-tdep.c
> @@ -63,7 +63,7 @@ static void
>   shnbsd_init_abi (struct gdbarch_info info,
>   		  struct gdbarch *gdbarch)
>   {
> -  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
>     nbsd_init_abi (info, gdbarch);
>   
>     tdep->core_gregmap = (struct sh_corefile_regmap *)regmap;
> diff --git a/gdb/sh-tdep.c b/gdb/sh-tdep.c
> index 2341a9beef6..062df860c81 100644
> --- a/gdb/sh-tdep.c
> +++ b/gdb/sh-tdep.c
> @@ -1554,7 +1554,7 @@ sh_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
>   static struct type *
>   sh_littlebyte_bigword_type (struct gdbarch *gdbarch)
>   {
> -  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->sh_littlebyte_bigword_type == NULL)
>       tdep->sh_littlebyte_bigword_type
> @@ -2146,7 +2146,7 @@ sh_corefile_supply_regset (const struct regset *regset,
>   			   int regnum, const void *regs, size_t len)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
>     const struct sh_corefile_regmap *regmap = (regset == &sh_corefile_gregset
>   					     ? tdep->core_gregmap
>   					     : tdep->core_fpregmap);
> @@ -2172,7 +2172,7 @@ sh_corefile_collect_regset (const struct regset *regset,
>   			    int regnum, void *regs, size_t len)
>   {
>     struct gdbarch *gdbarch = regcache->arch ();
> -  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
>     const struct sh_corefile_regmap *regmap = (regset == &sh_corefile_gregset
>   					     ? tdep->core_gregmap
>   					     : tdep->core_fpregmap);
> @@ -2210,7 +2210,7 @@ sh_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   				 void *cb_data,
>   				 const struct regcache *regcache)
>   {
> -  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->core_gregmap != NULL)
>       cb (".reg", tdep->sizeof_gregset, tdep->sizeof_gregset,
> diff --git a/gdb/sparc-linux-tdep.c b/gdb/sparc-linux-tdep.c
> index 18196b2f075..66481ea7b8a 100644
> --- a/gdb/sparc-linux-tdep.c
> +++ b/gdb/sparc-linux-tdep.c
> @@ -254,7 +254,7 @@ static void
>   sparc_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
>   {
>     gdbarch *arch = regcache->arch ();
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
>     ULONGEST psr;
>   
>     regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
> @@ -421,7 +421,7 @@ static const struct regset sparc32_linux_fpregset =
>   static void
>   sparc32_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     linux_init_abi (info, gdbarch, 0);
>   
> diff --git a/gdb/sparc-netbsd-tdep.c b/gdb/sparc-netbsd-tdep.c
> index a97a772dba2..57c178511fa 100644
> --- a/gdb/sparc-netbsd-tdep.c
> +++ b/gdb/sparc-netbsd-tdep.c
> @@ -295,7 +295,7 @@ static const struct regset sparc32nbsd_fpregset =
>   void
>   sparc32nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     nbsd_init_abi (info, gdbarch);
>   
> diff --git a/gdb/sparc-sol2-tdep.c b/gdb/sparc-sol2-tdep.c
> index 28eb6f67601..a92e95ce71b 100644
> --- a/gdb/sparc-sol2-tdep.c
> +++ b/gdb/sparc-sol2-tdep.c
> @@ -196,7 +196,7 @@ static const struct frame_unwind sparc32_sol2_sigtramp_frame_unwind =
>   static void
>   sparc32_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     tdep->gregset = &sparc32_sol2_gregset;
>     tdep->sizeof_gregset = 152;
> diff --git a/gdb/sparc-tdep.c b/gdb/sparc-tdep.c
> index e540263a2fe..397f5489550 100644
> --- a/gdb/sparc-tdep.c
> +++ b/gdb/sparc-tdep.c
> @@ -425,7 +425,7 @@ sparc32_register_name (struct gdbarch *gdbarch, int regnum)
>   static struct type *
>   sparc_psr_type (struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->sparc_psr_type)
>       {
> @@ -447,7 +447,7 @@ sparc_psr_type (struct gdbarch *gdbarch)
>   static struct type *
>   sparc_fsr_type (struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->sparc_fsr_type)
>       {
> @@ -988,7 +988,7 @@ CORE_ADDR
>   sparc_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
>   			CORE_ADDR current_pc, struct sparc_frame_cache *cache)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>     unsigned long insn;
>     int offset = 0;
>     int dest = -1;
> @@ -1680,7 +1680,7 @@ sparc_analyze_control_transfer (struct regcache *regcache,
>   
>         /* Trap instruction (TRAP).  */
>         gdbarch *arch = regcache->arch ();
> -      sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
> +      sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
>         return tdep->step_trap (frame, insn);
>       }
>   
> @@ -1731,7 +1731,7 @@ static std::vector<CORE_ADDR>
>   sparc_software_single_step (struct regcache *regcache)
>   {
>     struct gdbarch *arch = regcache->arch ();
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
>     CORE_ADDR npc, nnpc;
>   
>     CORE_ADDR pc, orig_npc;
> @@ -1761,7 +1761,7 @@ static void
>   sparc_write_pc (struct regcache *regcache, CORE_ADDR pc)
>   {
>     gdbarch *arch = regcache->arch ();
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
>   
>     regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
>     regcache_cooked_write_unsigned (regcache, tdep->npc_regnum, pc + 4);
> @@ -1776,7 +1776,7 @@ sparc_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   				    void *cb_data,
>   				    const struct regcache *regcache)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     cb (".reg", tdep->sizeof_gregset, tdep->sizeof_gregset, tdep->gregset, NULL,
>         cb_data);
> diff --git a/gdb/sparc64-fbsd-tdep.c b/gdb/sparc64-fbsd-tdep.c
> index 8a288282772..76c682fd521 100644
> --- a/gdb/sparc64-fbsd-tdep.c
> +++ b/gdb/sparc64-fbsd-tdep.c
> @@ -222,7 +222,7 @@ static const struct regset sparc64fbsd_fpregset =
>   static void
>   sparc64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     /* Generic FreeBSD support. */
>     fbsd_init_abi (info, gdbarch);
> diff --git a/gdb/sparc64-linux-tdep.c b/gdb/sparc64-linux-tdep.c
> index 9ea72331e93..f5940cfcdee 100644
> --- a/gdb/sparc64-linux-tdep.c
> +++ b/gdb/sparc64-linux-tdep.c
> @@ -262,7 +262,7 @@ static void
>   sparc64_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
>   {
>     gdbarch *arch = regcache->arch ();
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
>     ULONGEST state;
>   
>     regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
> @@ -364,7 +364,7 @@ static const struct regset sparc64_linux_fpregset =
>   static void
>   sparc64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     linux_init_abi (info, gdbarch, 0);
>   
> diff --git a/gdb/sparc64-netbsd-tdep.c b/gdb/sparc64-netbsd-tdep.c
> index 29cd3b6f3ba..db368118f23 100644
> --- a/gdb/sparc64-netbsd-tdep.c
> +++ b/gdb/sparc64-netbsd-tdep.c
> @@ -248,7 +248,7 @@ static const struct regset sparc64nbsd_fpregset =
>   static void
>   sparc64nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     nbsd_init_abi (info, gdbarch);
>   
> diff --git a/gdb/sparc64-obsd-tdep.c b/gdb/sparc64-obsd-tdep.c
> index 05ebbd2e84a..d6470a51b65 100644
> --- a/gdb/sparc64-obsd-tdep.c
> +++ b/gdb/sparc64-obsd-tdep.c
> @@ -423,7 +423,7 @@ static const struct regset sparc64obsd_fpregset =
>   static void
>   sparc64obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     tdep->gregset = &sparc64obsd_gregset;
>     tdep->sizeof_gregset = 288;
> diff --git a/gdb/sparc64-sol2-tdep.c b/gdb/sparc64-sol2-tdep.c
> index 458f0320582..e656c359efa 100644
> --- a/gdb/sparc64-sol2-tdep.c
> +++ b/gdb/sparc64-sol2-tdep.c
> @@ -199,7 +199,7 @@ static const struct frame_unwind sparc64_sol2_sigtramp_frame_unwind =
>   static void
>   sparc64_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     tdep->gregset = &sparc64_sol2_gregset;
>     tdep->sizeof_gregset = 304;
> diff --git a/gdb/sparc64-tdep.c b/gdb/sparc64-tdep.c
> index 95496d33ad4..5ca5f2dca8c 100644
> --- a/gdb/sparc64-tdep.c
> +++ b/gdb/sparc64-tdep.c
> @@ -648,7 +648,7 @@ sparc64_structure_or_union_p (const struct type *type)
>   static struct type *
>   sparc64_pstate_type (struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->sparc64_pstate_type)
>       {
> @@ -675,7 +675,7 @@ sparc64_pstate_type (struct gdbarch *gdbarch)
>   static struct type *
>   sparc64_ccr_type (struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->sparc64_ccr_type == NULL)
>       {
> @@ -700,7 +700,7 @@ sparc64_ccr_type (struct gdbarch *gdbarch)
>   static struct type *
>   sparc64_fsr_type (struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->sparc64_fsr_type)
>       {
> @@ -733,7 +733,7 @@ sparc64_fsr_type (struct gdbarch *gdbarch)
>   static struct type *
>   sparc64_fprs_type (struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     if (!tdep->sparc64_fprs_type)
>       {
> @@ -1806,7 +1806,7 @@ sparc64_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr)
>   void
>   sparc64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
>   
>     tdep->pc_regnum = SPARC64_PC_REGNUM;
>     tdep->npc_regnum = SPARC64_NPC_REGNUM;
> diff --git a/gdb/tic6x-linux-tdep.c b/gdb/tic6x-linux-tdep.c
> index 5a93294361a..b2422d1ccc0 100644
> --- a/gdb/tic6x-linux-tdep.c
> +++ b/gdb/tic6x-linux-tdep.c
> @@ -45,7 +45,7 @@ static const gdb_byte tic6x_bkpt_bnop_le[] = { 0x22, 0xa1, 0x00, 0x00 };
>   static unsigned int
>   tic6x_register_sigcontext_offset (unsigned int regnum, struct gdbarch *gdbarch)
>   {
> -  tic6x_gdbarch_tdep *tdep = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  tic6x_gdbarch_tdep *tdep = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
>   
>     if (regnum == TIC6X_A4_REGNUM || regnum == TIC6X_A4_REGNUM + 2
>         || regnum == TIC6X_A4_REGNUM + 4)
> @@ -92,7 +92,7 @@ tic6x_linux_rt_sigreturn_init (const struct tramp_frame *self,
>   		    + TIC6X_SIGINFO_SIZE
>   		    + 4 + 4 /* uc_flags and *uc_link in struct ucontext.  */
>   		    + TIC6X_STACK_T_SIZE);
> -  tic6x_gdbarch_tdep *tdep = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  tic6x_gdbarch_tdep *tdep = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
>     unsigned int reg_offset;
>     unsigned int i;
>   
> @@ -165,7 +165,7 @@ extern struct target_so_ops dsbt_so_ops;
>   static void
>   tic6x_uclinux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  tic6x_gdbarch_tdep *tdep = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  tic6x_gdbarch_tdep *tdep = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
>   
>     linux_init_abi (info, gdbarch, 0);
>   
> diff --git a/gdb/tic6x-tdep.c b/gdb/tic6x-tdep.c
> index 3e49030ab14..b7efcf18576 100644
> --- a/gdb/tic6x-tdep.c
> +++ b/gdb/tic6x-tdep.c
> @@ -325,7 +325,7 @@ tic6x_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
>   static const gdb_byte *
>   tic6x_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
>   {
> -  tic6x_gdbarch_tdep *tdep = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  tic6x_gdbarch_tdep *tdep = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
>   
>     *size = kind;
>   
> @@ -599,7 +599,7 @@ tic6x_get_next_pc (struct regcache *regcache, CORE_ADDR pc)
>         if (inst == TIC6X_INST_SWE)
>   	{
>   	  tic6x_gdbarch_tdep *tdep
> -	    = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +	    = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
>   
>   	  if (tdep->syscall_next_pc != NULL)
>   	    return tdep->syscall_next_pc (get_current_frame ());
> @@ -1217,7 +1217,7 @@ tic6x_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          arches = gdbarch_list_lookup_by_info (arches->next, &info))
>       {
>         tic6x_gdbarch_tdep *tdep
> -	= (tic6x_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<tic6x_gdbarch_tdep> (arches->gdbarch);
>   
>         if (has_gp != tdep->has_gp)
>   	continue;
> diff --git a/gdb/v850-tdep.c b/gdb/v850-tdep.c
> index a67310a2440..4de5faa6a47 100644
> --- a/gdb/v850-tdep.c
> +++ b/gdb/v850-tdep.c
> @@ -511,7 +511,7 @@ v850_use_struct_convention (struct gdbarch *gdbarch, struct type *type)
>   {
>     int i;
>     struct type *fld_type, *tgt_type;
> -  v850_gdbarch_tdep *tdep = (v850_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  v850_gdbarch_tdep *tdep = gdbarch_tdep<v850_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->abi == V850_ABI_RH850)
>       {
> @@ -1023,7 +1023,7 @@ v850_push_dummy_call (struct gdbarch *gdbarch,
>     int argnum;
>     int arg_space = 0;
>     int stack_offset;
> -  v850_gdbarch_tdep *tdep = (v850_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  v850_gdbarch_tdep *tdep = gdbarch_tdep<v850_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->abi == V850_ABI_RH850)
>       stack_offset = 0;
> @@ -1374,7 +1374,7 @@ v850_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>          arches = gdbarch_list_lookup_by_info (arches->next, &info))
>       {
>         v850_gdbarch_tdep *tdep
> -	= (v850_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> +	= gdbarch_tdep<v850_gdbarch_tdep> (arches->gdbarch);
>   
>         if (tdep->e_flags != e_flags || tdep->e_machine != e_machine)
>   	continue;
> diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
> index 277507ddf09..9e7335acec3 100644
> --- a/gdb/windows-nat.c
> +++ b/gdb/windows-nat.c
> @@ -488,7 +488,7 @@ windows_fetch_one_register (struct regcache *regcache,
>   
>     char *context_offset = context_ptr + windows_process.mappings[r];
>     struct gdbarch *gdbarch = regcache->arch ();
> -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
>   
>     gdb_assert (!gdbarch_read_pc_p (gdbarch));
>     gdb_assert (gdbarch_pc_regnum (gdbarch) >= 0);
> diff --git a/gdb/xtensa-linux-nat.c b/gdb/xtensa-linux-nat.c
> index 5a08824a680..d005c9d8f78 100644
> --- a/gdb/xtensa-linux-nat.c
> +++ b/gdb/xtensa-linux-nat.c
> @@ -62,7 +62,7 @@ fill_gregset (const struct regcache *regcache,
>     int i;
>     xtensa_elf_gregset_t *regs = (xtensa_elf_gregset_t *) gregsetp;
>     struct gdbarch *gdbarch = regcache->arch ();
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     if (regnum == gdbarch_pc_regnum (gdbarch) || regnum == -1)
>       regcache->raw_collect (gdbarch_pc_regnum (gdbarch), &regs->pc);
> @@ -124,7 +124,7 @@ supply_gregset_reg (struct regcache *regcache,
>     xtensa_elf_gregset_t *regs = (xtensa_elf_gregset_t *) gregsetp;
>   
>     struct gdbarch *gdbarch = regcache->arch ();
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     if (regnum == gdbarch_pc_regnum (gdbarch) || regnum == -1)
>       regcache->raw_supply (gdbarch_pc_regnum (gdbarch), &regs->pc);
> diff --git a/gdb/xtensa-linux-tdep.c b/gdb/xtensa-linux-tdep.c
> index ef55319fd09..600b59b8894 100644
> --- a/gdb/xtensa-linux-tdep.c
> +++ b/gdb/xtensa-linux-tdep.c
> @@ -99,7 +99,7 @@ xtensa_linux_gdb_signal_to_target (struct gdbarch *gdbarch,
>   static void
>   xtensa_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>   {
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->num_nopriv_regs < tdep->num_regs)
>       {
> diff --git a/gdb/xtensa-tdep.c b/gdb/xtensa-tdep.c
> index b6558838e44..f881870e244 100644
> --- a/gdb/xtensa-tdep.c
> +++ b/gdb/xtensa-tdep.c
> @@ -116,7 +116,7 @@ static unsigned int xtensa_debug_level = 0;
>   static int
>   windowing_enabled (struct gdbarch *gdbarch, unsigned int ps)
>   {
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     /* If we know CALL0 ABI is set explicitly,  say it is Call0.  */
>     if (tdep->call_abi == CallAbiCall0Only)
> @@ -130,7 +130,7 @@ windowing_enabled (struct gdbarch *gdbarch, unsigned int ps)
>   static int
>   arreg_number (struct gdbarch *gdbarch, int a_regnum, ULONGEST wb)
>   {
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>     int arreg;
>   
>     arreg = a_regnum - tdep->a0_base;
> @@ -145,7 +145,7 @@ arreg_number (struct gdbarch *gdbarch, int a_regnum, ULONGEST wb)
>   static int
>   areg_number (struct gdbarch *gdbarch, int ar_regnum, unsigned int wb)
>   {
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>     int areg;
>   
>     areg = ar_regnum - tdep->ar_base;
> @@ -226,7 +226,7 @@ static int
>   xtensa_find_register_by_name (struct gdbarch *gdbarch, const char *name)
>   {
>     int i;
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     for (i = 0; i < gdbarch_num_cooked_regs (gdbarch); i++)
>       if (strcasecmp (tdep->regmap[i].name, name) == 0)
> @@ -239,7 +239,7 @@ xtensa_find_register_by_name (struct gdbarch *gdbarch, const char *name)
>   static const char *
>   xtensa_register_name (struct gdbarch *gdbarch, int regnum)
>   {
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     /* Return the name stored in the register map.  */
>     if (regnum >= 0 && regnum < gdbarch_num_cooked_regs (gdbarch))
> @@ -254,7 +254,7 @@ xtensa_register_name (struct gdbarch *gdbarch, int regnum)
>   static struct type *
>   xtensa_register_type (struct gdbarch *gdbarch, int regnum)
>   {
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     /* Return signed integer for ARx and Ax registers.  */
>     if ((regnum >= tdep->ar_base
> @@ -339,7 +339,7 @@ static int
>   xtensa_reg_to_regnum (struct gdbarch *gdbarch, int regnum)
>   {
>     int i;
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     if (regnum >= 0 && regnum < 16)
>       return tdep->a0_base + regnum;
> @@ -542,7 +542,7 @@ xtensa_pseudo_register_read (struct gdbarch *gdbarch,
>   {
>     DEBUGTRACE ("xtensa_pseudo_register_read (... regnum = %d (%s) ...)\n",
>   	      regnum, xtensa_register_name (gdbarch, regnum));
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     /* Read aliases a0..a15, if this is a Windowed ABI.  */
>     if (tdep->isa_use_windowed_registers
> @@ -634,7 +634,7 @@ xtensa_pseudo_register_write (struct gdbarch *gdbarch,
>   {
>     DEBUGTRACE ("xtensa_pseudo_register_write (... regnum = %d (%s) ...)\n",
>   	      regnum, xtensa_register_name (gdbarch, regnum));
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     /* Renumber register, if aliases a0..a15 on Windowed ABI.  */
>     if (tdep->isa_use_windowed_registers
> @@ -767,7 +767,7 @@ xtensa_register_reggroup_p (struct gdbarch *gdbarch,
>   			    int regnum,
>   			    const struct reggroup *group)
>   {
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>     xtensa_register_t* reg = &tdep->regmap[regnum];
>     xtensa_register_type_t type = reg->type;
>     xtensa_register_group_t rg = reg->group;
> @@ -821,7 +821,7 @@ xtensa_supply_gregset (const struct regset *regset,
>   {
>     const xtensa_elf_gregset_t *regs = (const xtensa_elf_gregset_t *) gregs;
>     struct gdbarch *gdbarch = rc->arch ();
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>     int i;
>   
>     DEBUGTRACE ("xtensa_supply_gregset (..., regnum==%d, ...)\n", regnum);
> @@ -1050,7 +1050,7 @@ static struct frame_id
>   xtensa_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
>   {
>     CORE_ADDR pc, fp;
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     /* THIS-FRAME is a dummy frame.  Return a frame ID of that frame.  */
>   
> @@ -1105,7 +1105,7 @@ xtensa_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR current_pc)
>   {
>   #define RETURN_FP goto done
>   
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>     unsigned int fp_regnum = tdep->a0_base + 1;
>     CORE_ADDR start_addr;
>     xtensa_isa isa;
> @@ -1255,7 +1255,7 @@ xtensa_frame_cache (struct frame_info *this_frame, void **this_cache)
>     if (windowed)
>       {
>         LONGEST op1;
> -      xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>         /* Get WINDOWBASE, WINDOWSTART, and PS registers.  */
>         wb = get_frame_register_unsigned (this_frame,
> @@ -1417,7 +1417,7 @@ xtensa_frame_prev_register (struct frame_info *this_frame,
>     struct xtensa_frame_cache *cache;
>     ULONGEST saved_reg = 0;
>     int done = 1;
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     if (*this_cache == NULL)
>       *this_cache = xtensa_frame_cache (this_frame, this_cache);
> @@ -1546,7 +1546,7 @@ xtensa_extract_return_value (struct type *type,
>   
>     gdb_assert(len > 0);
>   
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>     if (tdep->call_abi != CallAbiCall0Only)
>       {
>         /* First, we have to find the caller window in the register file.  */
> @@ -1602,7 +1602,7 @@ xtensa_store_return_value (struct type *type,
>   
>     DEBUGTRACE ("xtensa_store_return_value (...)\n");
>   
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>     if (tdep->call_abi != CallAbiCall0Only)
>       {
>         regcache_raw_read_unsigned
> @@ -1686,7 +1686,7 @@ xtensa_push_dummy_call (struct gdbarch *gdbarch,
>   			CORE_ADDR struct_addr)
>   {
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>     int size, onstack_size;
>     gdb_byte *buf = (gdb_byte *) alloca (16);
>     CORE_ADDR ra, ps;
> @@ -1935,7 +1935,7 @@ xtensa_push_dummy_call (struct gdbarch *gdbarch,
>   static int
>   xtensa_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
>   {
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     if (tdep->isa_use_density_instructions)
>       return 2;
> @@ -2182,7 +2182,7 @@ call0_track_op (struct gdbarch *gdbarch, xtensa_c0reg_t dst[], xtensa_c0reg_t sr
>   {
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     unsigned litbase, litaddr, litval;
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     switch (opclass)
>       {
> @@ -2557,7 +2557,7 @@ call0_frame_cache (struct frame_info *this_frame,
>     CORE_ADDR body_pc=UINT_MAX;	/* PC, where prologue analysis stopped.  */
>     CORE_ADDR sp, fp, ra;
>     int fp_regnum = C0_SP, c0_hasfp = 0, c0_frmsz = 0, prev_sp = 0, to_stk;
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>    
>     sp = get_frame_register_unsigned
>       (this_frame, tdep->a0_base + 1);
> @@ -2710,7 +2710,7 @@ static int a11_was_saved;
>   static void
>   execute_l32e (struct gdbarch *gdbarch, int at, int as, int offset, CORE_ADDR wb)
>   {
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>     int atreg = arreg_number (gdbarch, tdep->a0_base + at, wb);
>     int asreg = arreg_number (gdbarch, tdep->a0_base + as, wb);
>     CORE_ADDR addr = xtensa_read_register (asreg) + offset;
> @@ -2740,7 +2740,7 @@ execute_l32e (struct gdbarch *gdbarch, int at, int as, int offset, CORE_ADDR wb)
>   static void
>   execute_s32e (struct gdbarch *gdbarch, int at, int as, int offset, CORE_ADDR wb)
>   {
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>     int atreg = arreg_number (gdbarch, tdep->a0_base + at, wb);
>     int asreg = arreg_number (gdbarch, tdep->a0_base + as, wb);
>     CORE_ADDR addr = xtensa_read_register (asreg) + offset;
> @@ -2774,7 +2774,7 @@ execute_code (struct gdbarch *gdbarch, CORE_ADDR current_pc, CORE_ADDR wb)
>     xtensa_opcode opc;
>     int insn_num = 0;
>     void (*func) (struct gdbarch *, int, int, int, CORE_ADDR);
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     uint32_t at, as, offset;
>   
> @@ -2905,7 +2905,7 @@ xtensa_window_interrupt_frame_cache (struct frame_info *this_frame,
>     CORE_ADDR ps, wb, ws, ra;
>     int epc1_regnum, i, regnum;
>     xtensa_exception_handler_t eh_type;
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>   
>     /* Read PS, WB, and WS from the hardware. Note that PS register
>        must be present, if Windowed ABI is supported.  */
> @@ -3019,7 +3019,7 @@ xtensa_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
>   
>         CORE_ADDR end_func;
>   
> -      xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>         if ((tdep->call_abi == CallAbiCall0Only)
>   	  && call0_ret (start_pc, prologue_sal.end))
>   	return start_pc;
> @@ -3041,7 +3041,7 @@ xtensa_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
>   static void
>   xtensa_verify_config (struct gdbarch *gdbarch)
>   {
> -  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
>     string_file log;
>   
>     /* Verify that we got a reasonable number of AREGS.  */
> diff --git a/gdb/z80-tdep.c b/gdb/z80-tdep.c
> index d27e567c358..6a11883e7b4 100644
> --- a/gdb/z80-tdep.c
> +++ b/gdb/z80-tdep.c
> @@ -308,7 +308,7 @@ z80_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR pc_beg, CORE_ADDR pc_end,
>   		   struct z80_unwind_cache *info)
>   {
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
> -  z80_gdbarch_tdep *tdep = (z80_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  z80_gdbarch_tdep *tdep = gdbarch_tdep<z80_gdbarch_tdep> (gdbarch);
>     int addr_len = tdep->addr_length;
>     gdb_byte prologue[32]; /* max prologue is 24 bytes: __interrupt with local array */
>     int pos = 0;
> @@ -564,7 +564,7 @@ z80_frame_unwind_cache (struct frame_info *this_frame,
>     gdb_byte buf[sizeof(void*)];
>     struct z80_unwind_cache *info;
>     struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -  z80_gdbarch_tdep *tdep = (z80_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +  z80_gdbarch_tdep *tdep = gdbarch_tdep<z80_gdbarch_tdep> (gdbarch);
>     int addr_len = tdep->addr_length;
>   
>     if (*this_prologue_cache)
> @@ -697,7 +697,7 @@ z80_frame_prev_register (struct frame_info *this_frame,
>   	  ULONGEST pc;
>   	  gdb_byte buf[3];
>   	  struct gdbarch *gdbarch = get_frame_arch (this_frame);
> -	  z80_gdbarch_tdep *tdep = (z80_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +	  z80_gdbarch_tdep *tdep = gdbarch_tdep<z80_gdbarch_tdep> (gdbarch);
>   	  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>   
>   	  read_memory (info->saved_regs[Z80_PC_REGNUM].addr (),
> @@ -750,7 +750,7 @@ z80_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
>       }
>     else /* kind is non-RST address, use CALL instead, but it is dungerous */
>       {
> -      z80_gdbarch_tdep *tdep = (z80_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> +      z80_gdbarch_tdep *tdep = gdbarch_tdep<z80_gdbarch_tdep> (gdbarch);
>         gdb_byte *p = break_insn;
>         *p++ = 0xcd;
>         *p++ = (kind >> 0) & 0xff;

LGTM from aarch64's/arm's linux side.

^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCHv3 0/6] Handle trying to use a native target with the wrong binary
  2022-06-10 13:08 ` [PATCHv2 0/6] Handle trying to use a native target with the wrong binary Andrew Burgess
                     ` (5 preceding siblings ...)
  2022-06-10 13:08   ` [PATCHv2 6/6] gdb: native target invalid architecture detection Andrew Burgess
@ 2022-06-13 16:15   ` Andrew Burgess
  2022-06-13 16:15     ` [PATCHv3 1/6] gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope Andrew Burgess
                       ` (7 more replies)
  6 siblings, 8 replies; 83+ messages in thread
From: Andrew Burgess @ 2022-06-13 16:15 UTC (permalink / raw)
  To: gdb-patches; +Cc: Luis Machado, Andrew Burgess

Changes since v2:

 - Patch #3 has been replaced after feedback from Luis.  New patch
   fixes sider issues for arm, mips, and frv targets, this includes
   the issue the v2 patch fixed.

 - Nothing else has changed.

Changes since v1:

 - Patches #1 and #2 are unchanged.

 - Patch #3 is new in this version.

 - Patch #4 is unchanged (was patch 3).

 - Patch #5 is updated inline with John's feedback (was patch 4).

 - Patch #6 is extended to handle multi-arch case for rs6000/ppc and
   arm/aarch64, commit message is updated to discuss these cases, as
   well as mentioning i386/x86-64 (was patch 5).

Series has been tested on x86-64/linux and aarch64/linux.

---

Andrew Burgess (6):
  gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope
  gdb/mips: rewrite show_mask_address
  gdb: select suitable thread for gdbarch_adjust_breakpoint_address
  gdb: move the type cast into gdbarch_tdep
  gdb: ensure the cast in gdbarch_tdep is valid
  gdb: native target invalid architecture detection

 gdb/aarch64-fbsd-nat.c     |   4 +-
 gdb/aarch64-fbsd-tdep.c    |   6 +-
 gdb/aarch64-linux-nat.c    |  28 +++++---
 gdb/aarch64-linux-tdep.c   |  10 +--
 gdb/aarch64-newlib-tdep.c  |   2 +-
 gdb/aarch64-tdep.c         |  48 ++++++-------
 gdb/aix-thread.c           |  28 ++++----
 gdb/alpha-linux-tdep.c     |   2 +-
 gdb/alpha-netbsd-tdep.c    |   2 +-
 gdb/alpha-obsd-tdep.c      |   2 +-
 gdb/alpha-tdep.c           |  14 ++--
 gdb/amd64-darwin-tdep.c    |   2 +-
 gdb/amd64-fbsd-nat.c       |   4 +-
 gdb/amd64-fbsd-tdep.c      |   4 +-
 gdb/amd64-linux-tdep.c     |   8 +--
 gdb/amd64-netbsd-tdep.c    |   2 +-
 gdb/amd64-obsd-tdep.c      |   2 +-
 gdb/amd64-sol2-tdep.c      |   2 +-
 gdb/amd64-tdep.c           |  34 ++++-----
 gdb/amd64-windows-tdep.c   |   2 +-
 gdb/arc-linux-tdep.c       |   4 +-
 gdb/arc-newlib-tdep.c      |   2 +-
 gdb/arc-tdep.c             |   8 +--
 gdb/arch-utils.c           |  14 +++-
 gdb/arch-utils.h           |   5 ++
 gdb/arm-fbsd-nat.c         |   4 +-
 gdb/arm-fbsd-tdep.c        |   6 +-
 gdb/arm-linux-nat.c        |   8 +--
 gdb/arm-linux-tdep.c       |   4 +-
 gdb/arm-netbsd-nat.c       |   8 +--
 gdb/arm-netbsd-tdep.c      |   4 +-
 gdb/arm-none-tdep.c        |   2 +-
 gdb/arm-obsd-tdep.c        |   2 +-
 gdb/arm-tdep.c             | 142 ++++++++++++++++++++-----------------
 gdb/arm-wince-tdep.c       |   2 +-
 gdb/avr-tdep.c             |  12 ++--
 gdb/bfin-tdep.c            |   4 +-
 gdb/breakpoint.c           |  24 +++++--
 gdb/cris-linux-tdep.c      |   2 +-
 gdb/cris-tdep.c            |  18 ++---
 gdb/csky-tdep.c            |   2 +-
 gdb/frv-tdep.c             |   4 +-
 gdb/ft32-tdep.c            |   2 +-
 gdb/gdbarch.h              |  26 ++++++-
 gdb/hppa-bsd-tdep.c        |   2 +-
 gdb/hppa-linux-tdep.c      |   4 +-
 gdb/hppa-tdep.c            |  12 ++--
 gdb/i386-bsd-tdep.c        |   2 +-
 gdb/i386-darwin-tdep.c     |   4 +-
 gdb/i386-fbsd-tdep.c       |   4 +-
 gdb/i386-gnu-tdep.c        |   2 +-
 gdb/i386-go32-tdep.c       |   2 +-
 gdb/i386-linux-tdep.c      |   4 +-
 gdb/i386-netbsd-tdep.c     |   4 +-
 gdb/i386-nto-tdep.c        |   6 +-
 gdb/i386-obsd-tdep.c       |   2 +-
 gdb/i386-sol2-tdep.c       |   2 +-
 gdb/i386-tdep.c            |  98 ++++++++++++-------------
 gdb/i386-windows-tdep.c    |   2 +-
 gdb/i387-tdep.c            |  20 +++---
 gdb/ia64-linux-tdep.c      |   2 +-
 gdb/ia64-tdep.c            |  12 ++--
 gdb/inf-child.c            |  19 +++++
 gdb/inf-child.h            |   2 +
 gdb/infcmd.c               |   8 +++
 gdb/loongarch-linux-nat.c  |   6 +-
 gdb/loongarch-linux-tdep.c |   8 +--
 gdb/loongarch-tdep.c       |  10 +--
 gdb/m32c-tdep.c            |  58 +++++++--------
 gdb/m68hc11-tdep.c         |  12 ++--
 gdb/m68k-bsd-tdep.c        |   2 +-
 gdb/m68k-linux-tdep.c      |   2 +-
 gdb/m68k-tdep.c            |  38 +++++-----
 gdb/mep-tdep.c             |   6 +-
 gdb/mips-linux-tdep.c      |   4 +-
 gdb/mips-tdep.c            |  85 +++++++++++-----------
 gdb/mn10300-tdep.c         |   2 +-
 gdb/mn10300-tdep.h         |   2 +-
 gdb/msp430-tdep.c          |  12 ++--
 gdb/nds32-tdep.c           |  20 +++---
 gdb/nios2-linux-tdep.c     |   2 +-
 gdb/nios2-tdep.c           |   4 +-
 gdb/or1k-tdep.c            |   8 +--
 gdb/ppc-fbsd-nat.c         |  12 +++-
 gdb/ppc-fbsd-tdep.c        |   8 +--
 gdb/ppc-linux-nat.c        |  30 +++++---
 gdb/ppc-linux-tdep.c       |  18 ++---
 gdb/ppc-netbsd-nat.c       |   6 +-
 gdb/ppc-netbsd-tdep.c      |   2 +-
 gdb/ppc-obsd-nat.c         |  12 +++-
 gdb/ppc-obsd-tdep.c        |   2 +-
 gdb/ppc-sysv-tdep.c        |  22 +++---
 gdb/ppc64-tdep.c           |   2 +-
 gdb/riscv-linux-tdep.c     |   2 +-
 gdb/riscv-tdep.c           |  26 +++----
 gdb/rl78-tdep.c            |   8 +--
 gdb/rs6000-aix-nat.c       |  14 +++-
 gdb/rs6000-aix-tdep.c      |  16 ++---
 gdb/rs6000-lynx178-tdep.c  |   4 +-
 gdb/rs6000-tdep.c          | 132 +++++++++++++++++-----------------
 gdb/rx-tdep.c              |   2 +-
 gdb/s390-linux-tdep.c      |  20 +++---
 gdb/s390-tdep.c            |  42 +++++------
 gdb/sh-linux-tdep.c        |   2 +-
 gdb/sh-netbsd-tdep.c       |   2 +-
 gdb/sh-tdep.c              |   8 +--
 gdb/sparc-linux-tdep.c     |   4 +-
 gdb/sparc-netbsd-tdep.c    |   2 +-
 gdb/sparc-sol2-tdep.c      |   2 +-
 gdb/sparc-tdep.c           |  14 ++--
 gdb/sparc64-fbsd-tdep.c    |   2 +-
 gdb/sparc64-linux-tdep.c   |   4 +-
 gdb/sparc64-netbsd-tdep.c  |   2 +-
 gdb/sparc64-obsd-tdep.c    |   2 +-
 gdb/sparc64-sol2-tdep.c    |   2 +-
 gdb/sparc64-tdep.c         |  10 +--
 gdb/target-delegates.c     |  28 ++++++++
 gdb/target.h               |  13 +++-
 gdb/tic6x-linux-tdep.c     |   6 +-
 gdb/tic6x-tdep.c           |   6 +-
 gdb/v850-tdep.c            |   6 +-
 gdb/windows-nat.c          |   2 +-
 gdb/xtensa-linux-nat.c     |   4 +-
 gdb/xtensa-linux-tdep.c    |   2 +-
 gdb/xtensa-tdep.c          |  54 +++++++-------
 gdb/z80-tdep.c             |   8 +--
 126 files changed, 868 insertions(+), 706 deletions(-)

-- 
2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCHv3 1/6] gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope
  2022-06-13 16:15   ` [PATCHv3 0/6] Handle trying to use a native target with the wrong binary Andrew Burgess
@ 2022-06-13 16:15     ` Andrew Burgess
  2022-06-13 16:15     ` [PATCHv3 2/6] gdb/mips: rewrite show_mask_address Andrew Burgess
                       ` (6 subsequent siblings)
  7 siblings, 0 replies; 83+ messages in thread
From: Andrew Burgess @ 2022-06-13 16:15 UTC (permalink / raw)
  To: gdb-patches; +Cc: Luis Machado, Andrew Burgess

This is a small refactor to resolve an issue before it becomes a
problem in a later commit.

Move the fetching of an arm_gdbarch_tdep into a more inner scope
within two functions in arm-tdep.c.

The problem with the current code is that the functions in question
are used as the callbacks for two set/show parameters.  These set/show
parameters are available no matter the current architecture, but are
really about controlling an ARM architecture specific setting.  And
so, if I build GDB for all targets on an x86-64/GNU-Linux system, I
can still do this:

  (gdb) show arm fpu
  (gdb) show arm abi

After these calls we end up in show_fp_model and arm_show_abi
respectively, where we unconditionally do this:

  arm_gdbarch_tdep *tdep
    = (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());

However, the gdbarch_tdep() result will only be a arm_gdbarch_tdep if
the current architecture is ARM, otherwise the result will actually be
of some other type.

This isn't actually a problem, as in both cases the use of tdep is
guarded by a later check that the gdbarch architecture is
bfd_arch_arm.

This commit just moves the call to gdbarch_tdep() after the
architecture check.

In a later commit gdbarch_tdep() will be able to spot when we are
casting the result to the wrong type, and this function will trigger
assertion failures if things are not fixed.

There should be not user visible changes after this commit.
---
 gdb/arm-tdep.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 456649afdaa..7f27d4bd6e8 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -9077,14 +9077,16 @@ static void
 show_fp_model (struct ui_file *file, int from_tty,
 	       struct cmd_list_element *c, const char *value)
 {
-  arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
-
   if (arm_fp_model == ARM_FLOAT_AUTO
       && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm)
-    gdb_printf (file, _("\
+    {
+      arm_gdbarch_tdep *tdep
+	= (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+
+      gdb_printf (file, _("\
 The current ARM floating point model is \"auto\" (currently \"%s\").\n"),
-		fp_model_strings[tdep->fp_model]);
+		  fp_model_strings[tdep->fp_model]);
+    }
   else
     gdb_printf (file, _("\
 The current ARM floating point model is \"%s\".\n"),
@@ -9115,14 +9117,16 @@ static void
 arm_show_abi (struct ui_file *file, int from_tty,
 	     struct cmd_list_element *c, const char *value)
 {
-  arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
-
   if (arm_abi_global == ARM_ABI_AUTO
       && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm)
-    gdb_printf (file, _("\
+    {
+      arm_gdbarch_tdep *tdep
+	= (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+
+      gdb_printf (file, _("\
 The current ARM ABI is \"auto\" (currently \"%s\").\n"),
-		arm_abi_strings[tdep->arm_abi]);
+		  arm_abi_strings[tdep->arm_abi]);
+    }
   else
     gdb_printf (file, _("The current ARM ABI is \"%s\".\n"),
 		arm_abi_string);
-- 
2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCHv3 2/6] gdb/mips: rewrite show_mask_address
  2022-06-13 16:15   ` [PATCHv3 0/6] Handle trying to use a native target with the wrong binary Andrew Burgess
  2022-06-13 16:15     ` [PATCHv3 1/6] gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope Andrew Burgess
@ 2022-06-13 16:15     ` Andrew Burgess
  2022-06-13 16:15     ` [PATCHv3 3/6] gdb: select suitable thread for gdbarch_adjust_breakpoint_address Andrew Burgess
                       ` (5 subsequent siblings)
  7 siblings, 0 replies; 83+ messages in thread
From: Andrew Burgess @ 2022-06-13 16:15 UTC (permalink / raw)
  To: gdb-patches; +Cc: Luis Machado, Andrew Burgess

This commit is similar to the previous commit, but in this case GDB is
actually relying on undefined behaviour.

Consider building GDB for all targets on x86-64/GNU-Linux, then doing
this:

  (gdb) show mips mask-address
  Zeroing of upper 32 bits of 64-bit addresses is auto.
  The 32 bit address mask is set automatically.  Currently disabled
  (gdb)

The 'show mips mask-address' command ends up in show_mask_address in
mips-tdep.c, and this function does this:

  mips_gdbarch_tdep *tdep
    = (mips_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());

Later we might pass TDEP to mips_mask_address_p.  However, in my
example above, on an x86-64 native target, the current target
architecture will be an x86-64 gdbarch, and the tdep field within the
gdbarch will be of type i386_gdbarch_tdep, not of type
mips_gdbarch_tdep, as a result the cast above was incorrect, and TDEP
is not pointing at what it thinks it is.

I also think the current output is a little confusing, we appear to
have two lines that show the same information, but using different
words.

The first line comes from calling deprecated_show_value_hack, while
the second line is printed directly from show_mask_address.  However,
both of these lines are printing the same mask_address_var value.  I
don't think the two lines actually adds any value here.

Finally, none of the text in this function is passed through the
internationalisation mechanism.

It would be nice to remove another use of deprecated_show_value_hack
if possible, so this commit does a complete rewrite of
show_mask_address.

After this commit the output of the above example command, still on my
x86-64 native target is:

    (gdb) show mips mask-address
    Zeroing of upper 32 bits of 64-bit addresses is "auto" (current architecture is not MIPS).

The 'current architecture is not MIPS' text is only displayed when the
current architecture is not MIPS.  If the architecture is mips then we
get the more commonly seen 'currently "on"' or 'currently "off"', like
this:

  (gdb) set architecture mips
  The target architecture is set to "mips".
  (gdb) show mips mask-address
  Zeroing of upper 32 bits of 64-bit addresses is "auto" (currently "off").
  (gdb)

All the text is passed through the internationalisation mechanism, and
we only call gdbarch_tdep when we know the gdbarch architecture is
bfd_arch_mips.
---
 gdb/mips-tdep.c | 37 +++++++++++++++++--------------------
 1 file changed, 17 insertions(+), 20 deletions(-)

diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index 805c5beba59..fc1cb46de84 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -1183,28 +1183,25 @@ static void
 show_mask_address (struct ui_file *file, int from_tty,
 		   struct cmd_list_element *c, const char *value)
 {
-  mips_gdbarch_tdep *tdep
-    = (mips_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
-
-  deprecated_show_value_hack (file, from_tty, c, value);
-  switch (mask_address_var)
+  const char *additional_text = "";
+  if (mask_address_var == AUTO_BOOLEAN_AUTO)
     {
-    case AUTO_BOOLEAN_TRUE:
-      gdb_printf (file, "The 32 bit mips address mask is enabled\n");
-      break;
-    case AUTO_BOOLEAN_FALSE:
-      gdb_printf (file, "The 32 bit mips address mask is disabled\n");
-      break;
-    case AUTO_BOOLEAN_AUTO:
-      gdb_printf
-	(file,
-	 "The 32 bit address mask is set automatically.  Currently %s\n",
-	 mips_mask_address_p (tdep) ? "enabled" : "disabled");
-      break;
-    default:
-      internal_error (__FILE__, __LINE__, _("show_mask_address: bad switch"));
-      break;
+      if (gdbarch_bfd_arch_info (target_gdbarch ())->arch != bfd_arch_mips)
+	additional_text = _(" (current architecture is not MIPS)");
+      else
+	{
+	  mips_gdbarch_tdep *tdep
+	    = (mips_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+
+	  if (mips_mask_address_p (tdep))
+	    additional_text = _(" (currently \"on\")");
+	  else
+	    additional_text = _(" (currently \"off\")");
+	}
     }
+
+  gdb_printf (file, _("Zeroing of upper 32 bits of 64-bit addresses is \"%s\"%s.\n"),
+	      value, additional_text);
 }
 
 /* Tell if the program counter value in MEMADDR is in a standard ISA
-- 
2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCHv3 3/6] gdb: select suitable thread for gdbarch_adjust_breakpoint_address
  2022-06-13 16:15   ` [PATCHv3 0/6] Handle trying to use a native target with the wrong binary Andrew Burgess
  2022-06-13 16:15     ` [PATCHv3 1/6] gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope Andrew Burgess
  2022-06-13 16:15     ` [PATCHv3 2/6] gdb/mips: rewrite show_mask_address Andrew Burgess
@ 2022-06-13 16:15     ` Andrew Burgess
  2022-06-14  9:45       ` Luis Machado
  2022-06-24 16:58       ` Pedro Alves
  2022-06-13 16:15     ` [PATCHv3 4/6] gdb: move the type cast into gdbarch_tdep Andrew Burgess
                       ` (4 subsequent siblings)
  7 siblings, 2 replies; 83+ messages in thread
From: Andrew Burgess @ 2022-06-13 16:15 UTC (permalink / raw)
  To: gdb-patches; +Cc: Luis Machado, Andrew Burgess

The three targets that implement gdbarch_adjust_breakpoint_address are
arm, frv, and mips.  In each of these targets the adjust breakpoint
address function does some combination of reading the symbol table, or
reading memory at the location the breakpoint could be placed.

The problem is that performing these actions requires that the current
inferior and program space be the one in which the breakpoint will be
placed, and this is not currently always the case.

Consider a GDB session with multiple inferiors.  One inferior might be
a native target while another could be a remote target of a completely
different architecture.  Alternatively, if we consider ARM and
AArch64, one native inferior might be AArch64, while a second native
inferior could be ARM.

In these cases it is possible, and valid, for a user to have one
inferior selected, and place a breakpoint in the other inferior by
placing a breakpoint on a particular symbol.

If this happens, then currently, when
gdbarch_adjust_breakpoint_address is called, the wrong inferior (and
program space) will be selected, and memory reads, and symbol look
ups, will not return the expected results, this could lead to
breakpoints being placed in the wrong location.

There are currently two places where gdbarch_adjust_breakpoint_address
is called:

  1. In infrun.c, in the function handle_step_into_function.  In this
  case, I believe that the correct inferior and program space will
  already be selected as this is called as part of the stop event
  handling, so I don't think we need to worry about this case, and

  2. In breakpoint.c, in the function adjust_breakpoint_address, which
  is itself called from code_breakpoint::add_location and
  watch_command_1.

  The watch_command_1 case I don't think we need to worry about, this
  is for when a local watch expression is created, which can only be
  in the currently selected inferior, so this case should be fine.

  The code_breakpoint::add_location case is the one that needs fixing,
  this is what allows a breakpoint to be created between inferiors.

To fix the code_breakpoint::add_location case, I propose that we pass
the "correct" program_space (i.e. the program space in which the
breakpoint will be created) to the adjust_breakpoint_address function.
Then in adjust_breakpoint_address we can make use of
switch_to_program_space_and_thread to switch program_space and
inferior before calling gdbarch_adjust_breakpoint_address.

I discovered this issue while working on a later patch in this
series.  This later patch will detect when we cast the result of
gdbarch_tdep to the wrong type.

With this later patch in place I ran gdb.multi/multi-arch.exp on an
AArch64 target.  In this situation, two inferiors are created, an
AArch64 inferior, and an ARM inferior.  The test selected the AArch64
inferior and tries to create a breakpoint in the ARM inferior.

As a result of this we end up in arm_adjust_breakpoint_address, which
calls arm_pc_is_thumb.  Before this commit the AArch64 inferior would
be current.  As a result, all of the checks in arm_pc_is_thumb would
fail (they rely on reading symbols from the current program space),
and so, at the end of arm_pc_is_thumb we would call
arm_frame_is_thumb.  However, remember, at this point the current
inferior is the AArch64 inferior, so the current frame is an AArch64
frame.

In arm_frame_is_thumb we call arm_psr_thumb_bit, which calls
gdbarch_tdep and casts the result to arm_gdbarch_tdep.  This is wrong,
the tdep field is of type aarch64_gdbarch_tdep.  After this we have
undefined behaviour.

With this patch in place, we will have switched to a thread in the ARM
program space before calling arm_adjust_breakpoint_address.  As a
result, we now succeed in looking up the required symbols in
arm_pc_is_thumb, and so we never call arm_frame_is_thumb.

However, in the worst case scenario, if we did end up calling
arm_frame_is_thumb, as the current inferior should now be the ARM
inferior, the current frame should be an ARM frame, so we still should
not hit undefined behaviour.

I have added an assert to arm_frame_is_thumb.
---
 gdb/arm-tdep.c   | 12 ++++++++----
 gdb/breakpoint.c | 24 ++++++++++++++++++------
 2 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 7f27d4bd6e8..e0e5c7efd63 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -541,20 +541,24 @@ arm_is_thumb (struct regcache *regcache)
   return (cpsr & t_bit) != 0;
 }
 
-/* Determine if FRAME is executing in Thumb mode.  */
+/* Determine if FRAME is executing in Thumb mode.  FRAME must be an ARM
+   frame.  */
 
 int
 arm_frame_is_thumb (struct frame_info *frame)
 {
-  CORE_ADDR cpsr;
-  ULONGEST t_bit = arm_psr_thumb_bit (get_frame_arch (frame));
+  /* Check the architecture of FRAME.  */
+  struct gdbarch *gdbarch = get_frame_arch (frame);
+  gdb_assert (gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm);
 
   /* Every ARM frame unwinder can unwind the T bit of the CPSR, either
      directly (from a signal frame or dummy frame) or by interpreting
      the saved LR (from a prologue or DWARF frame).  So consult it and
      trust the unwinders.  */
-  cpsr = get_frame_register_unsigned (frame, ARM_PS_REGNUM);
+  CORE_ADDR cpsr = get_frame_register_unsigned (frame, ARM_PS_REGNUM);
 
+  /* Find and extract the thumb bit.  */
+  ULONGEST t_bit = arm_psr_thumb_bit (gdbarch);
   return (cpsr & t_bit) != 0;
 }
 
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index ed932a19ed7..5370e70f15e 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -124,7 +124,8 @@ static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
 
 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
 					    CORE_ADDR bpaddr,
-					    enum bptype bptype);
+					    enum bptype bptype,
+					    struct program_space *pspace);
 
 static int watchpoint_locations_match (struct bp_location *loc1,
 				       struct bp_location *loc2);
@@ -7114,8 +7115,11 @@ breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
 
 static CORE_ADDR
 adjust_breakpoint_address (struct gdbarch *gdbarch,
-			   CORE_ADDR bpaddr, enum bptype bptype)
+			   CORE_ADDR bpaddr, enum bptype bptype,
+			   struct program_space *pspace)
 {
+  gdb_assert (pspace != nullptr);
+
   if (bptype == bp_watchpoint
       || bptype == bp_hardware_watchpoint
       || bptype == bp_read_watchpoint
@@ -7140,10 +7144,16 @@ adjust_breakpoint_address (struct gdbarch *gdbarch,
     {
       CORE_ADDR adjusted_bpaddr = bpaddr;
 
+      /* Some targets have architectural constraints on the placement
+	 of breakpoint instructions.  Obtain the adjusted address.  */
       if (gdbarch_adjust_breakpoint_address_p (gdbarch))
 	{
-	  /* Some targets have architectural constraints on the placement
-	     of breakpoint instructions.  Obtain the adjusted address.  */
+	  /* Targets that implement this adjustment function will
+	     likely inspect either the symbol table, or target memory
+	     add BPADDR, so ensure a suitable thread (and its
+	     associated program space) are currently selected.  */
+	  scoped_restore_current_pspace_and_thread restore_pspace_thread;
+	  switch_to_program_space_and_thread (pspace);
 	  adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
 	}
 
@@ -8098,7 +8108,8 @@ code_breakpoint::add_location (const symtab_and_line &sal)
      not want its scan of the location chain to find a breakpoint and
      location that's only been partially initialized.  */
   adjusted_address = adjust_breakpoint_address (loc_gdbarch,
-						sal.pc, type);
+						sal.pc, type,
+						sal.pspace);
 
   /* Sort the locations by their ADDRESS.  */
   new_loc = allocate_location ();
@@ -10085,7 +10096,8 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
 	  scope_breakpoint->loc->address
 	    = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
 					 scope_breakpoint->loc->requested_address,
-					 scope_breakpoint->type);
+					 scope_breakpoint->type,
+					 current_program_space);
 	}
     }
 
-- 
2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCHv3 4/6] gdb: move the type cast into gdbarch_tdep
  2022-06-13 16:15   ` [PATCHv3 0/6] Handle trying to use a native target with the wrong binary Andrew Burgess
                       ` (2 preceding siblings ...)
  2022-06-13 16:15     ` [PATCHv3 3/6] gdb: select suitable thread for gdbarch_adjust_breakpoint_address Andrew Burgess
@ 2022-06-13 16:15     ` Andrew Burgess
  2022-06-13 16:15     ` [PATCHv3 5/6] gdb: ensure the cast in gdbarch_tdep is valid Andrew Burgess
                       ` (3 subsequent siblings)
  7 siblings, 0 replies; 83+ messages in thread
From: Andrew Burgess @ 2022-06-13 16:15 UTC (permalink / raw)
  To: gdb-patches; +Cc: Luis Machado, Andrew Burgess

I built GDB for all targets on a x86-64/GNU-Linux system, and
then (accidentally) passed GDB a RISC-V binary, and asked GDB to "run"
the binary on the native target.  I got this error:

  (gdb) show architecture
  The target architecture is set to "auto" (currently "i386").
  (gdb) file /tmp/hello.rv32.exe
  Reading symbols from /tmp/hello.rv32.exe...
  (gdb) show architecture
  The target architecture is set to "auto" (currently "riscv:rv32").
  (gdb) run
  Starting program: /tmp/hello.rv32.exe
  ../../src/gdb/i387-tdep.c:596: internal-error: i387_supply_fxsave: Assertion `tdep->st0_regnum >= I386_ST0_REGNUM' failed.

What's going on here is this; initially the architecture is i386, this
is based on the default architecture, which is set based on the native
target.  After loading the RISC-V executable the architecture of the
current inferior is updated based on the architecture of the
executable.

When we "run", GDB does a fork & exec, with the inferior being
controlled through ptrace.  GDB sees an initial stop from the inferior
as soon as the inferior comes to life.  In response to this stop GDB
ends up calling save_stop_reason (linux-nat.c), which ends up trying
to read register from the inferior, to do this we end up calling
target_ops::fetch_registers, which, for the x86-64 native target,
calls amd64_linux_nat_target::fetch_registers.

After this I eventually end up in i387_supply_fxsave, different x86
based targets will end in different functions to fetch registers, but
it doesn't really matter which function we end up in, the problem is
this line, which is repeated in many places:

  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);

The problem here is that the ARCH in this line comes from the current
inferior, which, as we discussed above, will be a RISC-V gdbarch, the
tdep field will actually be of type riscv_gdbarch_tdep, not
i386_gdbarch_tdep.  After this cast we are relying on undefined
behaviour, in my case I happen to trigger an assert, but this might
not always be the case.

The thing I tried that exposed this problem was of course, trying to
start an executable of the wrong architecture on a native target.  I
don't think that the correct solution for this problem is to detect,
at the point of cast, that the gdbarch_tdep object is of the wrong
type, but, I did wonder, is there a way that we could protect
ourselves from incorrectly casting the gdbarch_tdep object?

I think that there is something we can do here, and this commit is the
first step in that direction, though no actual check is added by this
commit.

This commit can be split into two parts:

 (1) In gdbarch.h and arch-utils.c.  In these files I have modified
 gdbarch_tdep (the function) so that it now takes a template argument,
 like this:

    template<typename TDepType>
    static inline TDepType *
    gdbarch_tdep (struct gdbarch *gdbarch)
    {
      struct gdbarch_tdep *tdep = gdbarch_tdep_1 (gdbarch);
      return static_cast<TDepType *> (tdep);
    }

  After this change we are no better protected, but the cast is now
  done within the gdbarch_tdep function rather than at the call sites,
  this leads to the second, much larger change in this commit,

  (2) Everywhere gdbarch_tdep is called, we make changes like this:

    -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
    +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);

There should be no functional change after this commit.

In the next commit I will build on this change to add an assertion in
gdbarch_tdep that checks we are casting to the correct type.
---
 gdb/aarch64-fbsd-nat.c     |   4 +-
 gdb/aarch64-fbsd-tdep.c    |   6 +-
 gdb/aarch64-linux-nat.c    |  20 +++---
 gdb/aarch64-linux-tdep.c   |  10 +--
 gdb/aarch64-newlib-tdep.c  |   2 +-
 gdb/aarch64-tdep.c         |  48 +++++++-------
 gdb/aix-thread.c           |  28 ++++----
 gdb/alpha-linux-tdep.c     |   2 +-
 gdb/alpha-netbsd-tdep.c    |   2 +-
 gdb/alpha-obsd-tdep.c      |   2 +-
 gdb/alpha-tdep.c           |  14 ++--
 gdb/amd64-darwin-tdep.c    |   2 +-
 gdb/amd64-fbsd-nat.c       |   4 +-
 gdb/amd64-fbsd-tdep.c      |   4 +-
 gdb/amd64-linux-tdep.c     |   8 +--
 gdb/amd64-netbsd-tdep.c    |   2 +-
 gdb/amd64-obsd-tdep.c      |   2 +-
 gdb/amd64-sol2-tdep.c      |   2 +-
 gdb/amd64-tdep.c           |  34 +++++-----
 gdb/amd64-windows-tdep.c   |   2 +-
 gdb/arc-linux-tdep.c       |   4 +-
 gdb/arc-newlib-tdep.c      |   2 +-
 gdb/arc-tdep.c             |   8 +--
 gdb/arch-utils.c           |   6 +-
 gdb/arm-fbsd-nat.c         |   4 +-
 gdb/arm-fbsd-tdep.c        |   6 +-
 gdb/arm-linux-nat.c        |   8 +--
 gdb/arm-linux-tdep.c       |   4 +-
 gdb/arm-netbsd-nat.c       |   8 +--
 gdb/arm-netbsd-tdep.c      |   4 +-
 gdb/arm-none-tdep.c        |   2 +-
 gdb/arm-obsd-tdep.c        |   2 +-
 gdb/arm-tdep.c             | 110 +++++++++++++++----------------
 gdb/arm-wince-tdep.c       |   2 +-
 gdb/avr-tdep.c             |  12 ++--
 gdb/bfin-tdep.c            |   4 +-
 gdb/cris-linux-tdep.c      |   2 +-
 gdb/cris-tdep.c            |  18 ++---
 gdb/csky-tdep.c            |   2 +-
 gdb/frv-tdep.c             |   4 +-
 gdb/ft32-tdep.c            |   2 +-
 gdb/gdbarch.h              |  17 ++++-
 gdb/hppa-bsd-tdep.c        |   2 +-
 gdb/hppa-linux-tdep.c      |   4 +-
 gdb/hppa-tdep.c            |  12 ++--
 gdb/i386-bsd-tdep.c        |   2 +-
 gdb/i386-darwin-tdep.c     |   4 +-
 gdb/i386-fbsd-tdep.c       |   4 +-
 gdb/i386-gnu-tdep.c        |   2 +-
 gdb/i386-go32-tdep.c       |   2 +-
 gdb/i386-linux-tdep.c      |   4 +-
 gdb/i386-netbsd-tdep.c     |   4 +-
 gdb/i386-nto-tdep.c        |   6 +-
 gdb/i386-obsd-tdep.c       |   2 +-
 gdb/i386-sol2-tdep.c       |   2 +-
 gdb/i386-tdep.c            |  98 +++++++++++++--------------
 gdb/i386-windows-tdep.c    |   2 +-
 gdb/i387-tdep.c            |  20 +++---
 gdb/ia64-linux-tdep.c      |   2 +-
 gdb/ia64-tdep.c            |  12 ++--
 gdb/loongarch-linux-nat.c  |   6 +-
 gdb/loongarch-linux-tdep.c |   8 +--
 gdb/loongarch-tdep.c       |  10 +--
 gdb/m32c-tdep.c            |  58 ++++++++--------
 gdb/m68hc11-tdep.c         |  12 ++--
 gdb/m68k-bsd-tdep.c        |   2 +-
 gdb/m68k-linux-tdep.c      |   2 +-
 gdb/m68k-tdep.c            |  38 +++++------
 gdb/mep-tdep.c             |   6 +-
 gdb/mips-linux-tdep.c      |   4 +-
 gdb/mips-tdep.c            |  50 +++++++-------
 gdb/mn10300-tdep.c         |   2 +-
 gdb/mn10300-tdep.h         |   2 +-
 gdb/msp430-tdep.c          |  12 ++--
 gdb/nds32-tdep.c           |  20 +++---
 gdb/nios2-linux-tdep.c     |   2 +-
 gdb/nios2-tdep.c           |   4 +-
 gdb/or1k-tdep.c            |   8 +--
 gdb/ppc-fbsd-nat.c         |   4 +-
 gdb/ppc-fbsd-tdep.c        |   8 +--
 gdb/ppc-linux-nat.c        |  22 +++----
 gdb/ppc-linux-tdep.c       |  18 ++---
 gdb/ppc-netbsd-nat.c       |   6 +-
 gdb/ppc-netbsd-tdep.c      |   2 +-
 gdb/ppc-obsd-nat.c         |   4 +-
 gdb/ppc-obsd-tdep.c        |   2 +-
 gdb/ppc-sysv-tdep.c        |  22 +++----
 gdb/ppc64-tdep.c           |   2 +-
 gdb/riscv-linux-tdep.c     |   2 +-
 gdb/riscv-tdep.c           |  26 ++++----
 gdb/rl78-tdep.c            |   8 +--
 gdb/rs6000-aix-nat.c       |   6 +-
 gdb/rs6000-aix-tdep.c      |  16 ++---
 gdb/rs6000-lynx178-tdep.c  |   4 +-
 gdb/rs6000-tdep.c          | 132 ++++++++++++++++++-------------------
 gdb/rx-tdep.c              |   2 +-
 gdb/s390-linux-tdep.c      |  20 +++---
 gdb/s390-tdep.c            |  42 ++++++------
 gdb/sh-linux-tdep.c        |   2 +-
 gdb/sh-netbsd-tdep.c       |   2 +-
 gdb/sh-tdep.c              |   8 +--
 gdb/sparc-linux-tdep.c     |   4 +-
 gdb/sparc-netbsd-tdep.c    |   2 +-
 gdb/sparc-sol2-tdep.c      |   2 +-
 gdb/sparc-tdep.c           |  14 ++--
 gdb/sparc64-fbsd-tdep.c    |   2 +-
 gdb/sparc64-linux-tdep.c   |   4 +-
 gdb/sparc64-netbsd-tdep.c  |   2 +-
 gdb/sparc64-obsd-tdep.c    |   2 +-
 gdb/sparc64-sol2-tdep.c    |   2 +-
 gdb/sparc64-tdep.c         |  10 +--
 gdb/tic6x-linux-tdep.c     |   6 +-
 gdb/tic6x-tdep.c           |   6 +-
 gdb/v850-tdep.c            |   6 +-
 gdb/windows-nat.c          |   2 +-
 gdb/xtensa-linux-nat.c     |   4 +-
 gdb/xtensa-linux-tdep.c    |   2 +-
 gdb/xtensa-tdep.c          |  54 +++++++--------
 gdb/z80-tdep.c             |   8 +--
 119 files changed, 684 insertions(+), 667 deletions(-)

diff --git a/gdb/aarch64-fbsd-nat.c b/gdb/aarch64-fbsd-nat.c
index d8cf6227e73..708ddc40d58 100644
--- a/gdb/aarch64-fbsd-nat.c
+++ b/gdb/aarch64-fbsd-nat.c
@@ -90,7 +90,7 @@ aarch64_fbsd_nat_target::fetch_registers (struct regcache *regcache,
 				    &aarch64_fbsd_fpregset);
 
   gdbarch *gdbarch = regcache->arch ();
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   if (tdep->has_tls ())
     {
       const struct regcache_map_entry aarch64_fbsd_tls_regmap[] =
@@ -123,7 +123,7 @@ aarch64_fbsd_nat_target::store_registers (struct regcache *regcache,
 				    PT_SETFPREGS, &aarch64_fbsd_fpregset);
 
   gdbarch *gdbarch = regcache->arch ();
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   if (tdep->has_tls ())
     {
       const struct regcache_map_entry aarch64_fbsd_tls_regmap[] =
diff --git a/gdb/aarch64-fbsd-tdep.c b/gdb/aarch64-fbsd-tdep.c
index 891546b3c64..4a6b4115234 100644
--- a/gdb/aarch64-fbsd-tdep.c
+++ b/gdb/aarch64-fbsd-tdep.c
@@ -143,7 +143,7 @@ aarch64_fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					   void *cb_data,
 					   const struct regcache *regcache)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   cb (".reg", AARCH64_FBSD_SIZEOF_GREGSET, AARCH64_FBSD_SIZEOF_GREGSET,
       &aarch64_fbsd_gregset, NULL, cb_data);
@@ -190,7 +190,7 @@ static CORE_ADDR
 aarch64_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 				       CORE_ADDR lm_addr, CORE_ADDR offset)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   struct regcache *regcache;
 
   regcache = get_thread_arch_regcache (current_inferior ()->process_target (),
@@ -213,7 +213,7 @@ aarch64_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 static void
 aarch64_fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support.  */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c
index d58ad0143a2..a457fcd48ad 100644
--- a/gdb/aarch64-linux-nat.c
+++ b/gdb/aarch64-linux-nat.c
@@ -359,7 +359,7 @@ static void
 fetch_pauth_masks_from_thread (struct regcache *regcache)
 {
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
   int ret;
   struct iovec iovec;
   uint64_t pauth_regset[2] = {0, 0};
@@ -385,7 +385,7 @@ static void
 fetch_mteregs_from_thread (struct regcache *regcache)
 {
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
   int regno = tdep->mte_reg_base;
 
   gdb_assert (regno != -1);
@@ -410,7 +410,7 @@ static void
 store_mteregs_to_thread (struct regcache *regcache)
 {
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
   int regno = tdep->mte_reg_base;
 
   gdb_assert (regno != -1);
@@ -439,7 +439,7 @@ static void
 fetch_tlsregs_from_thread (struct regcache *regcache)
 {
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
   int regno = tdep->tls_regnum;
 
   gdb_assert (regno != -1);
@@ -464,7 +464,7 @@ static void
 store_tlsregs_to_thread (struct regcache *regcache)
 {
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
   int regno = tdep->tls_regnum;
 
   gdb_assert (regno != -1);
@@ -493,7 +493,7 @@ static void
 aarch64_fetch_registers (struct regcache *regcache, int regno)
 {
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
 
   if (regno == -1)
     {
@@ -543,7 +543,7 @@ static void
 aarch32_fetch_registers (struct regcache *regcache, int regno)
 {
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
 
   if (regno == -1)
     {
@@ -579,7 +579,7 @@ static void
 aarch64_store_registers (struct regcache *regcache, int regno)
 {
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
 
   if (regno == -1)
     {
@@ -619,7 +619,7 @@ static void
 aarch32_store_registers (struct regcache *regcache, int regno)
 {
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
 
   if (regno == -1)
     {
@@ -893,7 +893,7 @@ aarch64_linux_nat_target::thread_architecture (ptid_t ptid)
 
   /* Only return it if the current vector length matches the one in the tdep.  */
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (inf->gdbarch);
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (inf->gdbarch);
   uint64_t vq = aarch64_sve_get_vq (ptid.lwp ());
   if (vq == tdep->vq)
     return inf->gdbarch;
diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c
index 453692df2f4..4c96662efb3 100644
--- a/gdb/aarch64-linux-tdep.c
+++ b/gdb/aarch64-linux-tdep.c
@@ -286,7 +286,7 @@ aarch64_linux_sigframe_init (const struct tramp_frame *self,
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   CORE_ADDR sp = get_frame_register_unsigned (this_frame, AARCH64_SP_REGNUM);
   CORE_ADDR sigcontext_addr = (sp + AARCH64_RT_SIGFRAME_UCONTEXT_OFFSET
 			       + AARCH64_UCONTEXT_SIGCONTEXT_OFFSET );
@@ -640,7 +640,7 @@ aarch64_linux_collect_sve_regset (const struct regset *regset,
   gdb_byte *header = (gdb_byte *) buf;
   struct gdbarch *gdbarch = regcache->arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   uint64_t vq = tdep->vq;
 
   gdb_assert (buf != NULL);
@@ -676,7 +676,7 @@ aarch64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					    void *cb_data,
 					    const struct regcache *regcache)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   cb (".reg", AARCH64_LINUX_SIZEOF_GREGSET, AARCH64_LINUX_SIZEOF_GREGSET,
       &aarch64_linux_gregset, NULL, cb_data);
@@ -1743,7 +1743,7 @@ aarch64_linux_report_signal_info (struct gdbarch *gdbarch,
 				  struct ui_out *uiout,
 				  enum gdb_signal siggnal)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (!tdep->has_mte () || siggnal != GDB_SIGNAL_SEGV)
     return;
@@ -1812,7 +1812,7 @@ aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 								    NULL };
   static const char *const stap_register_indirection_suffixes[] = { "]",
 								    NULL };
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   tdep->lowest_pc = 0x8000;
 
diff --git a/gdb/aarch64-newlib-tdep.c b/gdb/aarch64-newlib-tdep.c
index 507b7fc5a51..c9236b17801 100644
--- a/gdb/aarch64-newlib-tdep.c
+++ b/gdb/aarch64-newlib-tdep.c
@@ -29,7 +29,7 @@
 static void
 aarch64_newlib_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   /* Jump buffer - support for longjmp.
      Offset of original PC in jump buffer (in registers).  */
diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
index 15b577c8a00..8670197a888 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -502,7 +502,7 @@ aarch64_analyze_prologue (struct gdbarch *gdbarch,
       else if (inst.opcode->iclass == ic_system)
 	{
 	  aarch64_gdbarch_tdep *tdep
-	    = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	    = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 	  int ra_state_val = 0;
 
 	  if (insn == 0xd503233f /* paciasp.  */
@@ -640,7 +640,7 @@ aarch64_analyze_prologue_test (void)
   struct aarch64_prologue_cache cache;
   cache.saved_regs = trad_frame_alloc_saved_regs (gdbarch);
 
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   /* Test the simple prologue in which frame pointer is used.  */
   {
@@ -1076,7 +1076,7 @@ aarch64_prologue_frame_unwind_stop_reason (struct frame_info *this_frame,
 
   /* Halt the backtrace at "_start".  */
   gdbarch *arch = get_frame_arch (this_frame);
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (arch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (arch);
   if (cache->prev_pc <= tdep->lowest_pc)
     return UNWIND_OUTERMOST;
 
@@ -1120,7 +1120,7 @@ aarch64_prologue_prev_register (struct frame_info *this_frame,
       CORE_ADDR lr;
       struct gdbarch *gdbarch = get_frame_arch (this_frame);
       aarch64_gdbarch_tdep *tdep
-	= (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	= gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
       lr = frame_unwind_register_unsigned (this_frame, AARCH64_LR_REGNUM);
 
@@ -1289,7 +1289,7 @@ aarch64_dwarf2_prev_register (struct frame_info *this_frame,
 			      void **this_cache, int regnum)
 {
   gdbarch *arch = get_frame_arch (this_frame);
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (arch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (arch);
   CORE_ADDR lr;
 
   switch (regnum)
@@ -1315,7 +1315,7 @@ aarch64_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
 			       struct dwarf2_frame_state_reg *reg,
 			       struct frame_info *this_frame)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   switch (regnum)
     {
@@ -1355,7 +1355,7 @@ static bool
 aarch64_execute_dwarf_cfa_vendor_op (struct gdbarch *gdbarch, gdb_byte op,
 				     struct dwarf2_frame_state *fs)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   struct dwarf2_frame_state_reg *ra_state;
 
   if (op == DW_CFA_AARCH64_negate_ra_state)
@@ -1996,7 +1996,7 @@ aarch64_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
 static struct type *
 aarch64_vnq_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vnq_type == NULL)
     {
@@ -2023,7 +2023,7 @@ aarch64_vnq_type (struct gdbarch *gdbarch)
 static struct type *
 aarch64_vnd_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vnd_type == NULL)
     {
@@ -2053,7 +2053,7 @@ aarch64_vnd_type (struct gdbarch *gdbarch)
 static struct type *
 aarch64_vns_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vns_type == NULL)
     {
@@ -2083,7 +2083,7 @@ aarch64_vns_type (struct gdbarch *gdbarch)
 static struct type *
 aarch64_vnh_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vnh_type == NULL)
     {
@@ -2116,7 +2116,7 @@ aarch64_vnh_type (struct gdbarch *gdbarch)
 static struct type *
 aarch64_vnb_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vnb_type == NULL)
     {
@@ -2143,7 +2143,7 @@ aarch64_vnb_type (struct gdbarch *gdbarch)
 static struct type *
 aarch64_vnv_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vnv_type == NULL)
     {
@@ -2214,7 +2214,7 @@ aarch64_vnv_type (struct gdbarch *gdbarch)
 static int
 aarch64_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (reg >= AARCH64_DWARF_X0 && reg <= AARCH64_DWARF_X0 + 30)
     return AARCH64_X0_REGNUM + reg - AARCH64_DWARF_X0;
@@ -2518,7 +2518,7 @@ aarch64_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
   CORE_ADDR jb_addr;
   gdb_byte buf[X_REGISTER_SIZE];
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   jb_addr = get_frame_register_unsigned (frame, AARCH64_X0_REGNUM);
@@ -2549,7 +2549,7 @@ aarch64_gen_return_address (struct gdbarch *gdbarch,
 static const char *
 aarch64_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   static const char *const q_name[] =
     {
@@ -2663,7 +2663,7 @@ aarch64_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 static struct type *
 aarch64_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   int p_regnum = regnum - gdbarch_num_regs (gdbarch);
 
@@ -2700,7 +2700,7 @@ static int
 aarch64_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 				    const struct reggroup *group)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   int p_regnum = regnum - gdbarch_num_regs (gdbarch);
 
@@ -2754,7 +2754,7 @@ static struct value *
 aarch64_pseudo_read_value (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int regnum)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   struct value *result_value = allocate_value (register_type (gdbarch, regnum));
 
   VALUE_LVAL (result_value) = lval_register;
@@ -2824,7 +2824,7 @@ static void
 aarch64_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache,
 		      int regnum, const gdb_byte *buf)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   regnum -= gdbarch_num_regs (gdbarch);
 
   if (regnum >= AARCH64_Q0_REGNUM && regnum < AARCH64_Q0_REGNUM + 32)
@@ -3377,7 +3377,7 @@ aarch64_get_tdesc_vq (const struct target_desc *tdesc)
 static int
 aarch64_cannot_store_register (struct gdbarch *gdbarch, int regnum)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (!tdep->has_pauth ())
     return 0;
@@ -3444,7 +3444,7 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
     {
       aarch64_gdbarch_tdep *tdep
-	= (aarch64_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
+	= gdbarch_tdep<aarch64_gdbarch_tdep> (best_arch->gdbarch);
       if (tdep && tdep->vq == vq)
 	return best_arch->gdbarch;
     }
@@ -3693,7 +3693,7 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 aarch64_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep == NULL)
     return;
@@ -3915,7 +3915,7 @@ aarch64_record_branch_except_sys (aarch64_insn_decode_record *aarch64_insn_r)
 {
 
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (aarch64_insn_r->gdbarch);
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (aarch64_insn_r->gdbarch);
   uint8_t insn_bits24_27, insn_bits28_31, insn_bits22_23;
   uint32_t record_buf[4];
 
diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c
index ecd8200b692..3d76b8c6d01 100644
--- a/gdb/aix-thread.c
+++ b/gdb/aix-thread.c
@@ -1114,7 +1114,7 @@ static void
 supply_gprs64 (struct regcache *regcache, uint64_t *vals)
 {
   ppc_gdbarch_tdep *tdep
-    = (ppc_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<ppc_gdbarch_tdep> (regcache->arch ());
   int regno;
 
   for (regno = 0; regno < ppc_num_gprs; regno++)
@@ -1136,7 +1136,7 @@ static void
 supply_fprs (struct regcache *regcache, double *vals)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int regno;
 
   /* This function should never be called on architectures without
@@ -1154,7 +1154,7 @@ supply_fprs (struct regcache *regcache, double *vals)
 static int
 special_register_p (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   return regno == gdbarch_pc_regnum (gdbarch)
       || regno == tdep->ppc_ps_regnum
@@ -1177,7 +1177,7 @@ supply_sprs64 (struct regcache *regcache,
 	       uint32_t fpscr)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   regcache->raw_supply (gdbarch_pc_regnum (gdbarch), (char *) &iar);
   regcache->raw_supply (tdep->ppc_ps_regnum, (char *) &msr);
@@ -1199,7 +1199,7 @@ supply_sprs32 (struct regcache *regcache,
 	       uint32_t fpscr)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   regcache->raw_supply (gdbarch_pc_regnum (gdbarch), (char *) &iar);
   regcache->raw_supply (tdep->ppc_ps_regnum, (char *) &msr);
@@ -1222,7 +1222,7 @@ static void
 fetch_regs_user_thread (struct regcache *regcache, pthdb_pthread_t pdtid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int status, i;
   pthdb_context_t ctx;
 
@@ -1277,7 +1277,7 @@ fetch_regs_kernel_thread (struct regcache *regcache, int regno,
 			  pthdb_tid_t tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   uint64_t gprs64[ppc_num_gprs];
   uint32_t gprs32[ppc_num_gprs];
   double fprs[ppc_num_fprs];
@@ -1380,7 +1380,7 @@ static void
 fill_gprs64 (const struct regcache *regcache, uint64_t *vals)
 {
   ppc_gdbarch_tdep *tdep
-    = (ppc_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<ppc_gdbarch_tdep> (regcache->arch ());
   int regno;
 
   for (regno = 0; regno < ppc_num_gprs; regno++)
@@ -1393,7 +1393,7 @@ static void
 fill_gprs32 (const struct regcache *regcache, uint32_t *vals)
 {
   ppc_gdbarch_tdep *tdep
-    = (ppc_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<ppc_gdbarch_tdep> (regcache->arch ());
   int regno;
 
   for (regno = 0; regno < ppc_num_gprs; regno++)
@@ -1407,7 +1407,7 @@ static void
 fill_fprs (const struct regcache *regcache, double *vals)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int regno;
 
   /* This function should never be called on architectures without
@@ -1431,7 +1431,7 @@ fill_sprs64 (const struct regcache *regcache,
 	     uint32_t *fpscr)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* Verify that the size of the size of the IAR buffer is the
      same as the raw size of the PC (in the register cache).  If
@@ -1465,7 +1465,7 @@ fill_sprs32 (const struct regcache *regcache,
 	     uint32_t *fpscr)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* Verify that the size of the size of the IAR buffer is the
      same as the raw size of the PC (in the register cache).  If
@@ -1502,7 +1502,7 @@ static void
 store_regs_user_thread (const struct regcache *regcache, pthdb_pthread_t pdtid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int status, i;
   pthdb_context_t ctx;
   uint32_t int32;
@@ -1592,7 +1592,7 @@ store_regs_kernel_thread (const struct regcache *regcache, int regno,
 			  pthdb_tid_t tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   uint64_t gprs64[ppc_num_gprs];
   uint32_t gprs32[ppc_num_gprs];
   double fprs[ppc_num_fprs];
diff --git a/gdb/alpha-linux-tdep.c b/gdb/alpha-linux-tdep.c
index 6cea40d3f34..c103aafc1ff 100644
--- a/gdb/alpha-linux-tdep.c
+++ b/gdb/alpha-linux-tdep.c
@@ -362,7 +362,7 @@ alpha_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   /* Hook into the MDEBUG frame unwinder.  */
   alpha_mdebug_init_abi (info, gdbarch);
 
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
   tdep->dynamic_sigtramp_offset = alpha_linux_sigtramp_offset;
   tdep->sigcontext_addr = alpha_linux_sigcontext_addr;
   tdep->pc_in_sigtramp = alpha_linux_pc_in_sigtramp;
diff --git a/gdb/alpha-netbsd-tdep.c b/gdb/alpha-netbsd-tdep.c
index 6b604cfa9c6..72d7019377f 100644
--- a/gdb/alpha-netbsd-tdep.c
+++ b/gdb/alpha-netbsd-tdep.c
@@ -250,7 +250,7 @@ static void
 alphanbsd_init_abi (struct gdbarch_info info,
 		    struct gdbarch *gdbarch)
 {
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
 
   /* Hook into the DWARF CFI frame unwinder.  */
   alpha_dwarf2_init_abi (info, gdbarch);
diff --git a/gdb/alpha-obsd-tdep.c b/gdb/alpha-obsd-tdep.c
index 8baa8cc32c4..c0d672c3f72 100644
--- a/gdb/alpha-obsd-tdep.c
+++ b/gdb/alpha-obsd-tdep.c
@@ -97,7 +97,7 @@ alphaobsd_sigcontext_addr (struct frame_info *this_frame)
 static void
 alphaobsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
 
   /* Hook into the DWARF CFI frame unwinder.  */
   alpha_dwarf2_init_abi (info, gdbarch);
diff --git a/gdb/alpha-tdep.c b/gdb/alpha-tdep.c
index f04bad6bed8..44efc8e4bbb 100644
--- a/gdb/alpha-tdep.c
+++ b/gdb/alpha-tdep.c
@@ -615,7 +615,7 @@ alpha_return_value (struct gdbarch *gdbarch, struct value *function,
 		    gdb_byte *readbuf, const gdb_byte *writebuf)
 {
   enum type_code code = type->code ();
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
 
   if ((code == TYPE_CODE_STRUCT
        || code == TYPE_CODE_UNION
@@ -851,7 +851,7 @@ static int
 alpha_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR jb_addr;
   gdb_byte raw_buffer[ALPHA_REGISTER_SIZE];
@@ -891,7 +891,7 @@ alpha_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
   *this_prologue_cache = info;
 
   gdbarch *arch = get_frame_arch (this_frame);
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (arch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (arch);
   info->sigcontext_addr = tdep->sigcontext_addr (this_frame);
 
   return info;
@@ -904,7 +904,7 @@ static CORE_ADDR
 alpha_sigtramp_register_address (struct gdbarch *gdbarch,
 				 CORE_ADDR sigcontext_addr, int regnum)
 { 
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
 
   if (regnum >= 0 && regnum < 32)
     return sigcontext_addr + tdep->sc_regs_offset + regnum * 8;
@@ -925,7 +925,7 @@ alpha_sigtramp_frame_this_id (struct frame_info *this_frame,
 			      struct frame_id *this_id)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
   struct alpha_sigtramp_unwind_cache *info
     = alpha_sigtramp_frame_unwind_cache (this_frame, this_prologue_cache);
   CORE_ADDR stack_addr, code_addr;
@@ -1000,7 +1000,7 @@ alpha_sigtramp_frame_sniffer (const struct frame_unwind *self,
 
   /* We shouldn't even bother to try if the OSABI didn't register a
      sigcontext_addr handler or pc_in_sigtramp handler.  */
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
   if (tdep->sigcontext_addr == NULL)
     return 0;
 
@@ -1041,7 +1041,7 @@ static int heuristic_fence_post = 0;
 static CORE_ADDR
 alpha_heuristic_proc_start (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
   CORE_ADDR last_non_nop = pc;
   CORE_ADDR fence = pc - heuristic_fence_post;
   CORE_ADDR orig_pc = pc;
diff --git a/gdb/amd64-darwin-tdep.c b/gdb/amd64-darwin-tdep.c
index 74906f6a02d..7fc35536bc6 100644
--- a/gdb/amd64-darwin-tdep.c
+++ b/gdb/amd64-darwin-tdep.c
@@ -97,7 +97,7 @@ amd64_darwin_sigcontext_addr (struct frame_info *this_frame)
 static void
 x86_darwin_init_abi_64 (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   amd64_init_abi (info, gdbarch,
 		  amd64_target_description (X86_XSTATE_SSE_MASK, true));
diff --git a/gdb/amd64-fbsd-nat.c b/gdb/amd64-fbsd-nat.c
index d125d582a21..7023a182e78 100644
--- a/gdb/amd64-fbsd-nat.c
+++ b/gdb/amd64-fbsd-nat.c
@@ -102,7 +102,7 @@ amd64_fbsd_nat_target::fetch_registers (struct regcache *regcache, int regnum)
 {
   struct gdbarch *gdbarch = regcache->arch ();
 #if defined(PT_GETFSBASE) || defined(PT_GETGSBASE)
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 #endif
   pid_t pid = get_ptrace_pid (regcache->ptid ());
   const struct regset *gregset = find_gregset (gdbarch);
@@ -174,7 +174,7 @@ amd64_fbsd_nat_target::store_registers (struct regcache *regcache, int regnum)
 {
   struct gdbarch *gdbarch = regcache->arch ();
 #if defined(PT_GETFSBASE) || defined(PT_GETGSBASE)
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 #endif
   pid_t pid = get_ptrace_pid (regcache->ptid ());
   const struct regset *gregset = find_gregset (gdbarch);
diff --git a/gdb/amd64-fbsd-tdep.c b/gdb/amd64-fbsd-tdep.c
index 55764beaad2..8e40283d838 100644
--- a/gdb/amd64-fbsd-tdep.c
+++ b/gdb/amd64-fbsd-tdep.c
@@ -262,7 +262,7 @@ amd64fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					void *cb_data,
 					const struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   cb (".reg", AMD64_FBSD_SIZEOF_GREGSET, AMD64_FBSD_SIZEOF_GREGSET,
       &amd64_fbsd_gregset, NULL, cb_data);
@@ -299,7 +299,7 @@ amd64fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 static void
 amd64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support. */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
index 9a0759d639c..aa9c56586ab 100644
--- a/gdb/amd64-linux-tdep.c
+++ b/gdb/amd64-linux-tdep.c
@@ -1656,7 +1656,7 @@ amd64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					  void *cb_data,
 					  const struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   cb (".reg", 27 * 8, 27 * 8, &i386_gregset, NULL, cb_data);
   cb (".reg2", 512, 512, &amd64_fpregset, NULL, cb_data);
@@ -1793,7 +1793,7 @@ static void
 amd64_linux_init_abi_common(struct gdbarch_info info, struct gdbarch *gdbarch,
 			    int num_disp_step_buffers)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, num_disp_step_buffers);
 
@@ -1846,7 +1846,7 @@ amd64_linux_init_abi_common(struct gdbarch_info info, struct gdbarch *gdbarch,
 static void
 amd64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   struct tdesc_arch_data *tdesc_data = info.tdesc_data;
   const struct tdesc_feature *feature;
   int valid_p;
@@ -2060,7 +2060,7 @@ amd64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 static void
 amd64_x32_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   struct tdesc_arch_data *tdesc_data = info.tdesc_data;
   const struct tdesc_feature *feature;
   int valid_p;
diff --git a/gdb/amd64-netbsd-tdep.c b/gdb/amd64-netbsd-tdep.c
index 3ab0267060d..59d723caa55 100644
--- a/gdb/amd64-netbsd-tdep.c
+++ b/gdb/amd64-netbsd-tdep.c
@@ -97,7 +97,7 @@ int amd64nbsd_r_reg_offset[] =
 static void
 amd64nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* Initialize general-purpose register set details first.  */
   tdep->gregset_reg_offset = amd64nbsd_r_reg_offset;
diff --git a/gdb/amd64-obsd-tdep.c b/gdb/amd64-obsd-tdep.c
index 3cb64fe924f..f0bc7c474a6 100644
--- a/gdb/amd64-obsd-tdep.c
+++ b/gdb/amd64-obsd-tdep.c
@@ -420,7 +420,7 @@ static const struct frame_unwind amd64obsd_trapframe_unwind =
 static void
 amd64obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   amd64_init_abi (info, gdbarch,
 		  amd64_target_description (X86_XSTATE_SSE_MASK, true));
diff --git a/gdb/amd64-sol2-tdep.c b/gdb/amd64-sol2-tdep.c
index 22a48e476a5..ce96eb045ec 100644
--- a/gdb/amd64-sol2-tdep.c
+++ b/gdb/amd64-sol2-tdep.c
@@ -80,7 +80,7 @@ amd64_sol2_mcontext_addr (struct frame_info *this_frame)
 static void
 amd64_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   tdep->gregset_reg_offset = amd64_sol2_gregset_reg_offset;
   tdep->gregset_num_regs = ARRAY_SIZE (amd64_sol2_gregset_reg_offset);
diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index b95ab1e87b8..0563b32a54b 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -247,7 +247,7 @@ static const int amd64_dwarf_regmap_len =
 static int
 amd64_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int ymm0_regnum = tdep->ymm0_regnum;
   int regnum = -1;
 
@@ -331,7 +331,7 @@ static const char * const amd64_dword_names[] =
 static const char *
 amd64_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   if (i386_byte_regnum_p (gdbarch, regnum))
     return amd64_byte_names[regnum - tdep->al_regnum];
   else if (i386_zmm_regnum_p (gdbarch, regnum))
@@ -353,7 +353,7 @@ amd64_pseudo_register_read_value (struct gdbarch *gdbarch,
 				  readable_regcache *regcache,
 				  int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   value *result_value = allocate_value (register_type (gdbarch, regnum));
   VALUE_LVAL (result_value) = lval_register;
@@ -413,7 +413,7 @@ amd64_pseudo_register_write (struct gdbarch *gdbarch,
 			     struct regcache *regcache,
 			     int regnum, const gdb_byte *buf)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (i386_byte_regnum_p (gdbarch, regnum))
     {
@@ -465,7 +465,7 @@ static int
 amd64_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				  struct agent_expr *ax, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (i386_byte_regnum_p (gdbarch, regnum))
     {
@@ -2749,7 +2749,7 @@ static struct amd64_frame_cache *
 amd64_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct amd64_frame_cache *cache;
   CORE_ADDR addr;
@@ -2832,7 +2832,7 @@ amd64_sigtramp_frame_sniffer (const struct frame_unwind *self,
 			      void **this_cache)
 {
   gdbarch *arch = get_frame_arch (this_frame);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
 
   /* We shouldn't even bother if we don't have a sigcontext_addr
      handler.  */
@@ -3032,7 +3032,7 @@ amd64_supply_fpregset (const struct regset *regset, struct regcache *regcache,
 		       int regnum, const void *fpregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   gdb_assert (len >= tdep->sizeof_fpregset);
   amd64_supply_fxsave (regcache, regnum, fpregs);
@@ -3049,7 +3049,7 @@ amd64_collect_fpregset (const struct regset *regset,
 			int regnum, void *fpregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   gdb_assert (len >= tdep->sizeof_fpregset);
   amd64_collect_fxsave (regcache, regnum, fpregs);
@@ -3073,7 +3073,7 @@ amd64_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
   gdb_byte buf[8];
   CORE_ADDR jb_addr;
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int jb_pc_offset = tdep->jb_pc_offset;
   int len = TYPE_LENGTH (builtin_type (gdbarch)->builtin_func_ptr);
 
@@ -3117,7 +3117,7 @@ void
 amd64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch,
 		const target_desc *default_tdesc)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   const struct target_desc *tdesc = info.target_desc;
   static const char *const stap_integer_prefixes[] = { "$", NULL };
   static const char *const stap_register_prefixes[] = { "%", NULL };
@@ -3296,7 +3296,7 @@ amd64_none_init_abi (gdbarch_info info, gdbarch *arch)
 static struct type *
 amd64_x32_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   switch (regnum - tdep->eax_regnum)
     {
@@ -3314,7 +3314,7 @@ void
 amd64_x32_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch,
 		    const target_desc *default_tdesc)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   amd64_init_abi (info, gdbarch, default_tdesc);
 
@@ -3384,7 +3384,7 @@ amd64_supply_fxsave (struct regcache *regcache, int regnum,
 		     const void *fxsave)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   i387_supply_fxsave (regcache, regnum, fxsave);
 
@@ -3407,7 +3407,7 @@ amd64_supply_xsave (struct regcache *regcache, int regnum,
 		    const void *xsave)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   i387_supply_xsave (regcache, regnum, xsave);
 
@@ -3442,7 +3442,7 @@ amd64_collect_fxsave (const struct regcache *regcache, int regnum,
 		      void *fxsave)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   gdb_byte *regs = (gdb_byte *) fxsave;
 
   i387_collect_fxsave (regcache, regnum, fxsave);
@@ -3463,7 +3463,7 @@ amd64_collect_xsave (const struct regcache *regcache, int regnum,
 		     void *xsave, int gcore)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   gdb_byte *regs = (gdb_byte *) xsave;
 
   i387_collect_xsave (regcache, regnum, xsave, gcore);
diff --git a/gdb/amd64-windows-tdep.c b/gdb/amd64-windows-tdep.c
index eca94f2ea7c..a9aef0bab88 100644
--- a/gdb/amd64-windows-tdep.c
+++ b/gdb/amd64-windows-tdep.c
@@ -1277,7 +1277,7 @@ amd64_windows_auto_wide_charset (void)
 static void
 amd64_windows_init_abi_common (gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* The dwarf2 unwinder (appended very early by i386_gdbarch_init) is
      preferred over the SEH one.  The reasons are:
diff --git a/gdb/arc-linux-tdep.c b/gdb/arc-linux-tdep.c
index 13595f2e8e9..9c1febcd900 100644
--- a/gdb/arc-linux-tdep.c
+++ b/gdb/arc-linux-tdep.c
@@ -411,7 +411,7 @@ static std::vector<CORE_ADDR>
 arc_linux_software_single_step (struct regcache *regcache)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
   struct disassemble_info di = arc_disassemble_info (gdbarch);
 
   /* Read current instruction.  */
@@ -693,7 +693,7 @@ arc_linux_core_read_description (struct gdbarch *gdbarch,
 static void
 arc_linux_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
 
   arc_linux_debug_printf ("GNU/Linux OS/ABI initialization.");
 
diff --git a/gdb/arc-newlib-tdep.c b/gdb/arc-newlib-tdep.c
index 7d7406c501c..2499dff43ec 100644
--- a/gdb/arc-newlib-tdep.c
+++ b/gdb/arc-newlib-tdep.c
@@ -36,7 +36,7 @@ arc_newlib_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
   arc_newlib_debug_printf ("Initialization.");
 
-  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
 
   /* Offset of original PC in longjmp jump buffer (in registers).  Value of PC
      offset can be found in newlib/libc/machine/arc/setjmp.S.  */
diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c
index 3edfd466f3b..b9c734210fe 100644
--- a/gdb/arc-tdep.c
+++ b/gdb/arc-tdep.c
@@ -1002,7 +1002,7 @@ arc_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
   arc_debug_printf ("called");
 
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
   int pc_offset = tdep->jb_pc * ARC_REGISTER_SIZE;
   gdb_byte buf[ARC_REGISTER_SIZE];
   CORE_ADDR jb_addr = get_frame_register_unsigned (frame, ARC_FIRST_ARG_REGNUM);
@@ -1827,7 +1827,7 @@ arc_make_sigtramp_frame_cache (struct frame_info *this_frame)
   arc_debug_printf ("called");
 
   gdbarch *arch = get_frame_arch (this_frame);
-  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (arch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (arch);
 
   /* Allocate new frame cache instance and space for saved register info.  */
   struct arc_frame_cache *cache = FRAME_OBSTACK_ZALLOC (struct arc_frame_cache);
@@ -1904,7 +1904,7 @@ arc_sigtramp_frame_sniffer (const struct frame_unwind *self,
   arc_debug_printf ("called");
 
   gdbarch *arch = get_frame_arch (this_frame);
-  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (arch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (arch);
 
   /* If we have a sigcontext_addr handler, then just return 1 (same as the
      "default_frame_sniffer ()").  */
@@ -2431,7 +2431,7 @@ arc_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 arc_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
 
   gdb_printf (file, "arc_dump_tdep: jb_pc = %i\n", tdep->jb_pc);
 
diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index ff946ee3767..360b8d694be 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -1198,11 +1198,13 @@ gdbarch_free (struct gdbarch *arch)
   xfree (obstack);
 }
 
+/* See gdbarch.h.  */
+
 struct gdbarch_tdep *
-gdbarch_tdep (struct gdbarch *gdbarch)
+gdbarch_tdep_1 (struct gdbarch *gdbarch)
 {
   if (gdbarch_debug >= 2)
-    gdb_printf (gdb_stdlog, "gdbarch_tdep called\n");
+    gdb_printf (gdb_stdlog, "gdbarch_tdep_1 called\n");
   return gdbarch->tdep;
 }
 
diff --git a/gdb/arm-fbsd-nat.c b/gdb/arm-fbsd-nat.c
index a306e1e2ee0..b161b7ed908 100644
--- a/gdb/arm-fbsd-nat.c
+++ b/gdb/arm-fbsd-nat.c
@@ -55,7 +55,7 @@ arm_fbsd_nat_target::fetch_registers (struct regcache *regcache, int regnum)
 #endif
 #ifdef PT_GETREGSET
   gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->tls_regnum > 0)
     {
@@ -90,7 +90,7 @@ arm_fbsd_nat_target::store_registers (struct regcache *regcache, int regnum)
 #endif
 #ifdef PT_GETREGSET
   gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->tls_regnum > 0)
     {
diff --git a/gdb/arm-fbsd-tdep.c b/gdb/arm-fbsd-tdep.c
index 483820c1092..61c8f0cecad 100644
--- a/gdb/arm-fbsd-tdep.c
+++ b/gdb/arm-fbsd-tdep.c
@@ -159,7 +159,7 @@ arm_fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				       void *cb_data,
 				       const struct regcache *regcache)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   cb (".reg", ARM_FBSD_SIZEOF_GREGSET, ARM_FBSD_SIZEOF_GREGSET,
       &arm_fbsd_gregset, NULL, cb_data);
@@ -233,7 +233,7 @@ static CORE_ADDR
 arm_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 				   CORE_ADDR lm_addr, CORE_ADDR offset)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   struct regcache *regcache;
 
   regcache = get_thread_arch_regcache (current_inferior ()->process_target (),
@@ -256,7 +256,7 @@ arm_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 static void
 arm_fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support.  */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/arm-linux-nat.c b/gdb/arm-linux-nat.c
index 8dac8456282..0188c78fe7a 100644
--- a/gdb/arm-linux-nat.c
+++ b/gdb/arm-linux-nat.c
@@ -339,7 +339,7 @@ fetch_vfp_regs (struct regcache *regcache)
   gdb_byte regbuf[ARM_VFP3_REGS_SIZE];
   int ret, tid;
   struct gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Get the thread id for the ptrace call.  */
   tid = regcache->ptid ().lwp ();
@@ -368,7 +368,7 @@ store_vfp_regs (const struct regcache *regcache)
   gdb_byte regbuf[ARM_VFP3_REGS_SIZE];
   int ret, tid;
   struct gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Get the thread id for the ptrace call.  */
   tid = regcache->ptid ().lwp ();
@@ -413,7 +413,7 @@ void
 arm_linux_nat_target::fetch_registers (struct regcache *regcache, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (-1 == regno)
     {
@@ -450,7 +450,7 @@ void
 arm_linux_nat_target::store_registers (struct regcache *regcache, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (-1 == regno)
     {
diff --git a/gdb/arm-linux-tdep.c b/gdb/arm-linux-tdep.c
index f299e9665d5..d530b7f59a8 100644
--- a/gdb/arm-linux-tdep.c
+++ b/gdb/arm-linux-tdep.c
@@ -712,7 +712,7 @@ arm_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					void *cb_data,
 					const struct regcache *regcache)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   cb (".reg", ARM_LINUX_SIZEOF_GREGSET, ARM_LINUX_SIZEOF_GREGSET,
       &arm_linux_gregset, NULL, cb_data);
@@ -1715,7 +1715,7 @@ arm_linux_init_abi (struct gdbarch_info info,
 								    NULL };
   static const char *const stap_register_indirection_suffixes[] = { "]",
 								    NULL };
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 1);
 
diff --git a/gdb/arm-netbsd-nat.c b/gdb/arm-netbsd-nat.c
index 764bbe8cd3d..251159154c9 100644
--- a/gdb/arm-netbsd-nat.c
+++ b/gdb/arm-netbsd-nat.c
@@ -50,7 +50,7 @@ static arm_netbsd_nat_target the_arm_netbsd_nat_target;
 static void
 arm_supply_vfpregset (struct regcache *regcache, struct fpreg *fpregset)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
   if (tdep->vfp_register_count == 0)
     return;
 
@@ -97,7 +97,7 @@ fetch_fp_register (struct regcache *regcache, int regno)
       return;
     }
 
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
   if (regno == ARM_FPSCR_REGNUM && tdep->vfp_register_count != 0)
     regcache->raw_supply (ARM_FPSCR_REGNUM, (char *) &vfp.vfp_fpscr);
   else if (regno >= ARM_D0_REGNUM
@@ -279,7 +279,7 @@ store_fp_register (const struct regcache *regcache, int regno)
       return;
     }
 
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
   if (regno == ARM_FPSCR_REGNUM && tdep->vfp_register_count != 0)
     regcache->raw_collect (ARM_FPSCR_REGNUM, (char *) &vfp.vfp_fpscr);
   else if (regno >= ARM_D0_REGNUM
@@ -301,7 +301,7 @@ store_fp_register (const struct regcache *regcache, int regno)
 static void
 store_fp_regs (const struct regcache *regcache)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
   int lwp = regcache->ptid ().lwp ();
   if (tdep->vfp_register_count == 0)
     return;
diff --git a/gdb/arm-netbsd-tdep.c b/gdb/arm-netbsd-tdep.c
index a6a78f0b893..aa4d15df4c6 100644
--- a/gdb/arm-netbsd-tdep.c
+++ b/gdb/arm-netbsd-tdep.c
@@ -111,7 +111,7 @@ static void
 arm_netbsd_init_abi_common (struct gdbarch_info info,
 			    struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   tdep->lowest_pc = 0x8000;
   switch (info.byte_order)
@@ -148,7 +148,7 @@ static void
 arm_netbsd_elf_init_abi (struct gdbarch_info info,
 			 struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   arm_netbsd_init_abi_common (info, gdbarch);
 
diff --git a/gdb/arm-none-tdep.c b/gdb/arm-none-tdep.c
index 510ce4fa3c5..0d5eb04826e 100644
--- a/gdb/arm-none-tdep.c
+++ b/gdb/arm-none-tdep.c
@@ -177,7 +177,7 @@ arm_none_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				       void *cb_data,
 				       const struct regcache *regcache)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   cb (".reg", ARM_NONE_SIZEOF_GREGSET, ARM_NONE_SIZEOF_GREGSET,
       &arm_none_gregset, nullptr, cb_data);
diff --git a/gdb/arm-obsd-tdep.c b/gdb/arm-obsd-tdep.c
index 37cb30b9a2a..634c76b7561 100644
--- a/gdb/arm-obsd-tdep.c
+++ b/gdb/arm-obsd-tdep.c
@@ -76,7 +76,7 @@ static void
 armobsd_init_abi (struct gdbarch_info info,
 		  struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->fp_model == ARM_FLOAT_AUTO)
     tdep->fp_model = ARM_FLOAT_SOFT_VFP;
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index e0e5c7efd63..25ea7d86962 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -338,7 +338,7 @@ static void
 arm_cache_init (struct arm_prologue_cache *cache, struct frame_info *frame)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   arm_cache_init (cache, gdbarch);
 
@@ -520,7 +520,7 @@ bool arm_unwind_secure_frames = true;
 int
 arm_psr_thumb_bit (struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->is_m)
     return XPSR_T;
@@ -632,7 +632,7 @@ arm_pc_is_thumb (struct gdbarch *gdbarch, CORE_ADDR memaddr)
   struct bound_minimal_symbol sym;
   char type;
   arm_displaced_step_copy_insn_closure *dsc = nullptr;
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (gdbarch_displaced_step_copy_insn_closure_by_addr_p (gdbarch))
     dsc = ((arm_displaced_step_copy_insn_closure * )
@@ -736,7 +736,7 @@ arm_pc_is_thumb (struct gdbarch *gdbarch, CORE_ADDR memaddr)
 static int
 arm_m_addr_is_magic (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   if (tdep->have_sec_ext)
     {
       switch ((addr & 0xff000000))
@@ -778,7 +778,7 @@ arm_m_addr_is_magic (struct gdbarch *gdbarch, CORE_ADDR addr)
 static CORE_ADDR
 arm_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR val)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* On M-profile devices, do not strip the low bit from EXC_RETURN
      (the magic exception return address).  */
@@ -1382,7 +1382,7 @@ thumb_analyze_prologue (struct gdbarch *gdbarch,
 	    }
 
 	  arm_gdbarch_tdep *tdep
-	    = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	    = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
 	  /* Make sure we are dealing with a target that supports ARMv8.1-m
 	     PACBTI.  */
@@ -1844,7 +1844,7 @@ arm_analyze_prologue (struct gdbarch *gdbarch,
   CORE_ADDR offset, current_pc;
   pv_t regs[ARM_FPS_REGNUM];
   CORE_ADDR unrecognized_pc = 0;
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Search the prologue looking for instructions that set up the
      frame pointer, adjust the stack pointer, and save registers.
@@ -2088,7 +2088,7 @@ arm_scan_prologue (struct frame_info *this_frame,
   CORE_ADDR prologue_start, prologue_end;
   CORE_ADDR prev_pc = get_frame_pc (this_frame);
   CORE_ADDR block_addr = get_frame_address_in_block (this_frame);
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Assume there is no frame until proven otherwise.  */
   cache->framereg = ARM_SP_REGNUM;
@@ -2193,7 +2193,7 @@ arm_make_prologue_cache (struct frame_info *this_frame)
     return cache;
 
   arm_gdbarch_tdep *tdep =
-    (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
 
   prev_sp = unwound_fp + cache->framesize;
   arm_cache_set_active_sp_value (cache, tdep, prev_sp);
@@ -2224,7 +2224,7 @@ arm_prologue_unwind_stop_reason (struct frame_info *this_frame,
   /* This is meant to halt the backtrace at "_start".  */
   pc = get_frame_pc (this_frame);
   gdbarch *arch = get_frame_arch (this_frame);
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (arch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (arch);
   if (pc <= tdep->lowest_pc)
     return UNWIND_OUTERMOST;
 
@@ -2252,7 +2252,7 @@ arm_prologue_this_id (struct frame_info *this_frame,
   cache = (struct arm_prologue_cache *) *this_cache;
 
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
 
   /* Use function start address as part of the frame ID.  If we cannot
      identify the start address (due to missing symbol information),
@@ -2279,7 +2279,7 @@ arm_prologue_prev_register (struct frame_info *this_frame,
     *this_cache = arm_make_prologue_cache (this_frame);
   cache = (struct arm_prologue_cache *) *this_cache;
 
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* If this frame has signed the return address, mark it as so.  */
   if (tdep->have_pacbti && cache->ra_signed_state.has_value ()
@@ -2952,7 +2952,7 @@ arm_exidx_fill_cache (struct frame_info *this_frame, gdb_byte *entry)
 
   /* We already got the previous SP.  */
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   arm_cache_set_active_sp_value (cache, tdep, vsp);
 
   return cache;
@@ -3077,7 +3077,7 @@ arm_make_epilogue_frame_cache (struct frame_info *this_frame)
 
   /* Since we are in epilogue, the SP has been restored.  */
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   arm_cache_set_active_sp_value (cache, tdep,
 				 get_frame_register_unsigned (this_frame,
 							      ARM_SP_REGNUM));
@@ -3116,7 +3116,7 @@ arm_epilogue_frame_this_id (struct frame_info *this_frame,
     func = pc;
 
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   *this_id = frame_id_build (arm_cache_get_prev_sp_value (cache, tdep), pc);
 }
 
@@ -3240,7 +3240,7 @@ arm_make_stub_cache (struct frame_info *this_frame)
   arm_cache_init (cache, this_frame);
 
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   arm_cache_set_active_sp_value (cache, tdep,
 				 get_frame_register_unsigned (this_frame,
 							      ARM_SP_REGNUM));
@@ -3262,7 +3262,7 @@ arm_stub_this_id (struct frame_info *this_frame,
   cache = (struct arm_prologue_cache *) *this_cache;
 
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   *this_id = frame_id_build (arm_cache_get_prev_sp_value (cache, tdep),
 			     get_frame_pc (this_frame));
 }
@@ -3310,7 +3310,7 @@ static struct arm_prologue_cache *
 arm_m_exception_cache (struct frame_info *this_frame)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct arm_prologue_cache *cache;
   CORE_ADDR lr;
@@ -3597,7 +3597,7 @@ arm_m_exception_this_id (struct frame_info *this_frame,
 
   /* Our frame ID for a stub frame is the current SP and LR.  */
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   *this_id = frame_id_build (arm_cache_get_prev_sp_value (cache, tdep),
 			     get_frame_pc (this_frame));
 }
@@ -3619,7 +3619,7 @@ arm_m_exception_prev_register (struct frame_info *this_frame,
 
   /* The value was already reconstructed into PREV_SP.  */
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   if (prev_regnum == ARM_SP_REGNUM)
     return frame_unwind_got_constant (this_frame, prev_regnum,
 				      arm_cache_get_prev_sp_value (cache, tdep));
@@ -3677,7 +3677,7 @@ arm_normal_frame_base (struct frame_info *this_frame, void **this_cache)
   cache = (struct arm_prologue_cache *) *this_cache;
 
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   return arm_cache_get_prev_sp_value (cache, tdep) - cache->framesize;
 }
 
@@ -3693,7 +3693,7 @@ arm_dwarf2_prev_register (struct frame_info *this_frame, void **this_cache,
 			  int regnum)
 {
   struct gdbarch * gdbarch = get_frame_arch (this_frame);
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   CORE_ADDR lr, cpsr;
   ULONGEST t_bit = arm_psr_thumb_bit (gdbarch);
 
@@ -4220,7 +4220,7 @@ arm_vfp_call_candidate (struct type *t, enum arm_vfp_cprc_base_type *base_type,
 static int
 arm_vfp_abi_for_function (struct gdbarch *gdbarch, struct type *func_type)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Variadic functions always use the base ABI.  Assume that functions
      without debug info are not variadic.  */
@@ -4254,7 +4254,7 @@ arm_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   int use_vfp_abi;
   struct type *ftype;
   unsigned vfp_regs_free = (1 << 16) - 1;
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Determine the type of this function and whether the VFP ABI
      applies.  */
@@ -4526,7 +4526,7 @@ arm_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
 static struct type *
 arm_ext_type (struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (!tdep->arm_ext_type)
     tdep->arm_ext_type
@@ -4539,7 +4539,7 @@ arm_ext_type (struct gdbarch *gdbarch)
 static struct type *
 arm_neon_double_type (struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->neon_double_type == NULL)
     {
@@ -4578,7 +4578,7 @@ arm_neon_double_type (struct gdbarch *gdbarch)
 static struct type *
 arm_neon_quad_type (struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->neon_quad_type == NULL)
     {
@@ -4616,7 +4616,7 @@ arm_neon_quad_type (struct gdbarch *gdbarch)
 static bool
 is_q_pseudo (struct gdbarch *gdbarch, int regnum)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Q pseudo registers are available for both NEON (Q0~Q15) and
      MVE (Q0~Q7) features.  */
@@ -4637,7 +4637,7 @@ is_q_pseudo (struct gdbarch *gdbarch, int regnum)
 static bool
 is_s_pseudo (struct gdbarch *gdbarch, int regnum)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->have_s_pseudos
       && regnum >= tdep->s_pseudo_base
@@ -4656,7 +4656,7 @@ is_s_pseudo (struct gdbarch *gdbarch, int regnum)
 static bool
 is_mve_pseudo (struct gdbarch *gdbarch, int regnum)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->have_mve
       && regnum >= tdep->mve_pseudo_base
@@ -4675,7 +4675,7 @@ is_mve_pseudo (struct gdbarch *gdbarch, int regnum)
 static bool
 is_pacbti_pseudo (struct gdbarch *gdbarch, int regnum)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->have_pacbti
       && regnum >= tdep->pacbti_pseudo_base
@@ -4691,7 +4691,7 @@ is_pacbti_pseudo (struct gdbarch *gdbarch, int regnum)
 static struct type *
 arm_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (is_s_pseudo (gdbarch, regnum))
     return builtin_type (gdbarch)->builtin_float;
@@ -4770,7 +4770,7 @@ arm_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
   /* PACBTI register containing the Pointer Authentication Code.  */
   if (reg == ARM_DWARF_RA_AUTH_CODE)
     {
-      arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
       if (tdep->have_pacbti)
 	return tdep->pacbti_pseudo_base;
@@ -4916,7 +4916,7 @@ arm_adjust_breakpoint_address (struct gdbarch *gdbarch, CORE_ADDR bpaddr)
   int buf_len;
   enum bfd_endian order = gdbarch_byte_order_for_code (gdbarch);
   int i, any, last_it, last_it_count;
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* If we are using BKPT breakpoints, none of this is necessary.  */
   if (tdep->thumb2_breakpoint == NULL)
@@ -8224,7 +8224,7 @@ arm_displaced_init_closure (struct gdbarch *gdbarch, CORE_ADDR from,
 			    CORE_ADDR to,
 			    arm_displaced_step_copy_insn_closure *dsc)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   unsigned int i, len, offset;
   enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
   int size = dsc->is_thumb? 2 : 4;
@@ -8387,7 +8387,7 @@ static const gdb_byte arm_default_thumb_be_breakpoint[] = THUMB_BE_BREAKPOINT;
 static int
 arm_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
 
   if (arm_pc_is_thumb (gdbarch, *pcptr))
@@ -8422,7 +8422,7 @@ arm_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 static const gdb_byte *
 arm_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   switch (kind)
     {
@@ -8494,7 +8494,7 @@ arm_extract_return_value (struct type *type, struct regcache *regs,
 {
   struct gdbarch *gdbarch = regs->arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (TYPE_CODE_FLT == type->code ())
     {
@@ -8605,7 +8605,7 @@ arm_return_in_memory (struct gdbarch *gdbarch, struct type *type)
       return (TYPE_LENGTH (type) > 16);
     }
 
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   if (tdep->arm_abi != ARM_ABI_APCS)
     {
       /* The AAPCS says all aggregates not larger than a word are returned
@@ -8711,7 +8711,7 @@ arm_store_return_value (struct type *type, struct regcache *regs,
   if (type->code () == TYPE_CODE_FLT)
     {
       gdb_byte buf[ARM_FP_REGISTER_SIZE];
-      arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
       switch (tdep->fp_model)
 	{
@@ -8800,7 +8800,7 @@ arm_return_value (struct gdbarch *gdbarch, struct value *function,
 		  struct type *valtype, struct regcache *regcache,
 		  gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   struct type *func_type = function ? value_type (function) : NULL;
   enum arm_vfp_cprc_base_type vfp_base_type;
   int vfp_base_count;
@@ -8892,7 +8892,7 @@ static int
 arm_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR jb_addr;
   gdb_byte buf[ARM_INT_REGISTER_SIZE];
@@ -9085,7 +9085,7 @@ show_fp_model (struct ui_file *file, int from_tty,
       && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm)
     {
       arm_gdbarch_tdep *tdep
-	= (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+	= gdbarch_tdep<arm_gdbarch_tdep> (target_gdbarch ());
 
       gdb_printf (file, _("\
 The current ARM floating point model is \"auto\" (currently \"%s\").\n"),
@@ -9125,7 +9125,7 @@ arm_show_abi (struct ui_file *file, int from_tty,
       && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm)
     {
       arm_gdbarch_tdep *tdep
-	= (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+	= gdbarch_tdep<arm_gdbarch_tdep> (target_gdbarch ());
 
       gdb_printf (file, _("\
 The current ARM ABI is \"auto\" (currently \"%s\").\n"),
@@ -9204,7 +9204,7 @@ show_disassembly_style_sfunc (struct ui_file *file, int from_tty,
 static const char *
 arm_register_name (struct gdbarch *gdbarch, int i)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (is_s_pseudo (gdbarch, i))
     {
@@ -9375,7 +9375,7 @@ static enum register_status
 arm_mve_pseudo_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 		     int regnum, gdb_byte *buf)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* P0 is the first 16 bits of VPR.  */
   return regcache->raw_read_part (tdep->mve_vpr_regnum, 0, 2, buf);
@@ -9389,7 +9389,7 @@ arm_pseudo_read (struct gdbarch *gdbarch, readable_regcache *regcache,
   char name_buf[4];
   gdb_byte reg_buf[8];
   int offset, double_regnum;
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   gdb_assert (regnum >= num_regs);
 
@@ -9461,7 +9461,7 @@ static void
 arm_mve_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache,
 		      int regnum, const gdb_byte *buf)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* P0 is the first 16 bits of VPR.  */
   regcache->raw_write_part (tdep->mve_vpr_regnum, 0, 2, buf);
@@ -9475,7 +9475,7 @@ arm_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache,
   char name_buf[4];
   gdb_byte reg_buf[8];
   int offset, double_regnum;
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   gdb_assert (regnum >= num_regs);
 
@@ -9563,7 +9563,7 @@ arm_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 static void
 arm_register_g_packet_guesses (struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->is_m)
     {
@@ -9606,7 +9606,7 @@ arm_register_g_packet_guesses (struct gdbarch *gdbarch)
 static int
 arm_code_of_frame_writable (struct gdbarch *gdbarch, struct frame_info *frame)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->is_m && get_frame_type (frame) == SIGTRAMP_FRAME)
     {
@@ -10165,7 +10165,7 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
     {
       arm_gdbarch_tdep *tdep
-	= (arm_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
+	= gdbarch_tdep<arm_gdbarch_tdep> (best_arch->gdbarch);
 
       if (arm_abi != ARM_ABI_AUTO && arm_abi != tdep->arm_abi)
 	continue;
@@ -10485,7 +10485,7 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 arm_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep == NULL)
     return;
@@ -12694,7 +12694,7 @@ arm_record_coproc_data_proc (arm_insn_decode_record *arm_insn_r)
 {
   uint32_t op, op1_ebit, coproc, bits_24_25;
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (arm_insn_r->gdbarch);
+    = gdbarch_tdep<arm_gdbarch_tdep> (arm_insn_r->gdbarch);
   struct regcache *reg_cache = arm_insn_r->regcache;
 
   arm_insn_r->opcode = bits (arm_insn_r->arm_insn, 24, 27);
@@ -13182,7 +13182,7 @@ static int
 thumb_record_ldm_stm_swi (arm_insn_decode_record *thumb_insn_r)
 {
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep  (thumb_insn_r->gdbarch);
+    = gdbarch_tdep<arm_gdbarch_tdep>  (thumb_insn_r->gdbarch);
   struct regcache *reg_cache = thumb_insn_r->regcache;
 
   uint32_t ret = 0; /* function return value: -1:record failure ;  0:success  */
diff --git a/gdb/arm-wince-tdep.c b/gdb/arm-wince-tdep.c
index 354c6fbca7f..5063b308809 100644
--- a/gdb/arm-wince-tdep.c
+++ b/gdb/arm-wince-tdep.c
@@ -115,7 +115,7 @@ arm_wince_skip_main_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
 static void
 arm_wince_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   windows_init_abi (info, gdbarch);
 
diff --git a/gdb/avr-tdep.c b/gdb/avr-tdep.c
index e103045cb23..4722f7ee748 100644
--- a/gdb/avr-tdep.c
+++ b/gdb/avr-tdep.c
@@ -232,7 +232,7 @@ avr_register_type (struct gdbarch *gdbarch, int reg_nr)
   if (reg_nr == AVR_PC_REGNUM)
     return builtin_type (gdbarch)->builtin_uint32;
 
-  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
   if (reg_nr == AVR_PSEUDO_PC_REGNUM)
     return tdep->pc_type;
 
@@ -750,7 +750,7 @@ avr_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR pc_beg, CORE_ADDR pc_end,
   gdb_assert (vpc < AVR_MAX_PROLOGUE_SIZE);
 
   /* Handle static small stack allocation using rcall or push.  */
-  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
   while (scan_stage == 1 && vpc < len)
     {
       insn = extract_unsigned_integer (&prologue[vpc], 2, byte_order);
@@ -1053,7 +1053,7 @@ avr_frame_unwind_cache (struct frame_info *this_frame,
 
   /* The previous frame's SP needed to be computed.  Save the computed
      value.  */
-  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
   info->saved_regs[AVR_SP_REGNUM].set_value (info->prev_sp
 					     - 1 + tdep->call_length);
 
@@ -1135,7 +1135,7 @@ avr_frame_prev_register (struct frame_info *this_frame,
 	  int i;
 	  gdb_byte buf[3];
 	  struct gdbarch *gdbarch = get_frame_arch (this_frame);
-	  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
 
 	  read_memory (info->saved_regs[AVR_PC_REGNUM].addr (),
 		       buf, tdep->call_length);
@@ -1277,7 +1277,7 @@ avr_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 {
   int i;
   gdb_byte buf[3];
-  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
   int call_length = tdep->call_length;
   CORE_ADDR return_pc = avr_convert_iaddr_to_raw (bp_addr);
   int regnum = AVR_ARGN_REGNUM;
@@ -1461,7 +1461,7 @@ avr_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
     {
       avr_gdbarch_tdep *tdep
-	= (avr_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
+	= gdbarch_tdep<avr_gdbarch_tdep> (best_arch->gdbarch);
 
       if (tdep->call_length == call_length)
 	return best_arch->gdbarch;
diff --git a/gdb/bfin-tdep.c b/gdb/bfin-tdep.c
index 573eed94793..f232e22c37c 100644
--- a/gdb/bfin-tdep.c
+++ b/gdb/bfin-tdep.c
@@ -766,7 +766,7 @@ bfin_frame_align (struct gdbarch *gdbarch, CORE_ADDR address)
 enum bfin_abi
 bfin_abi (struct gdbarch *gdbarch)
 {
-  bfin_gdbarch_tdep *tdep = (bfin_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  bfin_gdbarch_tdep *tdep = gdbarch_tdep<bfin_gdbarch_tdep> (gdbarch);
   return tdep->bfin_abi;
 }
 
@@ -792,7 +792,7 @@ bfin_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       bfin_gdbarch_tdep *tdep
-	= (bfin_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<bfin_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->bfin_abi != abi)
 	continue;
diff --git a/gdb/cris-linux-tdep.c b/gdb/cris-linux-tdep.c
index f55f9b9083c..b3ed7450e99 100644
--- a/gdb/cris-linux-tdep.c
+++ b/gdb/cris-linux-tdep.c
@@ -33,7 +33,7 @@
 static void
 cris_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/cris-tdep.c b/gdb/cris-tdep.c
index efd728a5229..73110d97f2f 100644
--- a/gdb/cris-tdep.c
+++ b/gdb/cris-tdep.c
@@ -313,7 +313,7 @@ cris_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
 				  void **this_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct cris_unwind_cache *info;
   CORE_ADDR addr;
@@ -450,7 +450,7 @@ static int
 crisv32_single_step_through_delay (struct gdbarch *gdbarch,
 				   struct frame_info *this_frame)
 {
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   ULONGEST erp;
   int ret = 0;
 
@@ -696,7 +696,7 @@ cris_frame_unwind_cache (struct frame_info *this_frame,
 			 void **this_prologue_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   struct cris_unwind_cache *info;
 
   if ((*this_prologue_cache))
@@ -1334,7 +1334,7 @@ crisv32_scan_prologue (CORE_ADDR pc, struct frame_info *this_frame,
 static CORE_ADDR
 cris_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   CORE_ADDR func_addr, func_end;
   struct symtab_and_line sal;
   CORE_ADDR pc_after_prologue;
@@ -1369,7 +1369,7 @@ cris_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 static const gdb_byte *
 cris_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   static unsigned char break8_insn[] = {0x38, 0xe9};
   static unsigned char break15_insn[] = {0x3f, 0xe9};
 
@@ -1388,7 +1388,7 @@ static int
 cris_spec_reg_applicable (struct gdbarch *gdbarch,
 			  struct cris_spec_reg spec_reg)
 {
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   unsigned int version = tdep->cris_version;
   
   switch (spec_reg.applicable_version)
@@ -3767,7 +3767,7 @@ cris_supply_gregset (const struct regset *regset, struct regcache *regcache,
 		     int regnum, const void *gregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   int i;
   const cris_elf_greg_t *regp = static_cast<const cris_elf_greg_t *>(gregs);
 
@@ -3861,7 +3861,7 @@ Makes GDB use the NRP register instead of the ERP register in certain cases."),
 static void
 cris_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   if (tdep != NULL)
     {
       gdb_printf (file, "cris_dump_tdep: tdep->cris_version = %i\n",
@@ -3941,7 +3941,7 @@ cris_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       cris_gdbarch_tdep *tdep
-	= (cris_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<cris_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->cris_version == usr_cmd_cris_version
 	  && tdep->cris_mode == usr_cmd_cris_mode
diff --git a/gdb/csky-tdep.c b/gdb/csky-tdep.c
index 7a9c38c0064..76d2ccf5eef 100644
--- a/gdb/csky-tdep.c
+++ b/gdb/csky-tdep.c
@@ -2665,7 +2665,7 @@ csky_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       csky_gdbarch_tdep *tdep
-        = (csky_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<csky_gdbarch_tdep> (arches->gdbarch);
       if (fpu_abi != tdep->fpu_abi)
         continue;
       if (vdsp_version != tdep->vdsp_version)
diff --git a/gdb/frv-tdep.c b/gdb/frv-tdep.c
index 2328791a540..34f437764a9 100644
--- a/gdb/frv-tdep.c
+++ b/gdb/frv-tdep.c
@@ -93,7 +93,7 @@ struct frv_gdbarch_tdep : gdbarch_tdep
 enum frv_abi
 frv_abi (struct gdbarch *gdbarch)
 {
-  frv_gdbarch_tdep *tdep = (frv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  frv_gdbarch_tdep *tdep = gdbarch_tdep<frv_gdbarch_tdep> (gdbarch);
   return tdep->frv_abi;
 }
 
@@ -275,7 +275,7 @@ frv_register_name (struct gdbarch *gdbarch, int reg)
   if (reg >= frv_num_regs + frv_num_pseudo_regs)
     return "?toolarge?";
 
-  frv_gdbarch_tdep *tdep = (frv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  frv_gdbarch_tdep *tdep = gdbarch_tdep<frv_gdbarch_tdep> (gdbarch);
   return tdep->register_names[reg];
 }
 
diff --git a/gdb/ft32-tdep.c b/gdb/ft32-tdep.c
index f77e313e0dd..024ca47ce4d 100644
--- a/gdb/ft32-tdep.c
+++ b/gdb/ft32-tdep.c
@@ -110,7 +110,7 @@ ft32_register_type (struct gdbarch *gdbarch, int reg_nr)
 {
   if (reg_nr == FT32_PC_REGNUM)
     {
-      ft32_gdbarch_tdep *tdep = (ft32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      ft32_gdbarch_tdep *tdep = gdbarch_tdep<ft32_gdbarch_tdep> (gdbarch);
       return tdep->pc_type;
     }
   else if (reg_nr == FT32_SP_REGNUM || reg_nr == FT32_FP_REGNUM)
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index 3a7b7f92ef7..b2c91db0c4f 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -142,8 +142,23 @@ using read_core_file_mappings_loop_ftype =
 
 #include "gdbarch-gen.h"
 
-extern struct gdbarch_tdep *gdbarch_tdep (struct gdbarch *gdbarch);
+/* An internal function that should _only_ be called from gdbarch_tdep.
+   Returns the gdbarch_tdep field held within GDBARCH.  */
 
+extern struct gdbarch_tdep *gdbarch_tdep_1 (struct gdbarch *gdbarch);
+
+/* Return the gdbarch_tdep object held within GDBARCH cast to the type
+   TDepType, which should be a sub-class of gdbarch_tdep.  There is no
+   checking done that the gdbarch_tdep within GDBARCH actually is of the
+   type TDepType, we just assume the caller knows what they are doing.  */
+
+template<typename TDepType>
+static inline TDepType *
+gdbarch_tdep (struct gdbarch *gdbarch)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep_1 (gdbarch);
+  return static_cast<TDepType *> (tdep);
+}
 
 /* Mechanism for co-ordinating the selection of a specific
    architecture.
diff --git a/gdb/hppa-bsd-tdep.c b/gdb/hppa-bsd-tdep.c
index 34f57d2512a..c405511529d 100644
--- a/gdb/hppa-bsd-tdep.c
+++ b/gdb/hppa-bsd-tdep.c
@@ -118,7 +118,7 @@ hppabsd_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
 void
 hppabsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
 
   /* OpenBSD and NetBSD have a 64-bit 'long double'.  */
   set_gdbarch_long_double_bit (gdbarch, 64);
diff --git a/gdb/hppa-linux-tdep.c b/gdb/hppa-linux-tdep.c
index 40e32c115d2..f17d2ae6b02 100644
--- a/gdb/hppa-linux-tdep.c
+++ b/gdb/hppa-linux-tdep.c
@@ -476,7 +476,7 @@ hppa_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					 void *cb_data,
 					 const struct regcache *regcache)
 {
-  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
 
   cb (".reg", 80 * tdep->bytes_per_address, 80 * tdep->bytes_per_address,
       &hppa_linux_regset, NULL, cb_data);
@@ -486,7 +486,7 @@ hppa_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 static void
 hppa_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/hppa-tdep.c b/gdb/hppa-tdep.c
index f9ececbb04f..9f93a945a6a 100644
--- a/gdb/hppa-tdep.c
+++ b/gdb/hppa-tdep.c
@@ -247,7 +247,7 @@ internalize_unwinds (struct objfile *objfile, struct unwind_table_entry *table,
   if (size > 0)
     {
       struct gdbarch *gdbarch = objfile->arch ();
-      hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
       unsigned long tmp;
       unsigned i;
       char *buf = (char *) alloca (size);
@@ -718,7 +718,7 @@ hppa32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   /* Global pointer (r19) of the function we are trying to call.  */
   CORE_ADDR gp;
 
-  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
 
   for (write_pass = 0; write_pass < 2; write_pass++)
     {
@@ -955,7 +955,7 @@ hppa64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 			function_call_return_method return_method,
 			CORE_ADDR struct_addr)
 {
-  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int i, offset = 0;
   CORE_ADDR gp;
@@ -2241,7 +2241,7 @@ hppa_frame_cache (struct frame_info *this_frame, void **this_cache)
   }
 
   {
-    hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+    hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
 
     if (tdep->unwind_adjust_stub)
       tdep->unwind_adjust_stub (this_frame, cache->base, cache->saved_regs);
@@ -2471,7 +2471,7 @@ hppa_stub_unwind_sniffer (const struct frame_unwind *self,
 {
   CORE_ADDR pc = get_frame_address_in_block (this_frame);
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
 
   if (pc == 0
       || (tdep->in_solib_call_trampoline != NULL
@@ -3147,7 +3147,7 @@ hppa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 hppa_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
 
   gdb_printf (file, "bytes_per_address = %d\n", 
 	      tdep->bytes_per_address);
diff --git a/gdb/i386-bsd-tdep.c b/gdb/i386-bsd-tdep.c
index b38f8d05887..dbbd3c786c3 100644
--- a/gdb/i386-bsd-tdep.c
+++ b/gdb/i386-bsd-tdep.c
@@ -74,7 +74,7 @@ int i386bsd_sc_reg_offset[] =
 void
 i386bsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   tdep->jb_pc_offset = 0;
 
diff --git a/gdb/i386-darwin-tdep.c b/gdb/i386-darwin-tdep.c
index dc780583766..2a9198aceb3 100644
--- a/gdb/i386-darwin-tdep.c
+++ b/gdb/i386-darwin-tdep.c
@@ -156,7 +156,7 @@ i386_darwin_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 			     function_call_return_method return_method,
 			     CORE_ADDR struct_addr)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   gdb_byte buf[4];
   int i;
@@ -248,7 +248,7 @@ i386_darwin_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 static void
 i386_darwin_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* We support the SSE registers.  */
   tdep->num_xmm_regs = I386_NUM_XREGS - 1;
diff --git a/gdb/i386-fbsd-tdep.c b/gdb/i386-fbsd-tdep.c
index d68498cd5e9..b7a524db68c 100644
--- a/gdb/i386-fbsd-tdep.c
+++ b/gdb/i386-fbsd-tdep.c
@@ -325,7 +325,7 @@ i386fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				       void *cb_data,
 				       const struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   cb (".reg", I386_FBSD_SIZEOF_GREGSET, I386_FBSD_SIZEOF_GREGSET,
       &i386_fbsd_gregset, NULL, cb_data);
@@ -365,7 +365,7 @@ i386fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 static void
 i386fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support. */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/i386-gnu-tdep.c b/gdb/i386-gnu-tdep.c
index 51c253d2dfe..3d97fe36a85 100644
--- a/gdb/i386-gnu-tdep.c
+++ b/gdb/i386-gnu-tdep.c
@@ -173,7 +173,7 @@ static int i386gnu_gregset_reg_offset[] =
 static void
 i386gnu_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* GNU uses ELF.  */
   i386_elf_init_abi (info, gdbarch);
diff --git a/gdb/i386-go32-tdep.c b/gdb/i386-go32-tdep.c
index 15ac38dc12f..0c0c08e3579 100644
--- a/gdb/i386-go32-tdep.c
+++ b/gdb/i386-go32-tdep.c
@@ -26,7 +26,7 @@
 static void
 i386_go32_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* DJGPP doesn't have any special frames for signal handlers.  */
   tdep->sigtramp_p = NULL;
diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c
index 5d7f54194af..6033104230f 100644
--- a/gdb/i386-linux-tdep.c
+++ b/gdb/i386-linux-tdep.c
@@ -763,7 +763,7 @@ i386_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					 void *cb_data,
 					 const struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   cb (".reg", 68, 68, &i386_gregset, NULL, cb_data);
 
@@ -825,7 +825,7 @@ i386_linux_displaced_step_copy_insn (struct gdbarch *gdbarch,
 static void
 i386_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   const struct target_desc *tdesc = info.target_desc;
   struct tdesc_arch_data *tdesc_data = info.tdesc_data;
   const struct tdesc_feature *feature;
diff --git a/gdb/i386-netbsd-tdep.c b/gdb/i386-netbsd-tdep.c
index 2cee1b94760..a9ebc3dd827 100644
--- a/gdb/i386-netbsd-tdep.c
+++ b/gdb/i386-netbsd-tdep.c
@@ -372,7 +372,7 @@ i386nbsd_sigtramp_cache_init (const struct tramp_frame *self,
 static void 
 i386nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* Obviously NetBSD is BSD-based.  */
   i386bsd_init_abi (info, gdbarch);
@@ -407,7 +407,7 @@ i386nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 static void
 i386nbsdelf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* It's still NetBSD.  */
   i386nbsd_init_abi (info, gdbarch);
diff --git a/gdb/i386-nto-tdep.c b/gdb/i386-nto-tdep.c
index 6716329149b..259867f262b 100644
--- a/gdb/i386-nto-tdep.c
+++ b/gdb/i386-nto-tdep.c
@@ -77,7 +77,7 @@ static void
 i386nto_supply_gregset (struct regcache *regcache, char *gpregs)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   gdb_assert (tdep->gregset_reg_offset == i386nto_gregset_reg_offset);
   i386_gregset.supply_regset (&i386_gregset, regcache, -1,
@@ -126,7 +126,7 @@ static int
 i386nto_register_area (struct gdbarch *gdbarch,
 		       int regno, int regset, unsigned *off)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   *off = 0;
   if (regset == NTO_REG_GENERAL)
@@ -315,7 +315,7 @@ init_i386nto_ops (void)
 static void
 i386nto_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   static struct target_so_ops nto_svr4_so_ops;
 
   /* Deal with our strange signals.  */
diff --git a/gdb/i386-obsd-tdep.c b/gdb/i386-obsd-tdep.c
index b1f4d6c5e8d..798094509c6 100644
--- a/gdb/i386-obsd-tdep.c
+++ b/gdb/i386-obsd-tdep.c
@@ -407,7 +407,7 @@ static const struct frame_unwind i386obsd_trapframe_unwind = {
 static void 
 i386obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* Obviously OpenBSD is BSD-based.  */
   i386bsd_init_abi (info, gdbarch);
diff --git a/gdb/i386-sol2-tdep.c b/gdb/i386-sol2-tdep.c
index e8a3ba20045..5ee108d3578 100644
--- a/gdb/i386-sol2-tdep.c
+++ b/gdb/i386-sol2-tdep.c
@@ -65,7 +65,7 @@ i386_sol2_mcontext_addr (struct frame_info *this_frame)
 static void
 i386_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* Solaris is SVR4-based.  */
   i386_svr4_init_abi (info, gdbarch);
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 8501e12e241..d500f6998c5 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -169,7 +169,7 @@ const int num_lower_zmm_regs = 16;
 static int
 i386_mmx_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int mm0_regnum = tdep->mm0_regnum;
 
   if (mm0_regnum < 0)
@@ -184,7 +184,7 @@ i386_mmx_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_byte_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   regnum -= tdep->al_regnum;
   return regnum >= 0 && regnum < tdep->num_byte_regs;
@@ -195,7 +195,7 @@ i386_byte_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_word_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   regnum -= tdep->ax_regnum;
   return regnum >= 0 && regnum < tdep->num_word_regs;
@@ -206,7 +206,7 @@ i386_word_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_dword_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int eax_regnum = tdep->eax_regnum;
 
   if (eax_regnum < 0)
@@ -221,7 +221,7 @@ i386_dword_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_zmmh_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int zmm0h_regnum = tdep->zmm0h_regnum;
 
   if (zmm0h_regnum < 0)
@@ -234,7 +234,7 @@ i386_zmmh_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_zmm_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int zmm0_regnum = tdep->zmm0_regnum;
 
   if (zmm0_regnum < 0)
@@ -247,7 +247,7 @@ i386_zmm_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_k_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int k0_regnum = tdep->k0_regnum;
 
   if (k0_regnum < 0)
@@ -260,7 +260,7 @@ i386_k_regnum_p (struct gdbarch *gdbarch, int regnum)
 static int
 i386_ymmh_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int ymm0h_regnum = tdep->ymm0h_regnum;
 
   if (ymm0h_regnum < 0)
@@ -275,7 +275,7 @@ i386_ymmh_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_ymm_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int ymm0_regnum = tdep->ymm0_regnum;
 
   if (ymm0_regnum < 0)
@@ -288,7 +288,7 @@ i386_ymm_regnum_p (struct gdbarch *gdbarch, int regnum)
 static int
 i386_ymmh_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int ymm16h_regnum = tdep->ymm16h_regnum;
 
   if (ymm16h_regnum < 0)
@@ -301,7 +301,7 @@ i386_ymmh_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_ymm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int ymm16_regnum = tdep->ymm16_regnum;
 
   if (ymm16_regnum < 0)
@@ -316,7 +316,7 @@ i386_ymm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_bnd_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int bnd0_regnum = tdep->bnd0_regnum;
 
   if (bnd0_regnum < 0)
@@ -331,7 +331,7 @@ i386_bnd_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_xmm_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int num_xmm_regs = I387_NUM_XMM_REGS (tdep);
 
   if (num_xmm_regs == 0)
@@ -346,7 +346,7 @@ i386_xmm_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_xmm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int num_xmm_avx512_regs = I387_NUM_XMM_AVX512_REGS (tdep);
 
   if (num_xmm_avx512_regs == 0)
@@ -359,7 +359,7 @@ i386_xmm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 static int
 i386_mxcsr_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (I387_NUM_XMM_REGS (tdep) == 0)
     return 0;
@@ -372,7 +372,7 @@ i386_mxcsr_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_fp_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (I387_ST0_REGNUM (tdep) < 0)
     return 0;
@@ -384,7 +384,7 @@ i386_fp_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_fpc_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (I387_ST0_REGNUM (tdep) < 0)
     return 0;
@@ -398,7 +398,7 @@ i386_fpc_regnum_p (struct gdbarch *gdbarch, int regnum)
 static int
 i386_bndr_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
    if (I387_BND0R_REGNUM (tdep) < 0)
      return 0;
@@ -412,7 +412,7 @@ i386_bndr_regnum_p (struct gdbarch *gdbarch, int regnum)
 static int
 i386_mpx_ctrl_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
    if (I387_BNDCFGU_REGNUM (tdep) < 0)
      return 0;
@@ -426,7 +426,7 @@ i386_mpx_ctrl_regnum_p (struct gdbarch *gdbarch, int regnum)
 bool
 i386_pkru_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int pkru_regnum = tdep->pkru_regnum;
 
   if (pkru_regnum < 0)
@@ -462,7 +462,7 @@ i386_register_name (struct gdbarch *gdbarch, int regnum)
 const char *
 i386_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   if (i386_bnd_regnum_p (gdbarch, regnum))
     return i386_bnd_names[regnum - tdep->bnd0_regnum];
   if (i386_mmx_regnum_p (gdbarch, regnum))
@@ -485,7 +485,7 @@ i386_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 static int
 i386_dbx_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* This implements what GCC calls the "default" register map
      (dbx_register_map[]).  */
@@ -532,7 +532,7 @@ i386_dbx_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 static int
 i386_svr4_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* This implements the GCC register map that tries to be compatible
      with the SVR4 C compiler for DWARF (svr4_dbx_register_map[]).  */
@@ -2434,7 +2434,7 @@ static struct i386_frame_cache *
 i386_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct i386_frame_cache *cache;
   CORE_ADDR addr;
@@ -2524,7 +2524,7 @@ i386_sigtramp_frame_sniffer (const struct frame_unwind *self,
 			     void **this_prologue_cache)
 {
   gdbarch *arch = get_frame_arch (this_frame);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
 
   /* We shouldn't even bother if we don't have a sigcontext_addr
      handler.  */
@@ -2611,7 +2611,7 @@ i386_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
   CORE_ADDR sp, jb_addr;
   struct gdbarch *gdbarch = get_frame_arch (frame);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int jb_pc_offset = tdep->jb_pc_offset;
 
   /* If JB_PC_OFFSET is -1, we have no way to find out where the
@@ -2860,7 +2860,7 @@ static void
 i386_extract_return_value (struct gdbarch *gdbarch, struct type *type,
 			   struct regcache *regcache, gdb_byte *valbuf)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int len = TYPE_LENGTH (type);
   gdb_byte buf[I386_MAX_REGISTER_SIZE];
 
@@ -2918,7 +2918,7 @@ static void
 i386_store_return_value (struct gdbarch *gdbarch, struct type *type,
 			 struct regcache *regcache, const gdb_byte *valbuf)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int len = TYPE_LENGTH (type);
 
   if (type->code () == TYPE_CODE_FLT)
@@ -2997,7 +2997,7 @@ static const char *struct_convention = default_struct_convention;
 static int
 i386_reg_struct_return_p (struct gdbarch *gdbarch, struct type *type)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   enum type_code code = type->code ();
   int len = TYPE_LENGTH (type);
 
@@ -3099,7 +3099,7 @@ i386_return_value (struct gdbarch *gdbarch, struct value *function,
 struct type *
 i387_ext_type (struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (!tdep->i387_ext_type)
     {
@@ -3117,7 +3117,7 @@ i387_ext_type (struct gdbarch *gdbarch)
 static struct type *
 i386_bnd_type (struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
 
   if (!tdep->i386_bnd_type)
@@ -3153,7 +3153,7 @@ i386_bnd_type (struct gdbarch *gdbarch)
 static struct type *
 i386_zmm_type (struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (!tdep->i386_zmm_type)
     {
@@ -3212,7 +3212,7 @@ i386_zmm_type (struct gdbarch *gdbarch)
 static struct type *
 i386_ymm_type (struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (!tdep->i386_ymm_type)
     {
@@ -3269,7 +3269,7 @@ i386_ymm_type (struct gdbarch *gdbarch)
 static struct type *
 i386_mmx_type (struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (!tdep->i386_mmx_type)
     {
@@ -3346,7 +3346,7 @@ static int
 i386_mmx_regnum_to_fp_regnum (readable_regcache *regcache, int regnum)
 {
   gdbarch *arch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
   int mmxreg, fpreg;
   ULONGEST fstat;
   int tos;
@@ -3387,7 +3387,7 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
     }
   else
     {
-      i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
       if (i386_bnd_regnum_p (gdbarch, regnum))
 	{
 	  regnum -= tdep->bnd0_regnum;
@@ -3577,7 +3577,7 @@ i386_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
     }
   else
     {
-      i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
       if (i386_bnd_regnum_p (gdbarch, regnum))
 	{
@@ -3685,7 +3685,7 @@ int
 i386_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				 struct agent_expr *ax, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (i386_mmx_regnum_p (gdbarch, regnum))
     {
@@ -3902,7 +3902,7 @@ i386_supply_gregset (const struct regset *regset, struct regcache *regcache,
 		     int regnum, const void *gregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   const gdb_byte *regs = (const gdb_byte *) gregs;
   int i;
 
@@ -3927,7 +3927,7 @@ i386_collect_gregset (const struct regset *regset,
 		      int regnum, void *gregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   gdb_byte *regs = (gdb_byte *) gregs;
   int i;
 
@@ -3950,7 +3950,7 @@ i386_supply_fpregset (const struct regset *regset, struct regcache *regcache,
 		      int regnum, const void *fpregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (len == I387_SIZEOF_FXSAVE)
     {
@@ -3973,7 +3973,7 @@ i386_collect_fpregset (const struct regset *regset,
 		       int regnum, void *fpregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (len == I387_SIZEOF_FXSAVE)
     {
@@ -4005,7 +4005,7 @@ i386_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				   void *cb_data,
 				   const struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   cb (".reg", tdep->sizeof_gregset, tdep->sizeof_gregset, &i386_gregset, NULL,
       cb_data);
@@ -4510,7 +4510,7 @@ i386_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 void
 i386_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* System V Release 4 uses ELF.  */
   i386_elf_init_abi (info, gdbarch);
@@ -4552,7 +4552,7 @@ int
 i386_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 			  const struct reggroup *group)
 {
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int fp_regnum_p, mmx_regnum_p, xmm_regnum_p, mxcsr_regnum_p,
       ymm_regnum_p, ymmh_regnum_p, ymm_avx512_regnum_p, ymmh_avx512_regnum_p,
       bndr_regnum_p, bnd_regnum_p, zmm_regnum_p, zmmh_regnum_p,
@@ -4997,7 +4997,7 @@ static int i386_record_floats (struct gdbarch *gdbarch,
 			       struct i386_record_s *ir,
 			       uint32_t iregnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int i;
 
   /* Oza: Because of floating point insn push/pop of fpu stack is going to
@@ -5068,7 +5068,7 @@ i386_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
   ULONGEST addr;
   gdb_byte buf[I386_MAX_REGISTER_SIZE];
   struct i386_record_s ir;
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   uint8_t rex_w = -1;
   uint8_t rex_r = 0;
 
@@ -8839,7 +8839,7 @@ i386_mpx_bd_base (void)
 
   rcache = get_current_regcache ();
   gdbarch *arch = rcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
 
   regstatus = regcache_raw_read_unsigned (rcache, tdep->bndcfgu_regnum, &ret);
 
@@ -8853,7 +8853,7 @@ int
 i386_mpx_enabled (void)
 {
   gdbarch *arch = get_current_arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
   const struct target_desc *tdesc = tdep->tdesc;
 
   return (tdesc_find_feature (tdesc, "org.gnu.gdb.i386.mpx") != NULL);
diff --git a/gdb/i386-windows-tdep.c b/gdb/i386-windows-tdep.c
index 8e1cc17b91c..9eec6e28109 100644
--- a/gdb/i386-windows-tdep.c
+++ b/gdb/i386-windows-tdep.c
@@ -136,7 +136,7 @@ i386_windows_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 static void
 i386_windows_init_abi_common (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   set_gdbarch_skip_trampoline_code (gdbarch, i386_windows_skip_trampoline_code);
 
diff --git a/gdb/i387-tdep.c b/gdb/i387-tdep.c
index f056ea59347..42ed4eebc2c 100644
--- a/gdb/i387-tdep.c
+++ b/gdb/i387-tdep.c
@@ -204,7 +204,7 @@ void
 i387_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
 		       struct frame_info *frame, const char *args)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   ULONGEST fctrl;
   int fctrl_p;
   ULONGEST fstat;
@@ -440,7 +440,7 @@ void
 i387_supply_fsave (struct regcache *regcache, int regnum, const void *fsave)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   const gdb_byte *regs = (const gdb_byte *) fsave;
   int i;
@@ -495,7 +495,7 @@ void
 i387_collect_fsave (const struct regcache *regcache, int regnum, void *fsave)
 {
   gdbarch *arch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
   gdb_byte *regs = (gdb_byte *) fsave;
   int i;
 
@@ -589,7 +589,7 @@ void
 i387_supply_fxsave (struct regcache *regcache, int regnum, const void *fxsave)
 {
   gdbarch *arch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
   const gdb_byte *regs = (const gdb_byte *) fxsave;
   int i;
 
@@ -673,7 +673,7 @@ void
 i387_collect_fxsave (const struct regcache *regcache, int regnum, void *fxsave)
 {
   gdbarch *arch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
   gdb_byte *regs = (gdb_byte *) fxsave;
   int i;
 
@@ -906,7 +906,7 @@ i387_xsave_get_clear_bv (struct gdbarch *gdbarch, const void *xsave)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   const gdb_byte *regs = (const gdb_byte *) xsave;
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* Get `xstat_bv'.  The supported bits in `xstat_bv' are 8 bytes.  */
   ULONGEST xstate_bv = extract_unsigned_integer (XSAVE_XSTATE_BV_ADDR (regs),
@@ -926,7 +926,7 @@ i387_supply_xsave (struct regcache *regcache, int regnum,
 {
   struct gdbarch *gdbarch = regcache->arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   const gdb_byte *regs = (const gdb_byte *) xsave;
   int i;
   /* In 64-bit mode the split between "low" and "high" ZMM registers is at
@@ -1349,7 +1349,7 @@ i387_collect_xsave (const struct regcache *regcache, int regnum,
 {
   struct gdbarch *gdbarch = regcache->arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   gdb_byte *p, *regs = (gdb_byte *) xsave;
   gdb_byte raw[I386_MAX_REGISTER_SIZE];
   ULONGEST initial_xstate_bv, clear_bv, xstate_bv = 0;
@@ -1934,7 +1934,7 @@ i387_tag (const gdb_byte *raw)
 void
 i387_return_value (struct gdbarch *gdbarch, struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   ULONGEST fstat;
 
   /* Set the top of the floating-point register stack to 7.  The
@@ -1957,7 +1957,7 @@ i387_return_value (struct gdbarch *gdbarch, struct regcache *regcache)
 void
 i387_reset_bnd_regs (struct gdbarch *gdbarch, struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (I387_BND0R_REGNUM (tdep) > 0)
     {
diff --git a/gdb/ia64-linux-tdep.c b/gdb/ia64-linux-tdep.c
index 64a57f5bf2f..508d4e6f7c6 100644
--- a/gdb/ia64-linux-tdep.c
+++ b/gdb/ia64-linux-tdep.c
@@ -216,7 +216,7 @@ ia64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 static void
 ia64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
   static const char *const stap_register_prefixes[] = { "r", NULL };
   static const char *const stap_register_indirection_prefixes[] = { "[",
 								    NULL };
diff --git a/gdb/ia64-tdep.c b/gdb/ia64-tdep.c
index 82456dc9c98..de343cfe17d 100644
--- a/gdb/ia64-tdep.c
+++ b/gdb/ia64-tdep.c
@@ -310,7 +310,7 @@ static const struct floatformat *floatformats_ia64_ext[2] =
 static struct type *
 ia64_ext_type (struct gdbarch *gdbarch)
 {
-  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
 
   if (!tdep->ia64_ext_type)
     tdep->ia64_ext_type
@@ -2177,7 +2177,7 @@ ia64_sigtramp_frame_init_saved_regs (struct frame_info *this_frame,
 				     struct ia64_frame_cache *cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
 
   if (tdep->sigcontext_register_address)
     {
@@ -2336,7 +2336,7 @@ ia64_sigtramp_frame_sniffer (const struct frame_unwind *self,
 			     void **this_cache)
 {
   gdbarch *arch = get_frame_arch (this_frame);
-  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (arch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (arch);
   if (tdep->pc_in_sigtramp)
     {
       CORE_ADDR pc = get_frame_pc (this_frame);
@@ -2485,7 +2485,7 @@ ia64_access_reg (unw_addr_space_t as, unw_regnum_t uw_regnum, unw_word_t *val,
   unw_word_t bsp, sof, cfm, psr, ip;
   struct frame_info *this_frame = (struct frame_info *) arg;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
   
   /* We never call any libunwind routines that need to write registers.  */
   gdb_assert (!write);
@@ -3484,7 +3484,7 @@ ia64_find_global_pointer_from_dynamic_section (struct gdbarch *gdbarch,
 static CORE_ADDR
 ia64_find_global_pointer (struct gdbarch *gdbarch, CORE_ADDR faddr)
 {
-  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
   CORE_ADDR addr = 0;
 
   if (tdep->find_global_pointer_from_solib)
@@ -3679,7 +3679,7 @@ ia64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 		      function_call_return_method return_method,
 		      CORE_ADDR struct_addr)
 {
-  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int argno;
   struct value *arg;
diff --git a/gdb/loongarch-linux-nat.c b/gdb/loongarch-linux-nat.c
index edc3d697d7b..689c10bd57e 100644
--- a/gdb/loongarch-linux-nat.c
+++ b/gdb/loongarch-linux-nat.c
@@ -51,7 +51,7 @@ static void
 fetch_gregs_from_thread (struct regcache *regcache, int regno, pid_t tid)
 {
   loongarch_gdbarch_tdep *tdep
-    = (loongarch_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<loongarch_gdbarch_tdep> (regcache->arch ());
   auto regs = tdep->regs;
   elf_gregset_t regset;
 
@@ -78,7 +78,7 @@ static void
 store_gregs_to_thread (struct regcache *regcache, int regno, pid_t tid)
 {
   loongarch_gdbarch_tdep *tdep
-    = (loongarch_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<loongarch_gdbarch_tdep> (regcache->arch ());
   auto regs = tdep->regs;
   elf_gregset_t regset;
 
@@ -131,7 +131,7 @@ loongarch_linux_nat_target::register_u_offset (struct gdbarch *gdbarch,
 					       int regno, int store_p)
 {
   loongarch_gdbarch_tdep *tdep
-    = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+    = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
   auto regs = tdep->regs;
 
   /* According to <asm/ptrace.h> */
diff --git a/gdb/loongarch-linux-tdep.c b/gdb/loongarch-linux-tdep.c
index 372643761b1..b6d790ab185 100644
--- a/gdb/loongarch-linux-tdep.c
+++ b/gdb/loongarch-linux-tdep.c
@@ -41,7 +41,7 @@ loongarch_supply_gregset (const struct regset *r,
 			  const void *gprs, size_t len)
 {
   loongarch_gdbarch_tdep *tdep
-    = (loongarch_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<loongarch_gdbarch_tdep> (regcache->arch ());
   auto regs = tdep->regs;
 
   int regsize = register_size (regcache->arch (), regs.r);
@@ -85,7 +85,7 @@ loongarch_fill_gregset (const struct regset *r,
 			void *gprs, size_t len)
 {
   loongarch_gdbarch_tdep *tdep
-    = (loongarch_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<loongarch_gdbarch_tdep> (regcache->arch ());
   auto regs = tdep->regs;
   int regsize = register_size (regcache->arch (), regs.r);
   gdb_byte *buf = nullptr;
@@ -136,7 +136,7 @@ loongarch_linux_rt_sigframe_init (const struct tramp_frame *self,
 				  CORE_ADDR func)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  loongarch_gdbarch_tdep *tdep = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
   auto regs = tdep->regs;
 
   CORE_ADDR frame_sp = get_frame_sp (this_frame);
@@ -177,7 +177,7 @@ loongarch_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					const struct regcache *regcache)
 {
   loongarch_gdbarch_tdep *tdep
-    = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+    = gdbarch_tdep<loongarch_gdbarch_tdep> (regcache->arch ());
   auto regs = tdep->regs;
   int regsize = register_size (gdbarch, regs.r);
 
diff --git a/gdb/loongarch-tdep.c b/gdb/loongarch-tdep.c
index 963e832454a..af5ccb17286 100644
--- a/gdb/loongarch-tdep.c
+++ b/gdb/loongarch-tdep.c
@@ -74,7 +74,7 @@ loongarch_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc,
 			 struct trad_frame_cache *this_cache)
 {
   CORE_ADDR cur_pc = start_pc, prologue_end = 0;
-  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  loongarch_gdbarch_tdep *tdep = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
   auto regs = tdep->regs;
   int32_t sp = regs.r + 3;
   int32_t fp = regs.r + 22;
@@ -306,7 +306,7 @@ loongarch_frame_cache (struct frame_info *this_frame, void **this_cache)
   cache = trad_frame_cache_zalloc (this_frame);
   *this_cache = cache;
 
-  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  loongarch_gdbarch_tdep *tdep = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
   trad_frame_set_reg_realreg (cache, gdbarch_pc_regnum (gdbarch), tdep->regs.ra);
 
   pc = get_frame_address_in_block (this_frame);
@@ -358,7 +358,7 @@ loongarch_return_value (struct gdbarch *gdbarch, struct value *function,
 			struct type *type, struct regcache *regcache,
 			gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  loongarch_gdbarch_tdep *tdep = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
   auto regs = tdep->regs;
   int len = TYPE_LENGTH (type);
   int regnum = -1;
@@ -386,7 +386,7 @@ loongarch_return_value (struct gdbarch *gdbarch, struct value *function,
 static int
 loongarch_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int num)
 {
-  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  loongarch_gdbarch_tdep *tdep = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
   auto regs = tdep->regs;
 
   if (0 <= num && num < 32)
@@ -512,7 +512,7 @@ loongarch_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 	 we are looking for.  If it doesn't then we can't reuse this
 	 gdbarch.  */
       loongarch_gdbarch_tdep *candidate_tdep
-	= (loongarch_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<loongarch_gdbarch_tdep> (arches->gdbarch);
 
       if (candidate_tdep->abi_features != abi_features)
 	continue;
diff --git a/gdb/m32c-tdep.c b/gdb/m32c-tdep.c
index 4971be796cd..37456d16cb3 100644
--- a/gdb/m32c-tdep.c
+++ b/gdb/m32c-tdep.c
@@ -142,7 +142,7 @@ struct m32c_gdbarch_tdep : gdbarch_tdep
 static void
 make_types (struct gdbarch *arch)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   unsigned long mach = gdbarch_bfd_arch_info (arch)->mach;
   int data_addr_reg_bits, code_addr_reg_bits;
   char type_name[50];
@@ -215,7 +215,7 @@ make_types (struct gdbarch *arch)
 static const char *
 m32c_register_name (struct gdbarch *gdbarch, int num)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   return tdep->regs[num].name;
 }
 
@@ -223,7 +223,7 @@ m32c_register_name (struct gdbarch *gdbarch, int num)
 static struct type *
 m32c_register_type (struct gdbarch *arch, int reg_nr)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   return tdep->regs[reg_nr].type;
 }
 
@@ -231,7 +231,7 @@ m32c_register_type (struct gdbarch *arch, int reg_nr)
 static int
 m32c_register_sim_regno (struct gdbarch *gdbarch, int reg_nr)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   return tdep->regs[reg_nr].sim_num;
 }
 
@@ -239,7 +239,7 @@ m32c_register_sim_regno (struct gdbarch *gdbarch, int reg_nr)
 static int
 m32c_debug_info_reg_to_regnum (struct gdbarch *gdbarch, int reg_nr)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   if (0 <= reg_nr && reg_nr <= M32C_MAX_DWARF_REGNUM
       && tdep->dwarf_regs[reg_nr])
     return tdep->dwarf_regs[reg_nr]->num;
@@ -254,7 +254,7 @@ static int
 m32c_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 			  const struct reggroup *group)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   struct m32c_reg *reg = &tdep->regs[regnum];
 
   /* The anonymous raw registers aren't in any groups.  */
@@ -330,7 +330,7 @@ static int
 m32c_read_flg (readable_regcache *cache)
 {
   gdbarch *arch = cache->arch ();
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   ULONGEST flg;
 
   cache->raw_read (tdep->flg->num, &flg);
@@ -530,7 +530,7 @@ static enum register_status
 m32c_r3r2r1r0_read (struct m32c_reg *reg, readable_regcache *cache, gdb_byte *buf)
 {
   gdbarch *arch = reg->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   int len = TYPE_LENGTH (tdep->r0->type);
   enum register_status status;
 
@@ -567,7 +567,7 @@ m32c_r3r2r1r0_write (struct m32c_reg *reg, struct regcache *cache,
 		     const gdb_byte *buf)
 {
   gdbarch *arch = reg->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   int len = TYPE_LENGTH (tdep->r0->type);
 
   if (gdbarch_byte_order (reg->arch) == BFD_ENDIAN_BIG)
@@ -595,7 +595,7 @@ m32c_pseudo_register_read (struct gdbarch *arch,
 			   int cookednum,
 			   gdb_byte *buf)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   struct m32c_reg *reg;
 
   gdb_assert (0 <= cookednum && cookednum < tdep->num_regs);
@@ -613,7 +613,7 @@ m32c_pseudo_register_write (struct gdbarch *arch,
 			    int cookednum,
 			    const gdb_byte *buf)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   struct m32c_reg *reg;
 
   gdb_assert (0 <= cookednum && cookednum < tdep->num_regs);
@@ -638,7 +638,7 @@ add_reg (struct gdbarch *arch,
 	 struct m32c_reg *ry,
 	 int n)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   struct m32c_reg *r = &tdep->regs[tdep->num_regs];
 
   gdb_assert (tdep->num_regs < M32C_MAX_NUM_REGS);
@@ -678,7 +678,7 @@ set_dwarf_regnum (struct m32c_reg *reg, int num)
 
   /* Update the DWARF->reg mapping.  */
   gdbarch *arch = reg->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   tdep->dwarf_regs[num] = reg;
 }
 
@@ -800,7 +800,7 @@ mark_save_restore (struct m32c_reg *reg)
 static void
 make_regs (struct gdbarch *arch)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   int mach = gdbarch_bfd_arch_info (arch)->mach;
   int num_raw_regs;
   int num_cooked_regs;
@@ -1349,7 +1349,7 @@ m32c_pv_enter (struct m32c_pv_state *state, int size)
     return 1;
 
   gdbarch *arch = state->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   if (m32c_pv_push (state, state->fb, tdep->push_addr_bytes))
     return 1;
 
@@ -1379,7 +1379,7 @@ static int
 m32c_pv_pushm (struct m32c_pv_state *state, int src)
 {
   gdbarch *arch = state->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   /* The bits in SRC indicating which registers to save are:
      r0 r1 r2 r3 a0 a1 sb fb */
@@ -1400,7 +1400,7 @@ static int
 m32c_is_1st_arg_reg (struct m32c_pv_state *state, pv_t value)
 {
   gdbarch *arch = state->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   return (value.kind == pvk_register
 	  && (gdbarch_bfd_arch_info (state->arch)->mach == bfd_mach_m16c
@@ -1415,7 +1415,7 @@ static int
 m32c_is_arg_reg (struct m32c_pv_state *state, pv_t value)
 {
   gdbarch *arch = state->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   return (value.kind == pvk_register
 	  && (gdbarch_bfd_arch_info (state->arch)->mach == bfd_mach_m16c
@@ -1440,7 +1440,7 @@ m32c_is_arg_spill (struct m32c_pv_state *st,
 		   pv_t value)
 {
   gdbarch *arch = st->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   return (m32c_is_arg_reg (st, value)
 	  && loc.kind == srcdest_mem
@@ -1464,7 +1464,7 @@ m32c_is_struct_return (struct m32c_pv_state *st,
 		       pv_t value)
 {
   gdbarch *arch = st->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   return (m32c_is_1st_arg_reg (st, value)
 	  && !st->stack->find_reg (st->arch, value.reg, 0)
@@ -1482,7 +1482,7 @@ static int
 m32c_pushm_is_reg_save (struct m32c_pv_state *st, int src)
 {
   gdbarch *arch = st->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   /* The bits in SRC indicating which registers to save are:
      r0 r1 r2 r3 a0 a1 sb fb */
@@ -1510,7 +1510,7 @@ check_for_saved (void *prologue_untyped, pv_t addr, CORE_ADDR size, pv_t value)
 {
   struct m32c_prologue *prologue = (struct m32c_prologue *) prologue_untyped;
   struct gdbarch *arch = prologue->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   /* Is this the unchanged value of some register being saved on the
      stack?  */
@@ -1550,7 +1550,7 @@ m32c_analyze_prologue (struct gdbarch *arch,
 		       CORE_ADDR start, CORE_ADDR limit,
 		       struct m32c_prologue *prologue)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   unsigned long mach = gdbarch_bfd_arch_info (arch)->mach;
   CORE_ADDR after_last_frame_related_insn;
   struct m32c_pv_state st;
@@ -1881,7 +1881,7 @@ m32c_frame_base (struct frame_info *this_frame,
   struct m32c_prologue *p
     = m32c_analyze_frame_prologue (this_frame, this_prologue_cache);
   gdbarch *arch = get_frame_arch (this_frame);
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   /* In functions that use alloca, the distance between the stack
      pointer and the frame base varies dynamically, so we can't use
@@ -1932,7 +1932,7 @@ m32c_prev_register (struct frame_info *this_frame,
 		    void **this_prologue_cache, int regnum)
 {
   gdbarch *arch = get_frame_arch (this_frame);
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   struct m32c_prologue *p
     = m32c_analyze_frame_prologue (this_frame, this_prologue_cache);
   CORE_ADDR frame_base = m32c_frame_base (this_frame, this_prologue_cache);
@@ -2015,7 +2015,7 @@ m32c_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 		      function_call_return_method return_method,
 		      CORE_ADDR struct_addr)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   unsigned long mach = gdbarch_bfd_arch_info (gdbarch)->mach;
   CORE_ADDR cfa;
@@ -2178,7 +2178,7 @@ m32c_return_value (struct gdbarch *gdbarch,
 		   gdb_byte *readbuf,
 		   const gdb_byte *writebuf)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   enum return_value_convention conv;
   ULONGEST valtype_len = TYPE_LENGTH (valtype);
@@ -2309,7 +2309,7 @@ static CORE_ADDR
 m32c_skip_trampoline_code (struct frame_info *frame, CORE_ADDR stop_pc)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   /* It would be nicer to simply look up the addresses of known
@@ -2555,7 +2555,7 @@ m32c_virtual_frame_pointer (struct gdbarch *gdbarch, CORE_ADDR pc,
   struct m32c_prologue p;
 
   struct regcache *regcache = get_current_regcache ();
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   
   if (!find_pc_partial_function (pc, &name, &func_addr, &func_end))
     internal_error (__FILE__, __LINE__,
diff --git a/gdb/m68hc11-tdep.c b/gdb/m68hc11-tdep.c
index 98f1367423e..9eb18b937be 100644
--- a/gdb/m68hc11-tdep.c
+++ b/gdb/m68hc11-tdep.c
@@ -146,14 +146,14 @@ struct m68gc11_gdbarch_tdep : gdbarch_tdep
 static int
 stack_correction (gdbarch *arch)
 {
-  m68gc11_gdbarch_tdep *tdep = (m68gc11_gdbarch_tdep *) gdbarch_tdep (arch);
+  m68gc11_gdbarch_tdep *tdep = gdbarch_tdep<m68gc11_gdbarch_tdep> (arch);
   return tdep->stack_correction;
 }
 
 static int
 use_page_register (gdbarch *arch)
 {
-  m68gc11_gdbarch_tdep *tdep = (m68gc11_gdbarch_tdep *) gdbarch_tdep (arch);
+  m68gc11_gdbarch_tdep *tdep = gdbarch_tdep<m68gc11_gdbarch_tdep> (arch);
   return tdep->stack_correction;
 }
 
@@ -642,7 +642,7 @@ m68hc11_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
       return pc;
     }
 
-  m68gc11_gdbarch_tdep *tdep = (m68gc11_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68gc11_gdbarch_tdep *tdep = gdbarch_tdep<m68gc11_gdbarch_tdep> (gdbarch);
   seq_table = tdep->prologue;
   
   /* The 68hc11 stack is as follows:
@@ -1020,7 +1020,7 @@ m68hc11_print_register (struct gdbarch *gdbarch, struct ui_file *file,
   else
     {
       m68gc11_gdbarch_tdep *tdep
-	= (m68gc11_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	= gdbarch_tdep<m68gc11_gdbarch_tdep> (gdbarch);
 
       if (regno == HARD_PC_REGNUM && tdep->use_page_register)
 	{
@@ -1125,7 +1125,7 @@ m68hc11_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file,
       gdb_printf (file, " Y=");
       m68hc11_print_register (gdbarch, file, frame, HARD_Y_REGNUM);
   
-      m68gc11_gdbarch_tdep *tdep = (m68gc11_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      m68gc11_gdbarch_tdep *tdep = gdbarch_tdep<m68gc11_gdbarch_tdep> (gdbarch);
 
       if (tdep->use_page_register)
 	{
@@ -1417,7 +1417,7 @@ m68hc11_gdbarch_init (struct gdbarch_info info,
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       m68gc11_gdbarch_tdep *tdep
-	= (m68gc11_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<m68gc11_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->elf_flags != elf_flags)
 	continue;
diff --git a/gdb/m68k-bsd-tdep.c b/gdb/m68k-bsd-tdep.c
index 9ef70f0dda4..2614c223f8e 100644
--- a/gdb/m68k-bsd-tdep.c
+++ b/gdb/m68k-bsd-tdep.c
@@ -133,7 +133,7 @@ m68kbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 static void
 m68kbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   tdep->jb_pc = 5;
   tdep->jb_elt_size = 4;
diff --git a/gdb/m68k-linux-tdep.c b/gdb/m68k-linux-tdep.c
index 85ad4741b1f..28401d3ecc6 100644
--- a/gdb/m68k-linux-tdep.c
+++ b/gdb/m68k-linux-tdep.c
@@ -384,7 +384,7 @@ m68k_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 static void
 m68k_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/m68k-tdep.c b/gdb/m68k-tdep.c
index 568bde66f93..9e59f5904c3 100644
--- a/gdb/m68k-tdep.c
+++ b/gdb/m68k-tdep.c
@@ -70,7 +70,7 @@ typedef BP_MANIPULATION (m68k_break_insn) m68k_breakpoint;
 static struct type *
 m68k_ps_type (struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (!tdep->m68k_ps_type)
     {
@@ -99,7 +99,7 @@ m68k_ps_type (struct gdbarch *gdbarch)
 static struct type *
 m68881_ext_type (struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (!tdep->m68881_ext_type)
     tdep->m68881_ext_type
@@ -120,7 +120,7 @@ m68881_ext_type (struct gdbarch *gdbarch)
 static struct type *
 m68k_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (tdep->fpregs_present)
     {
@@ -171,7 +171,7 @@ static const char * const m68k_register_names[] = {
 static const char *
 m68k_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (regnum < 0 || regnum >= ARRAY_SIZE (m68k_register_names))
     internal_error (__FILE__, __LINE__,
@@ -191,7 +191,7 @@ static int
 m68k_convert_register_p (struct gdbarch *gdbarch,
 			 int regnum, struct type *type)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (!tdep->fpregs_present)
     return 0;
@@ -300,7 +300,7 @@ m68k_extract_return_value (struct type *type, struct regcache *regcache,
   if (type->code () == TYPE_CODE_PTR && len == 4)
     {
       struct gdbarch *gdbarch = regcache->arch ();
-      m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
       regcache->raw_read (tdep->pointer_result_regnum, valbuf);
     }
   else if (len <= 4)
@@ -325,7 +325,7 @@ m68k_svr4_extract_return_value (struct type *type, struct regcache *regcache,
 {
   gdb_byte buf[M68K_MAX_REGISTER_SIZE];
   struct gdbarch *gdbarch = regcache->arch ();
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (tdep->float_return && type->code () == TYPE_CODE_FLT)
     {
@@ -348,7 +348,7 @@ m68k_store_return_value (struct type *type, struct regcache *regcache,
   if (type->code () == TYPE_CODE_PTR && len == 4)
     {
       struct gdbarch *gdbarch = regcache->arch ();
-      m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
       regcache->raw_write (tdep->pointer_result_regnum, valbuf);
       /* gdb historically also set D0 in the SVR4 case.  */
       if (tdep->pointer_result_regnum != M68K_D0_REGNUM)
@@ -371,7 +371,7 @@ m68k_svr4_store_return_value (struct type *type, struct regcache *regcache,
 			      const gdb_byte *valbuf)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (tdep->float_return && type->code () == TYPE_CODE_FLT)
     {
@@ -391,7 +391,7 @@ m68k_svr4_store_return_value (struct type *type, struct regcache *regcache,
 static int
 m68k_reg_struct_return_p (struct gdbarch *gdbarch, struct type *type)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
   enum type_code code = type->code ();
   int len = TYPE_LENGTH (type);
 
@@ -469,7 +469,7 @@ m68k_svr4_return_value (struct gdbarch *gdbarch, struct value *function,
 			gdb_byte *readbuf, const gdb_byte *writebuf)
 {
   enum type_code code = type->code ();
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   /* Aggregates with a single member are always returned like their
      sole element.  */
@@ -541,7 +541,7 @@ m68k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 		      function_call_return_method return_method,
 		      CORE_ADDR struct_addr)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   gdb_byte buf[4];
   int i;
@@ -596,7 +596,7 @@ m68k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 static int
 m68k_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int num)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (num < 8)
     /* d0..7 */
@@ -766,7 +766,7 @@ m68k_analyze_register_saves (struct gdbarch *gdbarch, CORE_ADDR pc,
 			     struct m68k_frame_cache *cache)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (cache->locals >= 0)
     {
@@ -1058,7 +1058,7 @@ m68k_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
   gdb_byte *buf;
   CORE_ADDR sp, jb_addr;
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   if (tdep->jb_pc < 0)
@@ -1104,7 +1104,7 @@ m68k_return_in_first_hidden_param_p (struct gdbarch *gdbarch,
 void
 m68k_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   /* SVR4 uses a different calling convention.  */
   set_gdbarch_return_value (gdbarch, m68k_svr4_return_value);
@@ -1122,7 +1122,7 @@ m68k_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 static void
 m68k_embedded_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   m68k_svr4_init_abi (info, gdbarch);
   tdep->pointer_result_regnum = M68K_D0_REGNUM;
@@ -1237,7 +1237,7 @@ m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
     {
       m68k_gdbarch_tdep *tdep
-	= (m68k_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
+	= gdbarch_tdep<m68k_gdbarch_tdep> (best_arch->gdbarch);
 
       if (flavour != tdep->flavour)
 	continue;
@@ -1339,7 +1339,7 @@ m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 m68k_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (tdep == NULL)
     return;
diff --git a/gdb/mep-tdep.c b/gdb/mep-tdep.c
index 6b3a62391c0..d5ba78c6df9 100644
--- a/gdb/mep-tdep.c
+++ b/gdb/mep-tdep.c
@@ -260,7 +260,7 @@ me_module_register_set (CONFIG_ATTR me_module,
        specifically excluding the generic coprocessor register sets.  */
 
   mep_gdbarch_tdep *tdep
-    = (mep_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+    = gdbarch_tdep<mep_gdbarch_tdep> (target_gdbarch ());
   CGEN_CPU_DESC desc = tdep->cpu_desc;
   const CGEN_HW_ENTRY *hw;
 
@@ -856,7 +856,7 @@ current_me_module (void)
   else
     {
       mep_gdbarch_tdep *tdep
-	= (mep_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+	= gdbarch_tdep<mep_gdbarch_tdep> (target_gdbarch ());
       return tdep->me_module;
     }
 }
@@ -2391,7 +2391,7 @@ mep_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       mep_gdbarch_tdep *tdep
-	= (mep_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<mep_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->me_module == me_module)
 	return arches->gdbarch;
diff --git a/gdb/mips-linux-tdep.c b/gdb/mips-linux-tdep.c
index d8f90ccf881..ca313a28279 100644
--- a/gdb/mips-linux-tdep.c
+++ b/gdb/mips-linux-tdep.c
@@ -1317,7 +1317,7 @@ mips_linux_get_syscall_number (struct gdbarch *gdbarch,
 			       thread_info *thread)
 {
   struct regcache *regcache = get_thread_regcache (thread);
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int regsize = register_size (gdbarch, MIPS_V0_REGNUM);
   /* The content of a register */
@@ -1527,7 +1527,7 @@ static void
 mips_linux_init_abi (struct gdbarch_info info,
 		     struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   enum mips_abi abi = mips_abi (gdbarch);
   struct tdesc_arch_data *tdesc_data = info.tdesc_data;
 
diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index fc1cb46de84..1ea16767e54 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -227,7 +227,7 @@ static const char mips_disassembler_options_n64[] = "gpr-names=64";
 const struct mips_regnum *
 mips_regnum (struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   return tdep->regnum;
 }
 
@@ -252,7 +252,7 @@ mips_float_register_p (struct gdbarch *gdbarch, int regnum)
 static bool
 mips_eabi (gdbarch *arch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (arch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (arch);
   return (tdep->mips_abi == MIPS_ABI_EABI32 \
 	  || tdep->mips_abi == MIPS_ABI_EABI64);
 }
@@ -260,21 +260,21 @@ mips_eabi (gdbarch *arch)
 static int
 mips_last_fp_arg_regnum (gdbarch *arch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (arch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (arch);
   return tdep->mips_last_fp_arg_regnum;
 }
 
 static int
 mips_last_arg_regnum (gdbarch *arch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (arch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (arch);
   return tdep->mips_last_arg_regnum;
 }
 
 static enum mips_fpu_type
 mips_get_fpu_type (gdbarch *arch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (arch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (arch);
   return tdep->mips_fpu_type;
 }
 
@@ -282,14 +282,14 @@ mips_get_fpu_type (gdbarch *arch)
 enum mips_abi
 mips_abi (struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   return tdep->mips_abi;
 }
 
 int
 mips_isa_regsize (struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
   /* If we know how big the registers are, use that size.  */
   if (tdep->register_size_valid_p)
@@ -335,7 +335,7 @@ mips_abi_regsize (struct gdbarch *gdbarch)
 static int
 is_mips16_isa (struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   return tdep->mips_isa == ISA_MIPS16;
 }
 
@@ -344,7 +344,7 @@ is_mips16_isa (struct gdbarch *gdbarch)
 static int
 is_micromips_isa (struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   return tdep->mips_isa == ISA_MICROMIPS;
 }
 
@@ -636,7 +636,7 @@ static const char * const mips_linux_reg_names[NUM_MIPS_PROCESSOR_REGS] = {
 static const char *
 mips_register_name (struct gdbarch *gdbarch, int regno)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   /* GPR names for all ABIs other than n32/n64.  */
   static const char *mips_gpr_names[] = {
     "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
@@ -777,7 +777,7 @@ mips_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
   else if (register_size (gdbarch, rawnum) >
 	   register_size (gdbarch, cookednum))
     {
-      mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
       if (tdep->mips64_transfers_32bit_regs_p)
 	return regcache->raw_read_part (rawnum, 0, 4, buf);
@@ -810,7 +810,7 @@ mips_pseudo_register_write (struct gdbarch *gdbarch,
   else if (register_size (gdbarch, rawnum) >
 	   register_size (gdbarch, cookednum))
     {
-      mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
       if (tdep->mips64_transfers_32bit_regs_p)
 	regcache->raw_write_part (rawnum, 0, 4, buf);
@@ -855,7 +855,7 @@ mips_ax_pseudo_register_push_stack (struct gdbarch *gdbarch,
       if (register_size (gdbarch, rawnum) > register_size (gdbarch, reg))
 	{
 	  mips_gdbarch_tdep *tdep
-	    = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	    = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
 	  if (!tdep->mips64_transfers_32bit_regs_p
 	      || gdbarch_byte_order (gdbarch) != BFD_ENDIAN_BIG)
@@ -1059,7 +1059,7 @@ mips_register_type (struct gdbarch *gdbarch, int regnum)
   else
     {
       int rawnum = regnum - gdbarch_num_regs (gdbarch);
-      mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
       /* The cooked or ABI registers.  These are sized according to
 	 the ABI (with a few complications).  */
@@ -1191,7 +1191,7 @@ show_mask_address (struct ui_file *file, int from_tty,
       else
 	{
 	  mips_gdbarch_tdep *tdep
-	    = (mips_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+	    = gdbarch_tdep<mips_gdbarch_tdep> (target_gdbarch ());
 
 	  if (mips_mask_address_p (tdep))
 	    additional_text = _(" (currently \"on\")");
@@ -1727,7 +1727,7 @@ mips32_next_pc (struct regcache *regcache, CORE_ADDR pc)
 	    case 12:            /* SYSCALL */
 	      {
 		mips_gdbarch_tdep *tdep
-		  = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+		  = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
 		if (tdep->syscall_next_pc != NULL)
 		  pc = tdep->syscall_next_pc (get_current_frame ());
@@ -1938,7 +1938,7 @@ micromips_next_pc (struct regcache *regcache, CORE_ADDR pc)
 		case 0x22d: /* SYSCALL:  000000 1000101101 111100 */
 		  {
 		    mips_gdbarch_tdep *tdep
-		      = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+		      = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
 		    if (tdep->syscall_next_pc != NULL)
 		      pc = tdep->syscall_next_pc (get_current_frame ());
@@ -3901,7 +3901,7 @@ mips_stub_frame_base_sniffer (struct frame_info *this_frame)
 static CORE_ADDR
 mips_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
   if (mips_mask_address_p (tdep) && (((ULONGEST) addr) >> 32 == 0xffffffffUL))
     /* This hack is a work-around for existing boards using PMON, the
@@ -4804,7 +4804,7 @@ mips_eabi_return_value (struct gdbarch *gdbarch, struct value *function,
 			struct type *type, struct regcache *regcache,
 			gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   int fp_return_type = 0;
   int offset, regnum, xfer;
 
@@ -5195,7 +5195,7 @@ mips_n32n64_return_value (struct gdbarch *gdbarch, struct value *function,
 			  struct type *type, struct regcache *regcache,
 			  gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
   /* From MIPSpro N32 ABI Handbook, Document Number: 007-2816-004
 
@@ -5704,7 +5704,7 @@ mips_o32_return_value (struct gdbarch *gdbarch, struct value *function,
 {
   CORE_ADDR func_addr = function ? find_function_addr (function, NULL) : 0;
   int mips16 = mips_pc_is_mips16 (gdbarch, func_addr);
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   enum mips_fval_reg fval_reg;
 
   fval_reg = readbuf ? mips16 ? mips_fval_gpr : mips_fval_fpr : mips_fval_both;
@@ -8101,7 +8101,7 @@ mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   else if (arches != NULL)
     {
       mips_gdbarch_tdep *tdep
-	= (mips_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<mips_gdbarch_tdep> (arches->gdbarch);
       elf_flags = tdep->elf_flags;
     }
   else
@@ -8142,7 +8142,7 @@ mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   if (found_abi == MIPS_ABI_UNKNOWN && info.abfd == NULL && arches != NULL)
     {
       mips_gdbarch_tdep *tdep
-	= (mips_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<mips_gdbarch_tdep> (arches->gdbarch);
       found_abi = tdep->found_abi;
     }
 
@@ -8459,7 +8459,7 @@ mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       mips_gdbarch_tdep *tdep
-        = (mips_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+        = gdbarch_tdep<mips_gdbarch_tdep> (arches->gdbarch);
 
       /* MIPS needs to be pedantic about which ABI and the compressed
 	 ISA variation the object is using.  */
@@ -8917,7 +8917,7 @@ mips_fpu_type_str (enum mips_fpu_type fpu_type)
 static void
 mips_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   if (tdep != NULL)
     {
       int ef_mips_arch;
diff --git a/gdb/mn10300-tdep.c b/gdb/mn10300-tdep.c
index 7a41070bb30..22511d894d4 100644
--- a/gdb/mn10300-tdep.c
+++ b/gdb/mn10300-tdep.c
@@ -1412,7 +1412,7 @@ mn10300_gdbarch_init (struct gdbarch_info info,
 static void
 mn10300_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  mn10300_gdbarch_tdep *tdep = (mn10300_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mn10300_gdbarch_tdep *tdep = gdbarch_tdep<mn10300_gdbarch_tdep> (gdbarch);
   gdb_printf (file, "mn10300_dump_tdep: am33_mode = %d\n",
 	      tdep->am33_mode);
 }
diff --git a/gdb/mn10300-tdep.h b/gdb/mn10300-tdep.h
index 10fef99c5d7..87b861ead90 100644
--- a/gdb/mn10300-tdep.h
+++ b/gdb/mn10300-tdep.h
@@ -84,7 +84,7 @@ struct mn10300_gdbarch_tdep : gdbarch_tdep
 static inline int
 get_am33_mode (gdbarch *arch)
 {
-  mn10300_gdbarch_tdep *tdep = (mn10300_gdbarch_tdep *) gdbarch_tdep (arch);
+  mn10300_gdbarch_tdep *tdep = gdbarch_tdep<mn10300_gdbarch_tdep> (arch);
   return tdep->am33_mode;
 }
 
diff --git a/gdb/msp430-tdep.c b/gdb/msp430-tdep.c
index 28268a95139..4ae8b3d5626 100644
--- a/gdb/msp430-tdep.c
+++ b/gdb/msp430-tdep.c
@@ -341,7 +341,7 @@ msp430_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc,
   int rn;
   pv_t reg[MSP430_NUM_TOTAL_REGS];
   CORE_ADDR after_last_frame_setup_insn = start_pc;
-  msp430_gdbarch_tdep *tdep = (msp430_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  msp430_gdbarch_tdep *tdep = gdbarch_tdep<msp430_gdbarch_tdep> (gdbarch);
   int code_model = tdep->code_model;
   int sz;
 
@@ -570,7 +570,7 @@ msp430_return_value (struct gdbarch *gdbarch,
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   LONGEST valtype_len = TYPE_LENGTH (valtype);
-  msp430_gdbarch_tdep *tdep = (msp430_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  msp430_gdbarch_tdep *tdep = gdbarch_tdep<msp430_gdbarch_tdep> (gdbarch);
   int code_model = tdep->code_model;
 
   if (TYPE_LENGTH (valtype) > 8
@@ -651,7 +651,7 @@ msp430_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   int write_pass;
   int sp_off = 0;
   CORE_ADDR cfa;
-  msp430_gdbarch_tdep *tdep = (msp430_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  msp430_gdbarch_tdep *tdep = gdbarch_tdep<msp430_gdbarch_tdep> (gdbarch);
   int code_model = tdep->code_model;
 
   struct type *func_type = value_type (function);
@@ -814,7 +814,7 @@ msp430_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
 
   stub_name = bms.minsym->linkage_name ();
 
-  msp430_gdbarch_tdep *tdep = (msp430_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  msp430_gdbarch_tdep *tdep = gdbarch_tdep<msp430_gdbarch_tdep> (gdbarch);
   if (tdep->code_model == MSP_SMALL_CODE_MODEL
       && msp430_in_return_stub (gdbarch, pc, stub_name))
     {
@@ -877,7 +877,7 @@ msp430_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 	  if (ca && gdbarch_bfd_arch_info (ca)->arch == bfd_arch_msp430)
 	    {
 	      msp430_gdbarch_tdep *ca_tdep
-		= (msp430_gdbarch_tdep *) gdbarch_tdep (ca);
+		= gdbarch_tdep<msp430_gdbarch_tdep> (ca);
 
 	      elf_flags = ca_tdep->elf_flags;
 	      isa = ca_tdep->isa;
@@ -904,7 +904,7 @@ msp430_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       msp430_gdbarch_tdep *candidate_tdep
-	= (msp430_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<msp430_gdbarch_tdep> (arches->gdbarch);
 
       if (candidate_tdep->elf_flags != elf_flags
 	  || candidate_tdep->isa != isa
diff --git a/gdb/nds32-tdep.c b/gdb/nds32-tdep.c
index e95ad7cc662..11bfd2d1f54 100644
--- a/gdb/nds32-tdep.c
+++ b/gdb/nds32-tdep.c
@@ -289,7 +289,7 @@ typedef BP_MANIPULATION (nds32_break_insn) nds32_breakpoint;
 static int
 nds32_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int num)
 {
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   const int FSR = 38;
   const int FDR = FSR + 32;
 
@@ -432,7 +432,7 @@ nds32_pseudo_register_read (struct gdbarch *gdbarch,
 			    readable_regcache *regcache, int regnum,
 			    gdb_byte *buf)
 {
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   gdb_byte reg_buf[8];
   int offset, fdr_regnum;
   enum register_status status;
@@ -471,7 +471,7 @@ nds32_pseudo_register_write (struct gdbarch *gdbarch,
 			     struct regcache *regcache, int regnum,
 			     const gdb_byte *buf)
 {
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   gdb_byte reg_buf[8];
   int offset, fdr_regnum;
 
@@ -608,7 +608,7 @@ static CORE_ADDR
 nds32_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
 			CORE_ADDR limit_pc, struct nds32_frame_cache *cache)
 {
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   /* Current scanning status.  */
   int in_prologue_bb = 0;
@@ -1169,7 +1169,7 @@ static int
 nds32_analyze_epilogue (struct gdbarch *gdbarch, CORE_ADDR pc,
 			struct nds32_frame_cache *cache)
 {
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   CORE_ADDR limit_pc;
   uint32_t insn, insn_len;
@@ -1220,7 +1220,7 @@ nds32_analyze_epilogue (struct gdbarch *gdbarch, CORE_ADDR pc,
 static int
 nds32_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   int insn_type = INSN_NORMAL;
   int ret_found = 0;
@@ -1424,7 +1424,7 @@ nds32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   int i;
   ULONGEST regval;
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   struct type *func_type = value_type (function);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   int abi_split = nds32_abi_split (tdep->elf_abi);
@@ -1652,7 +1652,7 @@ nds32_extract_return_value (struct gdbarch *gdbarch, struct type *type,
 			    struct regcache *regcache, gdb_byte *valbuf)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   int calling_use_fpr;
   int len;
@@ -1742,7 +1742,7 @@ nds32_store_return_value (struct gdbarch *gdbarch, struct type *type,
 			  struct regcache *regcache, const gdb_byte *valbuf)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   int calling_use_fpr;
   int len;
@@ -1965,7 +1965,7 @@ nds32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
     {
       nds32_gdbarch_tdep *idep
-	= (nds32_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
+	= gdbarch_tdep<nds32_gdbarch_tdep> (best_arch->gdbarch);
 
       if (idep->elf_abi != elf_abi)
 	continue;
diff --git a/gdb/nios2-linux-tdep.c b/gdb/nios2-linux-tdep.c
index a32f79aa28a..da69638b20b 100644
--- a/gdb/nios2-linux-tdep.c
+++ b/gdb/nios2-linux-tdep.c
@@ -217,7 +217,7 @@ nios2_linux_is_kernel_helper (CORE_ADDR pc)
 static void
 nios2_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  nios2_gdbarch_tdep *tdep = (nios2_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nios2_gdbarch_tdep *tdep = gdbarch_tdep<nios2_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/nios2-tdep.c b/gdb/nios2-tdep.c
index 159d31b2d0f..0bad229b44a 100644
--- a/gdb/nios2-tdep.c
+++ b/gdb/nios2-tdep.c
@@ -2098,7 +2098,7 @@ static CORE_ADDR
 nios2_get_next_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  nios2_gdbarch_tdep *tdep = (nios2_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nios2_gdbarch_tdep *tdep = gdbarch_tdep<nios2_gdbarch_tdep> (gdbarch);
   unsigned long mach = gdbarch_bfd_arch_info (gdbarch)->mach;
   unsigned int insn;
   const struct nios2_opcode *op = nios2_fetch_insn (gdbarch, pc, &insn);
@@ -2221,7 +2221,7 @@ static int
 nios2_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  nios2_gdbarch_tdep *tdep = (nios2_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nios2_gdbarch_tdep *tdep = gdbarch_tdep<nios2_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR jb_addr = get_frame_register_unsigned (frame, NIOS2_R4_REGNUM);
   gdb_byte buf[4];
diff --git a/gdb/or1k-tdep.c b/gdb/or1k-tdep.c
index 2b906fa69d3..4699b755d42 100644
--- a/gdb/or1k-tdep.c
+++ b/gdb/or1k-tdep.c
@@ -248,7 +248,7 @@ or1k_return_value (struct gdbarch *gdbarch, struct value *functype,
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   enum type_code rv_type = valtype->code ();
   unsigned int rv_size = TYPE_LENGTH (valtype);
-  or1k_gdbarch_tdep *tdep = (or1k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  or1k_gdbarch_tdep *tdep = gdbarch_tdep<or1k_gdbarch_tdep> (gdbarch);
   int bpw = tdep->bytes_per_word;
 
   /* Deal with struct/union as addresses.  If an array won't fit in a
@@ -353,7 +353,7 @@ or1k_delay_slot_p (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
   const CGEN_INSN *insn;
   CGEN_FIELDS tmp_fields;
-  or1k_gdbarch_tdep *tdep = (or1k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  or1k_gdbarch_tdep *tdep = gdbarch_tdep<or1k_gdbarch_tdep> (gdbarch);
 
   insn = cgen_lookup_insn (tdep->gdb_cgen_cpu_desc,
 			   NULL,
@@ -635,7 +635,7 @@ or1k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   int heap_offset = 0;
   CORE_ADDR heap_sp = sp - 128;
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  or1k_gdbarch_tdep *tdep = (or1k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  or1k_gdbarch_tdep *tdep = gdbarch_tdep<or1k_gdbarch_tdep> (gdbarch);
   int bpa = tdep->bytes_per_address;
   int bpw = tdep->bytes_per_word;
   struct type *func_type = value_type (function);
@@ -1273,7 +1273,7 @@ or1k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 or1k_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  or1k_gdbarch_tdep *tdep = (or1k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  or1k_gdbarch_tdep *tdep = gdbarch_tdep<or1k_gdbarch_tdep> (gdbarch);
 
   if (NULL == tdep)
     return; /* Nothing to report */
diff --git a/gdb/ppc-fbsd-nat.c b/gdb/ppc-fbsd-nat.c
index ce045ac55ab..d0a5778e2d3 100644
--- a/gdb/ppc-fbsd-nat.c
+++ b/gdb/ppc-fbsd-nat.c
@@ -100,7 +100,7 @@ fill_fpregset (const struct regcache *regcache,
 static int
 getfpregs_supplies (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
 	 point registers.  Traditionally, GDB's register set has still
@@ -185,7 +185,7 @@ static int
 ppcfbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i, regnum;
 
   /* The stack pointer shouldn't be zero.  */
diff --git a/gdb/ppc-fbsd-tdep.c b/gdb/ppc-fbsd-tdep.c
index 4afcc3019a4..f5b482921a7 100644
--- a/gdb/ppc-fbsd-tdep.c
+++ b/gdb/ppc-fbsd-tdep.c
@@ -126,7 +126,7 @@ ppcfbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				      void *cb_data,
 				      const struct regcache *regcache)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (tdep->wordsize == 4)
     cb (".reg", 148, 148, &ppc32_fbsd_gregset, NULL, cb_data);
@@ -200,7 +200,7 @@ static struct trad_frame_cache *
 ppcfbsd_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   struct trad_frame_cache *cache;
   CORE_ADDR addr, base, func;
   gdb_byte buf[PPC_INSN_SIZE];
@@ -287,7 +287,7 @@ static CORE_ADDR
 ppcfbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 				  CORE_ADDR lm_addr, CORE_ADDR offset)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   struct regcache *regcache;
   int tp_offset, tp_regnum;
 
@@ -319,7 +319,7 @@ ppcfbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 static void
 ppcfbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support. */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c
index f959bb0c1ad..de4158c411a 100644
--- a/gdb/ppc-linux-nat.c
+++ b/gdb/ppc-linux-nat.c
@@ -649,7 +649,7 @@ static int
 ppc_register_u_addr (struct gdbarch *gdbarch, int regno)
 {
   int u_addr = -1;
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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 +802,7 @@ static void
 fetch_spe_register (struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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 +911,7 @@ static void
 fetch_register (struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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;
@@ -1156,7 +1156,7 @@ static void
 fetch_gp_regs (struct regcache *regcache, int tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   if (have_ptrace_getsetregs)
@@ -1208,7 +1208,7 @@ static void
 fetch_fp_regs (struct regcache *regcache, int tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   if (have_ptrace_getsetfpregs)
@@ -1226,7 +1226,7 @@ static void
 fetch_ppc_registers (struct regcache *regcache, int tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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 +1425,7 @@ static void
 store_spe_register (const struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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 +1477,7 @@ static void
 store_register (const struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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;
@@ -1718,7 +1718,7 @@ static void
 store_gp_regs (const struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   if (have_ptrace_getsetregs)
@@ -1780,7 +1780,7 @@ static void
 store_fp_regs (const struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   if (have_ptrace_getsetfpregs)
@@ -1798,7 +1798,7 @@ static void
 store_ppc_registers (const struct regcache *regcache, int tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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)
diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c
index bf95f395515..cd1c176badf 100644
--- a/gdb/ppc-linux-tdep.c
+++ b/gdb/ppc-linux-tdep.c
@@ -332,7 +332,7 @@ ppc_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
 {
   unsigned int insnbuf[POWERPC32_PLT_CHECK_LEN];
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR target = 0;
   int scan_limit, i;
@@ -898,7 +898,7 @@ ppc_linux_vsxregset (void)
 const struct regset *
 ppc_linux_cgprregset (struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (tdep->wordsize == 4)
     {
@@ -938,7 +938,7 @@ ppc_linux_collect_core_cpgrregset (const struct regset *regset,
 				   int regnum, void *buf, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   const struct regset *cgprregset = ppc_linux_cgprregset (gdbarch);
 
@@ -985,7 +985,7 @@ ppc_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					void *cb_data,
 					const struct regcache *regcache)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int have_altivec = tdep->ppc_vr0_regnum != -1;
   int have_vsx = tdep->ppc_vsr0_upper_regnum != -1;
   int have_ppr = tdep->ppc_ppr_regnum != -1;
@@ -1170,7 +1170,7 @@ ppc_linux_sigtramp_cache (struct frame_info *this_frame,
   CORE_ADDR fpregs;
   int i;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   base = get_frame_register_unsigned (this_frame,
@@ -1341,7 +1341,7 @@ ppc_linux_get_syscall_number (struct gdbarch *gdbarch,
 			      thread_info *thread)
 {
   struct regcache *regcache = get_thread_regcache (thread);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   /* Make sure we're in a 32- or 64-bit machine */
@@ -1417,7 +1417,7 @@ static int
 ppc_linux_syscall_record (struct regcache *regcache)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   ULONGEST scnum;
   enum gdb_syscall syscall_gdb;
   int ret;
@@ -1507,7 +1507,7 @@ ppc_linux_record_signal (struct gdbarch *gdbarch, struct regcache *regcache,
   const int SIGNAL_FRAMESIZE = 128;
   const int sizeof_rt_sigframe = 1440 * 2 + 8 * 2 + 4 * 6 + 8 + 8 + 128 + 512;
   ULONGEST sp;
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   for (i = 3; i <= 12; i++)
@@ -2042,7 +2042,7 @@ static void
 ppc_linux_init_abi (struct gdbarch_info info,
 		    struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   struct tdesc_arch_data *tdesc_data = info.tdesc_data;
   static const char *const stap_integer_prefixes[] = { "i", NULL };
   static const char *const stap_register_indirection_prefixes[] = { "(",
diff --git a/gdb/ppc-netbsd-nat.c b/gdb/ppc-netbsd-nat.c
index fb2dce501a4..91f18fbb83f 100644
--- a/gdb/ppc-netbsd-nat.c
+++ b/gdb/ppc-netbsd-nat.c
@@ -52,7 +52,7 @@ static ppc_nbsd_nat_target the_ppc_nbsd_nat_target;
 static int
 getregs_supplies (struct gdbarch *gdbarch, int regnum)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   return ((regnum >= tdep->ppc_gp0_regnum
 	   && regnum < tdep->ppc_gp0_regnum + ppc_num_gprs)
@@ -68,7 +68,7 @@ getregs_supplies (struct gdbarch *gdbarch, int regnum)
 static int
 getfpregs_supplies (struct gdbarch *gdbarch, int regnum)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
      point registers.  Traditionally, GDB's register set has still
@@ -159,7 +159,7 @@ ppcnbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
   struct switchframe sf;
   struct callframe cf;
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   /* The stack pointer shouldn't be zero.  */
diff --git a/gdb/ppc-netbsd-tdep.c b/gdb/ppc-netbsd-tdep.c
index cb3d8d5e5df..d8dc494979a 100644
--- a/gdb/ppc-netbsd-tdep.c
+++ b/gdb/ppc-netbsd-tdep.c
@@ -102,7 +102,7 @@ ppcnbsd_sigtramp_cache_init (const struct tramp_frame *self,
 			     CORE_ADDR func)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   CORE_ADDR addr, base;
   int i;
 
diff --git a/gdb/ppc-obsd-nat.c b/gdb/ppc-obsd-nat.c
index 93e1024b589..e480f19dc73 100644
--- a/gdb/ppc-obsd-nat.c
+++ b/gdb/ppc-obsd-nat.c
@@ -54,7 +54,7 @@ static ppc_obsd_nat_target the_ppc_obsd_nat_target;
 static int
 getfpregs_supplies (struct gdbarch *gdbarch, int regnum)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
      point registers.  Traditionally, GDB's register set has still
@@ -154,7 +154,7 @@ static int
 ppcobsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   struct switchframe sf;
   struct callframe cf;
   int i, regnum;
diff --git a/gdb/ppc-obsd-tdep.c b/gdb/ppc-obsd-tdep.c
index a2924e35bbc..90fb5e3a399 100644
--- a/gdb/ppc-obsd-tdep.c
+++ b/gdb/ppc-obsd-tdep.c
@@ -161,7 +161,7 @@ static struct trad_frame_cache *
 ppcobsd_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct trad_frame_cache *cache;
   CORE_ADDR addr, base, func;
diff --git a/gdb/ppc-sysv-tdep.c b/gdb/ppc-sysv-tdep.c
index 6c2fd1bfc99..ed6c2d4449d 100644
--- a/gdb/ppc-sysv-tdep.c
+++ b/gdb/ppc-sysv-tdep.c
@@ -65,7 +65,7 @@ ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 			      function_call_return_method return_method,
 			      CORE_ADDR struct_addr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int opencl_abi = ppc_sysv_use_opencl_abi (value_type (function));
   ULONGEST saved_sp;
@@ -597,7 +597,7 @@ get_decimal_float_return_value (struct gdbarch *gdbarch, struct type *valtype,
 				struct regcache *regcache, gdb_byte *readbuf,
 				const gdb_byte *writebuf)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   gdb_assert (valtype->code () == TYPE_CODE_DECFLOAT);
 
@@ -675,7 +675,7 @@ do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *func_type,
 			  gdb_byte *readbuf, const gdb_byte *writebuf,
 			  int broken_gcc)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int opencl_abi = func_type? ppc_sysv_use_opencl_abi (func_type) : 0;
 
@@ -1250,7 +1250,7 @@ ppc64_sysv_abi_push_val (struct gdbarch *gdbarch,
 			 const bfd_byte *val, int len, int align,
 			 struct ppc64_sysv_argpos *argpos)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int offset = 0;
 
   /* Enforce alignment of stack location, if requested.  */
@@ -1300,7 +1300,7 @@ static void
 ppc64_sysv_abi_push_integer (struct gdbarch *gdbarch, ULONGEST val,
 			     struct ppc64_sysv_argpos *argpos)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   gdb_byte buf[PPC_MAX_REGISTER_SIZE];
 
@@ -1318,7 +1318,7 @@ ppc64_sysv_abi_push_freg (struct gdbarch *gdbarch,
 			  struct type *type, const bfd_byte *val,
 			  struct ppc64_sysv_argpos *argpos)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   if (tdep->soft_float)
     return;
 
@@ -1403,7 +1403,7 @@ static void
 ppc64_sysv_abi_push_vreg (struct gdbarch *gdbarch, const bfd_byte *val,
 			  struct ppc64_sysv_argpos *argpos)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (argpos->regcache && argpos->vreg <= 13)
     argpos->regcache->cooked_write (tdep->ppc_vr0_regnum + argpos->vreg, val);
@@ -1419,7 +1419,7 @@ ppc64_sysv_abi_push_param (struct gdbarch *gdbarch,
 			   struct type *type, const bfd_byte *val,
 			   struct ppc64_sysv_argpos *argpos)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (type->code () == TYPE_CODE_FLT
       || type->code () == TYPE_CODE_DECFLOAT)
@@ -1545,7 +1545,7 @@ ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch,
 				CORE_ADDR struct_addr)
 {
   CORE_ADDR func_addr = find_function_addr (function, NULL);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int opencl_abi = ppc_sysv_use_opencl_abi (value_type (function));
   ULONGEST back_chain;
@@ -1739,7 +1739,7 @@ ppc64_sysv_abi_return_value_base (struct gdbarch *gdbarch, struct type *valtype,
 				  struct regcache *regcache, gdb_byte *readbuf,
 				  const gdb_byte *writebuf, int index)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* Integers live in GPRs starting at r3.  */
   if ((valtype->code () == TYPE_CODE_INT
@@ -1922,7 +1922,7 @@ ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct value *function,
 			     struct type *valtype, struct regcache *regcache,
 			     gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   struct type *func_type = function ? value_type (function) : NULL;
   int opencl_abi = func_type? ppc_sysv_use_opencl_abi (func_type) : 0;
   struct type *eltype;
diff --git a/gdb/ppc64-tdep.c b/gdb/ppc64-tdep.c
index 32931f72691..0437ca7e3f3 100644
--- a/gdb/ppc64-tdep.c
+++ b/gdb/ppc64-tdep.c
@@ -89,7 +89,7 @@ ppc64_plt_entry_point (struct frame_info *frame, CORE_ADDR plt_off)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   CORE_ADDR tocp;
 
   if (execution_direction == EXEC_REVERSE)
diff --git a/gdb/riscv-linux-tdep.c b/gdb/riscv-linux-tdep.c
index 387b8bdbc2f..5bda2e5c824 100644
--- a/gdb/riscv-linux-tdep.c
+++ b/gdb/riscv-linux-tdep.c
@@ -179,7 +179,7 @@ riscv_linux_syscall_next_pc (struct frame_info *frame)
 static void
 riscv_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
index 69f2123dcdb..2d41be96b20 100644
--- a/gdb/riscv-tdep.c
+++ b/gdb/riscv-tdep.c
@@ -733,7 +733,7 @@ show_riscv_debug_variable (struct ui_file *file, int from_tty,
 int
 riscv_isa_xlen (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   return tdep->isa_features.xlen;
 }
 
@@ -742,7 +742,7 @@ riscv_isa_xlen (struct gdbarch *gdbarch)
 int
 riscv_abi_xlen (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   return tdep->abi_features.xlen;
 }
 
@@ -751,7 +751,7 @@ riscv_abi_xlen (struct gdbarch *gdbarch)
 int
 riscv_isa_flen (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   return tdep->isa_features.flen;
 }
 
@@ -760,7 +760,7 @@ riscv_isa_flen (struct gdbarch *gdbarch)
 int
 riscv_abi_flen (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   return tdep->abi_features.flen;
 }
 
@@ -769,7 +769,7 @@ riscv_abi_flen (struct gdbarch *gdbarch)
 bool
 riscv_abi_embedded (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   return tdep->abi_features.embedded;
 }
 
@@ -786,7 +786,7 @@ riscv_has_fp_regs (struct gdbarch *gdbarch)
 static bool
 riscv_has_fp_abi (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   return tdep->abi_features.flen > 0;
 }
 
@@ -910,7 +910,7 @@ riscv_register_name (struct gdbarch *gdbarch, int regnum)
      will show up in 'info register all'.  Unless, we identify the
      duplicate copies of these registers (in riscv_tdesc_unknown_reg) and
      then hide the registers here by giving them no name.  */
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   if (tdep->duplicate_fflags_regnum == regnum)
     return NULL;
   if (tdep->duplicate_frm_regnum == regnum)
@@ -938,7 +938,7 @@ riscv_register_name (struct gdbarch *gdbarch, int regnum)
 static struct type *
 riscv_fpreg_d_type (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
 
   if (tdep->riscv_fpreg_d_type == nullptr)
     {
@@ -1260,7 +1260,7 @@ riscv_is_regnum_a_named_csr (int regnum)
 static bool
 riscv_is_unknown_csr (struct gdbarch *gdbarch, int regnum)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   return (regnum >= tdep->unknown_csrs_first_regnum
 	  && regnum < (tdep->unknown_csrs_first_regnum
 		       + tdep->unknown_csrs_count));
@@ -3600,7 +3600,7 @@ riscv_tdesc_unknown_reg (struct gdbarch *gdbarch, tdesc_feature *feature,
      record their register numbers here.  */
   if (strcmp (tdesc_feature_name (feature), riscv_freg_feature.name ()) == 0)
     {
-      riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
       int *regnum_ptr = nullptr;
 
       if (strcmp (reg_name, "fflags") == 0)
@@ -3631,7 +3631,7 @@ riscv_tdesc_unknown_reg (struct gdbarch *gdbarch, tdesc_feature *feature,
      about register groups in riscv_register_reggroup_p.  */
   if (strcmp (tdesc_feature_name (feature), riscv_csr_feature.name ()) == 0)
     {
-      riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
       if (tdep->unknown_csrs_first_regnum == -1)
 	tdep->unknown_csrs_first_regnum = possible_regnum;
       gdb_assert (tdep->unknown_csrs_first_regnum
@@ -3733,7 +3733,7 @@ riscv_gdbarch_init (struct gdbarch_info info,
 	 we are looking for.  If it doesn't then we can't reuse this
 	 gdbarch.  */
       riscv_gdbarch_tdep *other_tdep
-	= (riscv_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<riscv_gdbarch_tdep> (arches->gdbarch);
 
       if (other_tdep->isa_features != features
 	  || other_tdep->abi_features != abi_features)
@@ -3858,7 +3858,7 @@ riscv_next_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   struct gdbarch *gdbarch = regcache->arch ();
   const riscv_gdbarch_tdep *tdep
-    = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+    = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   struct riscv_insn insn;
   CORE_ADDR next_pc;
 
diff --git a/gdb/rl78-tdep.c b/gdb/rl78-tdep.c
index 6ea0473081d..2462e7a191d 100644
--- a/gdb/rl78-tdep.c
+++ b/gdb/rl78-tdep.c
@@ -267,7 +267,7 @@ struct rl78_prologue
 static struct type *
 rl78_psw_type (struct gdbarch *gdbarch)
 {
-  rl78_gdbarch_tdep *tdep = (rl78_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  rl78_gdbarch_tdep *tdep = gdbarch_tdep<rl78_gdbarch_tdep> (gdbarch);
 
   if (tdep->rl78_psw_type == NULL)
     {
@@ -291,7 +291,7 @@ rl78_psw_type (struct gdbarch *gdbarch)
 static struct type *
 rl78_register_type (struct gdbarch *gdbarch, int reg_nr)
 {
-  rl78_gdbarch_tdep *tdep = (rl78_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  rl78_gdbarch_tdep *tdep = gdbarch_tdep<rl78_gdbarch_tdep> (gdbarch);
 
   if (reg_nr == RL78_PC_REGNUM)
     return tdep->rl78_code_pointer;
@@ -1248,7 +1248,7 @@ rl78_return_value (struct gdbarch *gdbarch,
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   ULONGEST valtype_len = TYPE_LENGTH (valtype);
-  rl78_gdbarch_tdep *tdep = (rl78_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  rl78_gdbarch_tdep *tdep = gdbarch_tdep<rl78_gdbarch_tdep> (gdbarch);
   int is_g10 = tdep->elf_flags & E_FLAG_RL78_G10;
 
   if (valtype_len > 8)
@@ -1394,7 +1394,7 @@ rl78_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       rl78_gdbarch_tdep *tdep
-	= (rl78_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<rl78_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->elf_flags != elf_flags)
 	continue;
diff --git a/gdb/rs6000-aix-nat.c b/gdb/rs6000-aix-nat.c
index 8563aea313a..8697d27b4ed 100644
--- a/gdb/rs6000-aix-nat.c
+++ b/gdb/rs6000-aix-nat.c
@@ -115,7 +115,7 @@ static rs6000_nat_target the_rs6000_nat_target;
 static int
 regmap (struct gdbarch *gdbarch, int regno, int *isfloat)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   *isfloat = 0;
   if (tdep->ppc_gp0_regnum <= regno
@@ -317,7 +317,7 @@ rs6000_nat_target::fetch_registers (struct regcache *regcache, int regno)
 
   else
     {
-      ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
       /* Read 32 general purpose registers.  */
       for (regno = tdep->ppc_gp0_regnum;
@@ -359,7 +359,7 @@ rs6000_nat_target::store_registers (struct regcache *regcache, int regno)
 
   else
     {
-      ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
       /* Write general purpose registers first.  */
       for (regno = tdep->ppc_gp0_regnum;
diff --git a/gdb/rs6000-aix-tdep.c b/gdb/rs6000-aix-tdep.c
index 867f21dc634..41384993c26 100644
--- a/gdb/rs6000-aix-tdep.c
+++ b/gdb/rs6000-aix-tdep.c
@@ -75,7 +75,7 @@ aix_sighandle_frame_cache (struct frame_info *this_frame,
   LONGEST backchain;
   CORE_ADDR base, base_orig, func;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct trad_frame_cache *this_trad_cache;
 
@@ -261,7 +261,7 @@ rs6000_aix_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					 void *cb_data,
 					 const struct regcache *regcache)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   if (tdep->wordsize == 4)
     cb (".reg", 592, 592, &rs6000_aix32_regset, NULL, cb_data);
   else
@@ -292,7 +292,7 @@ rs6000_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 			function_call_return_method return_method,
 			CORE_ADDR struct_addr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int ii;
   int len = 0;
@@ -522,7 +522,7 @@ rs6000_return_value (struct gdbarch *gdbarch, struct value *function,
 		     struct type *valtype, struct regcache *regcache,
 		     gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   /* The calling convention this function implements assumes the
@@ -660,7 +660,7 @@ rs6000_convert_from_func_ptr_addr (struct gdbarch *gdbarch,
 				   CORE_ADDR addr,
 				   struct target_ops *targ)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct obj_section *s;
 
@@ -704,7 +704,7 @@ branch_dest (struct regcache *regcache, int opcode, int instr,
 	     CORE_ADDR pc, CORE_ADDR safety)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR dest;
   int immediate;
@@ -972,7 +972,7 @@ static struct ld_info
 rs6000_aix_extract_ld_info (struct gdbarch *gdbarch,
 			    const gdb_byte *ldi_buf)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
   const struct ld_info_desc desc
@@ -1131,7 +1131,7 @@ rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch,
 static void
 rs6000_aix_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* RS6000/AIX does not support PT_STEP.  Has to be simulated.  */
   set_gdbarch_software_single_step (gdbarch, rs6000_software_single_step);
diff --git a/gdb/rs6000-lynx178-tdep.c b/gdb/rs6000-lynx178-tdep.c
index 844d0a4ede2..dc13dd3fa73 100644
--- a/gdb/rs6000-lynx178-tdep.c
+++ b/gdb/rs6000-lynx178-tdep.c
@@ -36,7 +36,7 @@ rs6000_lynx178_push_dummy_call (struct gdbarch *gdbarch,
 				function_call_return_method return_method,
 				CORE_ADDR struct_addr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int ii;
   int len = 0;
@@ -265,7 +265,7 @@ rs6000_lynx178_return_value (struct gdbarch *gdbarch, struct value *function,
 			     struct type *valtype, struct regcache *regcache,
 			     gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   /* The calling convention this function implements assumes the
diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
index 6815dfaa820..640459f1c28 100644
--- a/gdb/rs6000-tdep.c
+++ b/gdb/rs6000-tdep.c
@@ -201,7 +201,7 @@ struct rs6000_framedata
 int
 vsx_register_p (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   if (tdep->ppc_vsr0_regnum < 0)
     return 0;
   else
@@ -213,7 +213,7 @@ vsx_register_p (struct gdbarch *gdbarch, int regno)
 int
 altivec_register_p (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   if (tdep->ppc_vr0_regnum < 0 || tdep->ppc_vrsave_regnum < 0)
     return 0;
   else
@@ -225,7 +225,7 @@ altivec_register_p (struct gdbarch *gdbarch, int regno)
 int
 spe_register_p (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   
   /* Is it a reference to EV0 -- EV31, and do we have those?  */
   if (IS_SPE_PSEUDOREG (tdep, regno))
@@ -257,7 +257,7 @@ spe_register_p (struct gdbarch *gdbarch, int regno)
 int
 ppc_floating_point_unit_p (struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   return (tdep->ppc_fp0_regnum >= 0
 	  && tdep->ppc_fpscr_regnum >= 0);
@@ -268,7 +268,7 @@ ppc_floating_point_unit_p (struct gdbarch *gdbarch)
 int
 ppc_altivec_support_p (struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   return (tdep->ppc_vr0_regnum >= 0
 	  && tdep->ppc_vrsave_regnum >= 0);
@@ -297,7 +297,7 @@ set_sim_regno (int *table, int gdb_regno, int sim_regno)
 static void
 init_sim_regno_table (struct gdbarch *arch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (arch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (arch);
   int total_regs = gdbarch_num_regs (arch);
   int *sim_regno = GDBARCH_OBSTACK_CALLOC (arch, total_regs, int);
   int i;
@@ -391,7 +391,7 @@ init_sim_regno_table (struct gdbarch *arch)
 static int
 rs6000_register_sim_regno (struct gdbarch *gdbarch, int reg)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int sim_regno;
 
   if (tdep->sim_regno == NULL)
@@ -522,7 +522,7 @@ ppc_supply_gregset (const struct regset *regset, struct regcache *regcache,
 		    int regnum, const void *gregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   const struct ppc_reg_offsets *offsets
     = (const struct ppc_reg_offsets *) regset->regmap;
   size_t offset;
@@ -578,7 +578,7 @@ ppc_supply_fpregset (const struct regset *regset, struct regcache *regcache,
   if (!ppc_floating_point_unit_p (gdbarch))
     return;
 
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   offsets = (const struct ppc_reg_offsets *) regset->regmap;
   if (regnum == -1)
     {
@@ -611,7 +611,7 @@ ppc_collect_gregset (const struct regset *regset,
 		     int regnum, void *gregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   const struct ppc_reg_offsets *offsets
     = (const struct ppc_reg_offsets *) regset->regmap;
   size_t offset;
@@ -668,7 +668,7 @@ ppc_collect_fpregset (const struct regset *regset,
   if (!ppc_floating_point_unit_p (gdbarch))
     return;
 
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   offsets = (const struct ppc_reg_offsets *) regset->regmap;
   if (regnum == -1)
     {
@@ -746,7 +746,7 @@ static int
 rs6000_in_function_epilogue_frame_p (struct frame_info *curfrm,
 				     struct gdbarch *gdbarch, CORE_ADDR pc)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   bfd_byte insn_buf[PPC_INSN_SIZE];
   CORE_ADDR scan_pc, func_start, func_end, epilogue_start, epilogue_end;
@@ -1042,7 +1042,7 @@ ppc_displaced_step_fixup (struct gdbarch *gdbarch,
       if (insn & 0x1)
 	{
 	  /* Link register needs to be set to the next instruction's PC.  */
-	  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 	  regcache_cooked_write_unsigned (regs,
 					  tdep->ppc_lr_regnum,
 					  from + PPC_INSN_SIZE);
@@ -1590,7 +1590,7 @@ skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc, CORE_ADDR lim_pc,
   int num_skip_non_prologue_insns = 0;
   int r0_contains_arg = 0;
   const struct bfd_arch_info *arch_info = gdbarch_bfd_arch_info (gdbarch);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   memset (fdata, 0, sizeof (struct rs6000_framedata));
@@ -2310,7 +2310,7 @@ static CORE_ADDR
 rs6000_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   unsigned int ii, op;
   int rel;
@@ -2368,7 +2368,7 @@ rs6000_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
 static struct type *
 rs6000_builtin_type_vec64 (struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->ppc_builtin_type_vec64)
     {
@@ -2413,7 +2413,7 @@ rs6000_builtin_type_vec64 (struct gdbarch *gdbarch)
 static struct type *
 rs6000_builtin_type_vec128 (struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->ppc_builtin_type_vec128)
     {
@@ -2467,7 +2467,7 @@ rs6000_builtin_type_vec128 (struct gdbarch *gdbarch)
 static const char *
 rs6000_register_name (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* The upper half "registers" have names in the XML description,
      but we present only the low GPRs and the full 64-bit registers
@@ -2605,7 +2605,7 @@ rs6000_register_name (struct gdbarch *gdbarch, int regno)
 static struct type *
 rs6000_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* These are the e500 pseudo-registers.  */
   if (IS_SPE_PSEUDOREG (tdep, regnum))
@@ -2644,7 +2644,7 @@ static int
 rs6000_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 				   const struct reggroup *group)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (IS_V_ALIAS_PSEUDOREG (tdep, regnum))
     return 0;
@@ -2659,7 +2659,7 @@ static int
 rs6000_convert_register_p (struct gdbarch *gdbarch, int regnum,
 			   struct type *type)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   return (tdep->ppc_fp0_regnum >= 0
 	  && regnum >= tdep->ppc_fp0_regnum
@@ -2744,7 +2744,7 @@ e500_move_ev_register (move_ev_register_func move,
 		       struct regcache *regcache, int ev_reg, void *buffer)
 {
   struct gdbarch *arch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (arch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (arch);
   int reg_index;
   gdb_byte *byte_buffer = (gdb_byte *) buffer;
   enum register_status status;
@@ -2785,7 +2785,7 @@ e500_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int ev_reg, gdb_byte *buffer)
 {
   struct gdbarch *arch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index;
   enum register_status status;
 
@@ -2826,7 +2826,7 @@ static enum register_status
 dfp_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int reg_nr, gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, fp0;
   enum register_status status;
 
@@ -2866,7 +2866,7 @@ static void
 dfp_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
 			    int reg_nr, const gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, fp0;
 
   if (IS_DFP_PSEUDOREG (tdep, reg_nr))
@@ -2903,7 +2903,7 @@ v_alias_pseudo_register_read (struct gdbarch *gdbarch,
 			      readable_regcache *regcache, int reg_nr,
 			      gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   gdb_assert (IS_V_ALIAS_PSEUDOREG (tdep, reg_nr));
 
   return regcache->raw_read (tdep->ppc_vr0_regnum
@@ -2918,7 +2918,7 @@ v_alias_pseudo_register_write (struct gdbarch *gdbarch,
 			       struct regcache *regcache,
 			       int reg_nr, const gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   gdb_assert (IS_V_ALIAS_PSEUDOREG (tdep, reg_nr));
 
   regcache->raw_write (tdep->ppc_vr0_regnum
@@ -2930,7 +2930,7 @@ static enum register_status
 vsx_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int reg_nr, gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0, fp0, vsr0_upper;
   enum register_status status;
 
@@ -2978,7 +2978,7 @@ static void
 vsx_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
 			    int reg_nr, const gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0, fp0, vsr0_upper;
 
   if (IS_VSX_PSEUDOREG (tdep, reg_nr))
@@ -3020,7 +3020,7 @@ static enum register_status
 efp_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int reg_nr, gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0;
 
   if (IS_EFP_PSEUDOREG (tdep, reg_nr))
@@ -3049,7 +3049,7 @@ static void
 efp_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
 			    int reg_nr, const gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0;
   int offset = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG ? 0 : 8;
 
@@ -3085,7 +3085,7 @@ rs6000_pseudo_register_read (struct gdbarch *gdbarch,
 			     int reg_nr, gdb_byte *buffer)
 {
   struct gdbarch *regcache_arch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   gdb_assert (regcache_arch == gdbarch);
 
@@ -3116,7 +3116,7 @@ rs6000_pseudo_register_write (struct gdbarch *gdbarch,
 			      int reg_nr, const gdb_byte *buffer)
 {
   struct gdbarch *regcache_arch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   gdb_assert (regcache_arch == gdbarch);
 
@@ -3147,7 +3147,7 @@ static void
 dfp_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				struct agent_expr *ax, int reg_nr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, fp0;
 
   if (IS_DFP_PSEUDOREG (tdep, reg_nr))
@@ -3174,7 +3174,7 @@ static void
 v_alias_pseudo_register_collect (struct gdbarch *gdbarch,
 				 struct agent_expr *ax, int reg_nr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   gdb_assert (IS_V_ALIAS_PSEUDOREG (tdep, reg_nr));
 
   ax_reg_mask (ax, tdep->ppc_vr0_regnum
@@ -3188,7 +3188,7 @@ static void
 vsx_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				struct agent_expr *ax, int reg_nr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0, fp0, vsr0_upper;
 
   if (IS_VSX_PSEUDOREG (tdep, reg_nr))
@@ -3226,7 +3226,7 @@ static void
 efp_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				struct agent_expr *ax, int reg_nr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0;
 
   if (IS_EFP_PSEUDOREG (tdep, reg_nr))
@@ -3249,7 +3249,7 @@ static int
 rs6000_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				   struct agent_expr *ax, int reg_nr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   if (IS_SPE_PSEUDOREG (tdep, reg_nr))
     {
       int reg_index = reg_nr - tdep->ppc_ev0_regnum;
@@ -3289,7 +3289,7 @@ rs6000_gen_return_address (struct gdbarch *gdbarch,
 			   struct agent_expr *ax, struct axs_value *value,
 			   CORE_ADDR scope)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   value->type = register_type (gdbarch, tdep->ppc_lr_regnum);
   value->kind = axs_lvalue_register;
   value->u.reg = tdep->ppc_lr_regnum;
@@ -3300,7 +3300,7 @@ rs6000_gen_return_address (struct gdbarch *gdbarch,
 static int
 rs6000_stab_reg_to_regnum (struct gdbarch *gdbarch, int num)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (0 <= num && num <= 31)
     return tdep->ppc_gp0_regnum + num;
@@ -3342,7 +3342,7 @@ rs6000_stab_reg_to_regnum (struct gdbarch *gdbarch, int num)
 static int
 rs6000_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int num)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (0 <= num && num <= 31)
     return tdep->ppc_gp0_regnum + num;
@@ -3561,7 +3561,7 @@ rs6000_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct rs6000_frame_cache *cache;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct rs6000_framedata fdata;
   int wordsize = tdep->wordsize;
@@ -3797,7 +3797,7 @@ rs6000_epilogue_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct rs6000_frame_cache *cache;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (*this_cache)
     return (struct rs6000_frame_cache *) *this_cache;
@@ -3918,7 +3918,7 @@ ppc_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
 			    struct dwarf2_frame_state_reg *reg,
 			    struct frame_info *this_frame)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* PPC32 and PPC64 ABI's are the same regarding volatile and
      non-volatile registers.  We will use the same code for both.  */
@@ -4229,7 +4229,7 @@ static int
 ppc_process_record_op4 (struct gdbarch *gdbarch, struct regcache *regcache,
 			CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_FIELD (insn, 21, 11);
   int vra = PPC_FIELD (insn, 11, 5);
 
@@ -4771,7 +4771,7 @@ static int
 ppc_process_record_op6 (struct gdbarch *gdbarch, struct regcache *regcache,
 			CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int subtype = PPC_FIELD (insn, 28, 4);
   CORE_ADDR ea = 0;
 
@@ -4799,7 +4799,7 @@ static int
 ppc_process_record_op19 (struct gdbarch *gdbarch, struct regcache *regcache,
 			   CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_EXTOP (insn);
 
   switch (ext & 0x01f)
@@ -4855,7 +4855,7 @@ ppc_process_record_op31_177 (struct gdbarch *gdbarch,
 {
   int RA_opcode = PPC_RA(insn);
   int as = PPC_FIELD (insn, 6, 3);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   switch (RA_opcode)
     {
@@ -4875,7 +4875,7 @@ static int
 ppc_process_record_op31 (struct gdbarch *gdbarch, struct regcache *regcache,
 			   CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_EXTOP (insn);
   int tmp, nr, nb = 0, i;
   CORE_ADDR at_dcsz, ea = 0;
@@ -5536,7 +5536,7 @@ static int
 ppc_process_record_op59 (struct gdbarch *gdbarch, struct regcache *regcache,
 			 CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_EXTOP (insn);
   int at = PPC_FIELD (insn, 6, 3);
 
@@ -5701,7 +5701,7 @@ ppc_process_record_op60_XX2 (struct gdbarch *gdbarch,
 			     struct regcache *regcache,
 			     CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int RA_opcode = PPC_RA(insn);
 
   switch (RA_opcode)
@@ -5742,7 +5742,7 @@ static int
 ppc_process_record_op60 (struct gdbarch *gdbarch, struct regcache *regcache,
 			   CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_EXTOP (insn);
 
   switch (ext >> 2)
@@ -6097,7 +6097,7 @@ static int
 ppc_process_record_op61 (struct gdbarch *gdbarch, struct regcache *regcache,
 			   CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   ULONGEST ea = 0;
   int size;
 
@@ -6156,7 +6156,7 @@ static int
 ppc_process_record_op63 (struct gdbarch *gdbarch, struct regcache *regcache,
 			   CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_EXTOP (insn);
   int tmp;
 
@@ -6453,7 +6453,7 @@ ppc_process_record_prefix_op42 (struct gdbarch *gdbarch,
 				struct regcache *regcache,
 				uint32_t insn_prefix, uint32_t insn_suffix)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST1 = PPC_FIELD (insn_prefix, 8, 1);
 
@@ -6489,7 +6489,7 @@ ppc_process_record_prefix_op59_XX3 (struct gdbarch *gdbarch,
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST4 = PPC_FIELD (insn_prefix, 8, 4);
   int at = PPC_FIELD (insn_suffix, 6, 3);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (type == 3)
     {
@@ -6603,7 +6603,7 @@ ppc_process_record_prefix_store (struct gdbarch *gdbarch,
 				 CORE_ADDR addr, uint32_t insn_prefix,
 				 uint32_t insn_suffix)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   ULONGEST iaddr = 0;
   int size;
   int R = PPC_BIT (insn_prefix, 11);
@@ -6659,7 +6659,7 @@ ppc_process_record_prefix_op32 (struct gdbarch *gdbarch,
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST1 = PPC_FIELD (insn_prefix, 8, 1);
   int ST4 = PPC_FIELD (insn_prefix, 8, 4);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (type == 1)
     {
@@ -6713,7 +6713,7 @@ ppc_process_record_prefix_op33 (struct gdbarch *gdbarch,
 {
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST4 = PPC_FIELD (insn_prefix, 8, 4);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (type == 1)
     {
@@ -6751,7 +6751,7 @@ ppc_process_record_prefix_op34 (struct gdbarch *gdbarch,
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST1 = PPC_FIELD (insn_prefix, 8, 1);
   int ST4 = PPC_FIELD (insn_prefix, 8, 4);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (type == 1)
     {
@@ -6797,7 +6797,7 @@ ppc_process_record_prefix_store_vsx_ds_form (struct gdbarch *gdbarch,
 					     uint32_t insn_prefix,
 					     uint32_t insn_suffix)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   ULONGEST ea = 0;
   int size;
   int R = PPC_BIT (insn_prefix, 11);
@@ -6850,7 +6850,7 @@ ppc_process_record_prefix_vsx_d_form (struct gdbarch *gdbarch,
 				      uint32_t insn_prefix,
 				      uint32_t insn_suffix)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   ULONGEST ea = 0;
   int size;
   int R = PPC_BIT (insn_prefix, 11);
@@ -6907,7 +6907,7 @@ ppc_process_prefix_instruction (int insn_prefix, int insn_suffix,
 {
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST1 = PPC_FIELD (insn_prefix, 8, 1);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int op6;
 
   /* D-form has uses a 5-bit opcode in the instruction suffix */
@@ -7086,7 +7086,7 @@ int
 ppc_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
 		      CORE_ADDR addr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   uint32_t insn, insn_suffix;
   int op6, tmp, i;
@@ -8150,7 +8150,7 @@ rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 	 meaningful, because 64-bit CPUs can run in 32-bit mode.  So, perform
 	 separate word size check.  */
       ppc_gdbarch_tdep *tdep
-	= (ppc_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<ppc_gdbarch_tdep> (arches->gdbarch);
       if (tdep && tdep->elf_abi != elf_abi)
 	continue;
       if (tdep && tdep->soft_float != soft_float)
@@ -8452,7 +8452,7 @@ rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 rs6000_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (tdep == NULL)
     return;
diff --git a/gdb/rx-tdep.c b/gdb/rx-tdep.c
index 2a24ebba2b6..c67d4057195 100644
--- a/gdb/rx-tdep.c
+++ b/gdb/rx-tdep.c
@@ -964,7 +964,7 @@ rx_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       rx_gdbarch_tdep *tdep
-	= (rx_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<rx_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->elf_flags != elf_flags)
 	continue;
diff --git a/gdb/s390-linux-tdep.c b/gdb/s390-linux-tdep.c
index 9d4e2d09f2a..03611fe1d23 100644
--- a/gdb/s390-linux-tdep.c
+++ b/gdb/s390-linux-tdep.c
@@ -79,7 +79,7 @@ static void
 s390_write_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
 
@@ -269,7 +269,7 @@ s390_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				   void *cb_data,
 				   const struct regcache *regcache)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   const int gregset_size = (tdep->abi == ABI_LINUX_S390 ?
 			    s390_sizeof_gregset : s390x_sizeof_gregset);
 
@@ -390,7 +390,7 @@ s390_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
 				  void **this_prologue_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   int word_size = gdbarch_ptr_bit (gdbarch) / 8;
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct s390_sigtramp_unwind_cache *info;
@@ -561,7 +561,7 @@ s390_linux_get_syscall_number (struct gdbarch *gdbarch,
 			       thread_info *thread)
 {
   struct regcache *regs = get_thread_regcache (thread);
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   ULONGEST pc;
   ULONGEST svc_number = -1;
@@ -594,7 +594,7 @@ static int
 s390_all_but_pc_registers_record (struct regcache *regcache)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   int i;
 
   for (i = 0; i < 16; i++)
@@ -802,7 +802,7 @@ static int
 s390_linux_syscall_record (struct regcache *regcache, LONGEST syscall_native)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   int ret;
   enum gdb_syscall syscall_gdb;
 
@@ -853,7 +853,7 @@ static int
 s390_linux_record_signal (struct gdbarch *gdbarch, struct regcache *regcache,
 			  enum gdb_signal signal)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   /* There are two kinds of signal frames on s390. rt_sigframe is always
      the larger one, so don't even bother with sigframe.  */
   const int sizeof_rt_sigframe = (tdep->abi == ABI_LINUX_ZSERIES ?
@@ -1117,7 +1117,7 @@ s390_init_linux_record_tdep (struct linux_record_tdep *record_tdep,
 static void
 s390_linux_init_abi_any (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   tdep->s390_syscall_record = s390_linux_syscall_record;
 
@@ -1152,7 +1152,7 @@ s390_linux_init_abi_any (struct gdbarch_info info, struct gdbarch *gdbarch)
 static void
 s390_linux_init_abi_31 (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   tdep->abi = ABI_LINUX_S390;
 
@@ -1168,7 +1168,7 @@ s390_linux_init_abi_31 (struct gdbarch_info info, struct gdbarch *gdbarch)
 static void
 s390_linux_init_abi_64 (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   tdep->abi = ABI_LINUX_ZSERIES;
 
diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c
index 14b03a167d7..2aeb3a14637 100644
--- a/gdb/s390-tdep.c
+++ b/gdb/s390-tdep.c
@@ -1045,7 +1045,7 @@ s390_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
 static int
 s390_register_call_saved (struct gdbarch *gdbarch, int regnum)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   switch (tdep->abi)
     {
@@ -1076,7 +1076,7 @@ s390_guess_tracepoint_registers (struct gdbarch *gdbarch,
 				 struct regcache *regcache,
 				 CORE_ADDR addr)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   int sz = register_size (gdbarch, S390_PSWA_REGNUM);
   gdb_byte *reg = (gdb_byte *) alloca (sz);
   ULONGEST pswm, pswa;
@@ -1172,7 +1172,7 @@ enum { s390_dwarf_reg_r0l = ARRAY_SIZE (s390_dwarf_regmap) - 16 };
 static int
 s390_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   int gdb_reg = -1;
 
   /* In a 32-on-64 debug scenario, debug info refers to the full
@@ -1231,7 +1231,7 @@ static struct value *
 s390_value_from_register (struct gdbarch *gdbarch, struct type *type,
 			  int regnum, struct frame_id frame_id)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   struct value *value = default_value_from_register (gdbarch, type,
 						     regnum, frame_id);
   check_typedef (type);
@@ -1250,7 +1250,7 @@ s390_value_from_register (struct gdbarch *gdbarch, struct type *type,
 static const char *
 s390_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   if (regnum == tdep->pc_regnum)
     return "pc";
@@ -1284,7 +1284,7 @@ s390_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 static struct type *
 s390_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   if (regnum == tdep->pc_regnum)
     return builtin_type (gdbarch)->builtin_func_ptr;
@@ -1308,7 +1308,7 @@ static enum register_status
 s390_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int regnum, gdb_byte *buf)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int regsize = register_size (gdbarch, regnum);
   ULONGEST val;
@@ -1383,7 +1383,7 @@ static void
 s390_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
 			    int regnum, const gdb_byte *buf)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int regsize = register_size (gdbarch, regnum);
   ULONGEST val, psw;
@@ -1442,7 +1442,7 @@ static int
 s390_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 				 const struct reggroup *group)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   /* We usually save/restore the whole PSW, which includes PC and CC.
      However, some older gdbservers may not support saving/restoring
@@ -1470,7 +1470,7 @@ static int
 s390_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				 struct agent_expr *ax, int regnum)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   if (regnum == tdep->pc_regnum)
     {
       ax_reg_mask (ax, S390_PSWA_REGNUM);
@@ -1504,7 +1504,7 @@ static int
 s390_ax_pseudo_register_push_stack (struct gdbarch *gdbarch,
 				    struct agent_expr *ax, int regnum)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   if (regnum == tdep->pc_regnum)
     {
       ax_reg (ax, S390_PSWA_REGNUM);
@@ -1905,7 +1905,7 @@ s390_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 		      function_call_return_method return_method,
 		      CORE_ADDR struct_addr)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   int word_size = gdbarch_ptr_bit (gdbarch) / 8;
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int i;
@@ -2084,7 +2084,7 @@ s390_return_value (struct gdbarch *gdbarch, struct value *function,
       break;
     case TYPE_CODE_ARRAY:
       {
-	s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 	rvc = (tdep->vector_abi == S390_VECTOR_ABI_128
 	       && TYPE_LENGTH (type) <= 16 && type->is_vector ())
 	  ? RETURN_VALUE_REGISTER_CONVENTION
@@ -2168,7 +2168,7 @@ s390_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
 static CORE_ADDR
 s390_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   ULONGEST pc;
   pc = frame_unwind_register_unsigned (next_frame, tdep->pc_regnum);
   return gdbarch_addr_bits_remove (gdbarch, pc);
@@ -2190,7 +2190,7 @@ static struct value *
 s390_unwind_pseudo_register (struct frame_info *this_frame, int regnum)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   struct type *type = register_type (gdbarch, regnum);
 
   /* Unwind PC via PSW address.  */
@@ -2775,7 +2775,7 @@ static CORE_ADDR
 s390_record_address_mask (struct gdbarch *gdbarch, struct regcache *regcache,
 			  CORE_ADDR val)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   ULONGEST pswm, pswa;
   int am;
   if (tdep->abi == ABI_LINUX_S390)
@@ -2842,7 +2842,7 @@ s390_record_calc_disp_vsce (struct gdbarch *gdbarch, struct regcache *regcache,
 			    uint8_t vx, uint8_t el, uint8_t es, uint16_t bd,
 			    int8_t dh, CORE_ADDR *res)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   ULONGEST x;
   gdb_byte buf[16];
@@ -2885,7 +2885,7 @@ static int s390_popcnt (unsigned int x) {
 static int
 s390_record_gpr_g (struct gdbarch *gdbarch, struct regcache *regcache, int i)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + i))
     return -1;
   if (tdep->abi == ABI_LINUX_S390)
@@ -2899,7 +2899,7 @@ s390_record_gpr_g (struct gdbarch *gdbarch, struct regcache *regcache, int i)
 static int
 s390_record_gpr_h (struct gdbarch *gdbarch, struct regcache *regcache, int i)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   if (tdep->abi == ABI_LINUX_S390)
     {
       if (record_full_arch_list_add_reg (regcache, S390_R0_UPPER_REGNUM + i))
@@ -2939,7 +2939,7 @@ static int
 s390_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
 		     CORE_ADDR addr)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   uint16_t insn[3] = {0};
   /* Instruction as bytes.  */
   uint8_t ibyte[6];
@@ -7178,7 +7178,7 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       s390_gdbarch_tdep *tmp
-	= (s390_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<s390_gdbarch_tdep> (arches->gdbarch);
 
       if (!tmp)
 	continue;
diff --git a/gdb/sh-linux-tdep.c b/gdb/sh-linux-tdep.c
index 2975a8f5d3d..f146f023add 100644
--- a/gdb/sh-linux-tdep.c
+++ b/gdb/sh-linux-tdep.c
@@ -195,7 +195,7 @@ sh_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   set_gdbarch_fetch_tls_load_module_address (gdbarch,
 					     svr4_fetch_objfile_link_map);
 
-  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
 
   /* Remember regset characteristics.  The sizes should match
      elf_gregset_t and elf_fpregset_t from Linux.  */
diff --git a/gdb/sh-netbsd-tdep.c b/gdb/sh-netbsd-tdep.c
index 4fbb53b49ff..49760337c4b 100644
--- a/gdb/sh-netbsd-tdep.c
+++ b/gdb/sh-netbsd-tdep.c
@@ -63,7 +63,7 @@ static void
 shnbsd_init_abi (struct gdbarch_info info,
 		  struct gdbarch *gdbarch)
 {
-  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
   nbsd_init_abi (info, gdbarch);
 
   tdep->core_gregmap = (struct sh_corefile_regmap *)regmap;
diff --git a/gdb/sh-tdep.c b/gdb/sh-tdep.c
index 2341a9beef6..062df860c81 100644
--- a/gdb/sh-tdep.c
+++ b/gdb/sh-tdep.c
@@ -1554,7 +1554,7 @@ sh_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 static struct type *
 sh_littlebyte_bigword_type (struct gdbarch *gdbarch)
 {
-  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
 
   if (tdep->sh_littlebyte_bigword_type == NULL)
     tdep->sh_littlebyte_bigword_type
@@ -2146,7 +2146,7 @@ sh_corefile_supply_regset (const struct regset *regset,
 			   int regnum, const void *regs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
   const struct sh_corefile_regmap *regmap = (regset == &sh_corefile_gregset
 					     ? tdep->core_gregmap
 					     : tdep->core_fpregmap);
@@ -2172,7 +2172,7 @@ sh_corefile_collect_regset (const struct regset *regset,
 			    int regnum, void *regs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
   const struct sh_corefile_regmap *regmap = (regset == &sh_corefile_gregset
 					     ? tdep->core_gregmap
 					     : tdep->core_fpregmap);
@@ -2210,7 +2210,7 @@ sh_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				 void *cb_data,
 				 const struct regcache *regcache)
 {
-  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
 
   if (tdep->core_gregmap != NULL)
     cb (".reg", tdep->sizeof_gregset, tdep->sizeof_gregset,
diff --git a/gdb/sparc-linux-tdep.c b/gdb/sparc-linux-tdep.c
index 18196b2f075..66481ea7b8a 100644
--- a/gdb/sparc-linux-tdep.c
+++ b/gdb/sparc-linux-tdep.c
@@ -254,7 +254,7 @@ static void
 sparc_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   gdbarch *arch = regcache->arch ();
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
   ULONGEST psr;
 
   regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
@@ -421,7 +421,7 @@ static const struct regset sparc32_linux_fpregset =
 static void
 sparc32_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/sparc-netbsd-tdep.c b/gdb/sparc-netbsd-tdep.c
index a97a772dba2..57c178511fa 100644
--- a/gdb/sparc-netbsd-tdep.c
+++ b/gdb/sparc-netbsd-tdep.c
@@ -295,7 +295,7 @@ static const struct regset sparc32nbsd_fpregset =
 void
 sparc32nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   nbsd_init_abi (info, gdbarch);
 
diff --git a/gdb/sparc-sol2-tdep.c b/gdb/sparc-sol2-tdep.c
index 28eb6f67601..a92e95ce71b 100644
--- a/gdb/sparc-sol2-tdep.c
+++ b/gdb/sparc-sol2-tdep.c
@@ -196,7 +196,7 @@ static const struct frame_unwind sparc32_sol2_sigtramp_frame_unwind =
 static void
 sparc32_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   tdep->gregset = &sparc32_sol2_gregset;
   tdep->sizeof_gregset = 152;
diff --git a/gdb/sparc-tdep.c b/gdb/sparc-tdep.c
index e540263a2fe..397f5489550 100644
--- a/gdb/sparc-tdep.c
+++ b/gdb/sparc-tdep.c
@@ -425,7 +425,7 @@ sparc32_register_name (struct gdbarch *gdbarch, int regnum)
 static struct type *
 sparc_psr_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->sparc_psr_type)
     {
@@ -447,7 +447,7 @@ sparc_psr_type (struct gdbarch *gdbarch)
 static struct type *
 sparc_fsr_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->sparc_fsr_type)
     {
@@ -988,7 +988,7 @@ CORE_ADDR
 sparc_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
 			CORE_ADDR current_pc, struct sparc_frame_cache *cache)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
   unsigned long insn;
   int offset = 0;
   int dest = -1;
@@ -1680,7 +1680,7 @@ sparc_analyze_control_transfer (struct regcache *regcache,
 
       /* Trap instruction (TRAP).  */
       gdbarch *arch = regcache->arch ();
-      sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
+      sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
       return tdep->step_trap (frame, insn);
     }
 
@@ -1731,7 +1731,7 @@ static std::vector<CORE_ADDR>
 sparc_software_single_step (struct regcache *regcache)
 {
   struct gdbarch *arch = regcache->arch ();
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
   CORE_ADDR npc, nnpc;
 
   CORE_ADDR pc, orig_npc;
@@ -1761,7 +1761,7 @@ static void
 sparc_write_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   gdbarch *arch = regcache->arch ();
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
 
   regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
   regcache_cooked_write_unsigned (regcache, tdep->npc_regnum, pc + 4);
@@ -1776,7 +1776,7 @@ sparc_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				    void *cb_data,
 				    const struct regcache *regcache)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   cb (".reg", tdep->sizeof_gregset, tdep->sizeof_gregset, tdep->gregset, NULL,
       cb_data);
diff --git a/gdb/sparc64-fbsd-tdep.c b/gdb/sparc64-fbsd-tdep.c
index 8a288282772..76c682fd521 100644
--- a/gdb/sparc64-fbsd-tdep.c
+++ b/gdb/sparc64-fbsd-tdep.c
@@ -222,7 +222,7 @@ static const struct regset sparc64fbsd_fpregset =
 static void
 sparc64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support. */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/sparc64-linux-tdep.c b/gdb/sparc64-linux-tdep.c
index 9ea72331e93..f5940cfcdee 100644
--- a/gdb/sparc64-linux-tdep.c
+++ b/gdb/sparc64-linux-tdep.c
@@ -262,7 +262,7 @@ static void
 sparc64_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   gdbarch *arch = regcache->arch ();
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
   ULONGEST state;
 
   regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
@@ -364,7 +364,7 @@ static const struct regset sparc64_linux_fpregset =
 static void
 sparc64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/sparc64-netbsd-tdep.c b/gdb/sparc64-netbsd-tdep.c
index 29cd3b6f3ba..db368118f23 100644
--- a/gdb/sparc64-netbsd-tdep.c
+++ b/gdb/sparc64-netbsd-tdep.c
@@ -248,7 +248,7 @@ static const struct regset sparc64nbsd_fpregset =
 static void
 sparc64nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   nbsd_init_abi (info, gdbarch);
 
diff --git a/gdb/sparc64-obsd-tdep.c b/gdb/sparc64-obsd-tdep.c
index 05ebbd2e84a..d6470a51b65 100644
--- a/gdb/sparc64-obsd-tdep.c
+++ b/gdb/sparc64-obsd-tdep.c
@@ -423,7 +423,7 @@ static const struct regset sparc64obsd_fpregset =
 static void
 sparc64obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   tdep->gregset = &sparc64obsd_gregset;
   tdep->sizeof_gregset = 288;
diff --git a/gdb/sparc64-sol2-tdep.c b/gdb/sparc64-sol2-tdep.c
index 458f0320582..e656c359efa 100644
--- a/gdb/sparc64-sol2-tdep.c
+++ b/gdb/sparc64-sol2-tdep.c
@@ -199,7 +199,7 @@ static const struct frame_unwind sparc64_sol2_sigtramp_frame_unwind =
 static void
 sparc64_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   tdep->gregset = &sparc64_sol2_gregset;
   tdep->sizeof_gregset = 304;
diff --git a/gdb/sparc64-tdep.c b/gdb/sparc64-tdep.c
index 95496d33ad4..5ca5f2dca8c 100644
--- a/gdb/sparc64-tdep.c
+++ b/gdb/sparc64-tdep.c
@@ -648,7 +648,7 @@ sparc64_structure_or_union_p (const struct type *type)
 static struct type *
 sparc64_pstate_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->sparc64_pstate_type)
     {
@@ -675,7 +675,7 @@ sparc64_pstate_type (struct gdbarch *gdbarch)
 static struct type *
 sparc64_ccr_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   if (tdep->sparc64_ccr_type == NULL)
     {
@@ -700,7 +700,7 @@ sparc64_ccr_type (struct gdbarch *gdbarch)
 static struct type *
 sparc64_fsr_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->sparc64_fsr_type)
     {
@@ -733,7 +733,7 @@ sparc64_fsr_type (struct gdbarch *gdbarch)
 static struct type *
 sparc64_fprs_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->sparc64_fprs_type)
     {
@@ -1806,7 +1806,7 @@ sparc64_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr)
 void
 sparc64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   tdep->pc_regnum = SPARC64_PC_REGNUM;
   tdep->npc_regnum = SPARC64_NPC_REGNUM;
diff --git a/gdb/tic6x-linux-tdep.c b/gdb/tic6x-linux-tdep.c
index 5a93294361a..b2422d1ccc0 100644
--- a/gdb/tic6x-linux-tdep.c
+++ b/gdb/tic6x-linux-tdep.c
@@ -45,7 +45,7 @@ static const gdb_byte tic6x_bkpt_bnop_le[] = { 0x22, 0xa1, 0x00, 0x00 };
 static unsigned int
 tic6x_register_sigcontext_offset (unsigned int regnum, struct gdbarch *gdbarch)
 {
-  tic6x_gdbarch_tdep *tdep = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  tic6x_gdbarch_tdep *tdep = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
 
   if (regnum == TIC6X_A4_REGNUM || regnum == TIC6X_A4_REGNUM + 2
       || regnum == TIC6X_A4_REGNUM + 4)
@@ -92,7 +92,7 @@ tic6x_linux_rt_sigreturn_init (const struct tramp_frame *self,
 		    + TIC6X_SIGINFO_SIZE
 		    + 4 + 4 /* uc_flags and *uc_link in struct ucontext.  */
 		    + TIC6X_STACK_T_SIZE);
-  tic6x_gdbarch_tdep *tdep = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  tic6x_gdbarch_tdep *tdep = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
   unsigned int reg_offset;
   unsigned int i;
 
@@ -165,7 +165,7 @@ extern struct target_so_ops dsbt_so_ops;
 static void
 tic6x_uclinux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  tic6x_gdbarch_tdep *tdep = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  tic6x_gdbarch_tdep *tdep = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/tic6x-tdep.c b/gdb/tic6x-tdep.c
index 3e49030ab14..b7efcf18576 100644
--- a/gdb/tic6x-tdep.c
+++ b/gdb/tic6x-tdep.c
@@ -325,7 +325,7 @@ tic6x_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 static const gdb_byte *
 tic6x_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
-  tic6x_gdbarch_tdep *tdep = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  tic6x_gdbarch_tdep *tdep = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
 
   *size = kind;
 
@@ -599,7 +599,7 @@ tic6x_get_next_pc (struct regcache *regcache, CORE_ADDR pc)
       if (inst == TIC6X_INST_SWE)
 	{
 	  tic6x_gdbarch_tdep *tdep
-	    = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	    = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
 
 	  if (tdep->syscall_next_pc != NULL)
 	    return tdep->syscall_next_pc (get_current_frame ());
@@ -1217,7 +1217,7 @@ tic6x_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       tic6x_gdbarch_tdep *tdep
-	= (tic6x_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<tic6x_gdbarch_tdep> (arches->gdbarch);
 
       if (has_gp != tdep->has_gp)
 	continue;
diff --git a/gdb/v850-tdep.c b/gdb/v850-tdep.c
index a67310a2440..4de5faa6a47 100644
--- a/gdb/v850-tdep.c
+++ b/gdb/v850-tdep.c
@@ -511,7 +511,7 @@ v850_use_struct_convention (struct gdbarch *gdbarch, struct type *type)
 {
   int i;
   struct type *fld_type, *tgt_type;
-  v850_gdbarch_tdep *tdep = (v850_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  v850_gdbarch_tdep *tdep = gdbarch_tdep<v850_gdbarch_tdep> (gdbarch);
 
   if (tdep->abi == V850_ABI_RH850)
     {
@@ -1023,7 +1023,7 @@ v850_push_dummy_call (struct gdbarch *gdbarch,
   int argnum;
   int arg_space = 0;
   int stack_offset;
-  v850_gdbarch_tdep *tdep = (v850_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  v850_gdbarch_tdep *tdep = gdbarch_tdep<v850_gdbarch_tdep> (gdbarch);
 
   if (tdep->abi == V850_ABI_RH850)
     stack_offset = 0;
@@ -1374,7 +1374,7 @@ v850_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       v850_gdbarch_tdep *tdep
-	= (v850_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<v850_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->e_flags != e_flags || tdep->e_machine != e_machine)
 	continue;
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 9705fa33cc2..b62d216a7d3 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -486,7 +486,7 @@ windows_fetch_one_register (struct regcache *regcache,
 
   char *context_offset = context_ptr + windows_process.mappings[r];
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   gdb_assert (!gdbarch_read_pc_p (gdbarch));
   gdb_assert (gdbarch_pc_regnum (gdbarch) >= 0);
diff --git a/gdb/xtensa-linux-nat.c b/gdb/xtensa-linux-nat.c
index 5a08824a680..d005c9d8f78 100644
--- a/gdb/xtensa-linux-nat.c
+++ b/gdb/xtensa-linux-nat.c
@@ -62,7 +62,7 @@ fill_gregset (const struct regcache *regcache,
   int i;
   xtensa_elf_gregset_t *regs = (xtensa_elf_gregset_t *) gregsetp;
   struct gdbarch *gdbarch = regcache->arch ();
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   if (regnum == gdbarch_pc_regnum (gdbarch) || regnum == -1)
     regcache->raw_collect (gdbarch_pc_regnum (gdbarch), &regs->pc);
@@ -124,7 +124,7 @@ supply_gregset_reg (struct regcache *regcache,
   xtensa_elf_gregset_t *regs = (xtensa_elf_gregset_t *) gregsetp;
 
   struct gdbarch *gdbarch = regcache->arch ();
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   if (regnum == gdbarch_pc_regnum (gdbarch) || regnum == -1)
     regcache->raw_supply (gdbarch_pc_regnum (gdbarch), &regs->pc);
diff --git a/gdb/xtensa-linux-tdep.c b/gdb/xtensa-linux-tdep.c
index ef55319fd09..600b59b8894 100644
--- a/gdb/xtensa-linux-tdep.c
+++ b/gdb/xtensa-linux-tdep.c
@@ -99,7 +99,7 @@ xtensa_linux_gdb_signal_to_target (struct gdbarch *gdbarch,
 static void
 xtensa_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   if (tdep->num_nopriv_regs < tdep->num_regs)
     {
diff --git a/gdb/xtensa-tdep.c b/gdb/xtensa-tdep.c
index b6558838e44..f881870e244 100644
--- a/gdb/xtensa-tdep.c
+++ b/gdb/xtensa-tdep.c
@@ -116,7 +116,7 @@ static unsigned int xtensa_debug_level = 0;
 static int
 windowing_enabled (struct gdbarch *gdbarch, unsigned int ps)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   /* If we know CALL0 ABI is set explicitly,  say it is Call0.  */
   if (tdep->call_abi == CallAbiCall0Only)
@@ -130,7 +130,7 @@ windowing_enabled (struct gdbarch *gdbarch, unsigned int ps)
 static int
 arreg_number (struct gdbarch *gdbarch, int a_regnum, ULONGEST wb)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   int arreg;
 
   arreg = a_regnum - tdep->a0_base;
@@ -145,7 +145,7 @@ arreg_number (struct gdbarch *gdbarch, int a_regnum, ULONGEST wb)
 static int
 areg_number (struct gdbarch *gdbarch, int ar_regnum, unsigned int wb)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   int areg;
 
   areg = ar_regnum - tdep->ar_base;
@@ -226,7 +226,7 @@ static int
 xtensa_find_register_by_name (struct gdbarch *gdbarch, const char *name)
 {
   int i;
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   for (i = 0; i < gdbarch_num_cooked_regs (gdbarch); i++)
     if (strcasecmp (tdep->regmap[i].name, name) == 0)
@@ -239,7 +239,7 @@ xtensa_find_register_by_name (struct gdbarch *gdbarch, const char *name)
 static const char *
 xtensa_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   /* Return the name stored in the register map.  */
   if (regnum >= 0 && regnum < gdbarch_num_cooked_regs (gdbarch))
@@ -254,7 +254,7 @@ xtensa_register_name (struct gdbarch *gdbarch, int regnum)
 static struct type *
 xtensa_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   /* Return signed integer for ARx and Ax registers.  */
   if ((regnum >= tdep->ar_base
@@ -339,7 +339,7 @@ static int
 xtensa_reg_to_regnum (struct gdbarch *gdbarch, int regnum)
 {
   int i;
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   if (regnum >= 0 && regnum < 16)
     return tdep->a0_base + regnum;
@@ -542,7 +542,7 @@ xtensa_pseudo_register_read (struct gdbarch *gdbarch,
 {
   DEBUGTRACE ("xtensa_pseudo_register_read (... regnum = %d (%s) ...)\n",
 	      regnum, xtensa_register_name (gdbarch, regnum));
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   /* Read aliases a0..a15, if this is a Windowed ABI.  */
   if (tdep->isa_use_windowed_registers
@@ -634,7 +634,7 @@ xtensa_pseudo_register_write (struct gdbarch *gdbarch,
 {
   DEBUGTRACE ("xtensa_pseudo_register_write (... regnum = %d (%s) ...)\n",
 	      regnum, xtensa_register_name (gdbarch, regnum));
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   /* Renumber register, if aliases a0..a15 on Windowed ABI.  */
   if (tdep->isa_use_windowed_registers
@@ -767,7 +767,7 @@ xtensa_register_reggroup_p (struct gdbarch *gdbarch,
 			    int regnum,
 			    const struct reggroup *group)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   xtensa_register_t* reg = &tdep->regmap[regnum];
   xtensa_register_type_t type = reg->type;
   xtensa_register_group_t rg = reg->group;
@@ -821,7 +821,7 @@ xtensa_supply_gregset (const struct regset *regset,
 {
   const xtensa_elf_gregset_t *regs = (const xtensa_elf_gregset_t *) gregs;
   struct gdbarch *gdbarch = rc->arch ();
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   int i;
 
   DEBUGTRACE ("xtensa_supply_gregset (..., regnum==%d, ...)\n", regnum);
@@ -1050,7 +1050,7 @@ static struct frame_id
 xtensa_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
 {
   CORE_ADDR pc, fp;
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   /* THIS-FRAME is a dummy frame.  Return a frame ID of that frame.  */
 
@@ -1105,7 +1105,7 @@ xtensa_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR current_pc)
 {
 #define RETURN_FP goto done
 
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   unsigned int fp_regnum = tdep->a0_base + 1;
   CORE_ADDR start_addr;
   xtensa_isa isa;
@@ -1255,7 +1255,7 @@ xtensa_frame_cache (struct frame_info *this_frame, void **this_cache)
   if (windowed)
     {
       LONGEST op1;
-      xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
       /* Get WINDOWBASE, WINDOWSTART, and PS registers.  */
       wb = get_frame_register_unsigned (this_frame, 
@@ -1417,7 +1417,7 @@ xtensa_frame_prev_register (struct frame_info *this_frame,
   struct xtensa_frame_cache *cache;
   ULONGEST saved_reg = 0;
   int done = 1;
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   if (*this_cache == NULL)
     *this_cache = xtensa_frame_cache (this_frame, this_cache);
@@ -1546,7 +1546,7 @@ xtensa_extract_return_value (struct type *type,
 
   gdb_assert(len > 0);
 
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   if (tdep->call_abi != CallAbiCall0Only)
     {
       /* First, we have to find the caller window in the register file.  */
@@ -1602,7 +1602,7 @@ xtensa_store_return_value (struct type *type,
 
   DEBUGTRACE ("xtensa_store_return_value (...)\n");
 
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   if (tdep->call_abi != CallAbiCall0Only)
     {
       regcache_raw_read_unsigned 
@@ -1686,7 +1686,7 @@ xtensa_push_dummy_call (struct gdbarch *gdbarch,
 			CORE_ADDR struct_addr)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   int size, onstack_size;
   gdb_byte *buf = (gdb_byte *) alloca (16);
   CORE_ADDR ra, ps;
@@ -1935,7 +1935,7 @@ xtensa_push_dummy_call (struct gdbarch *gdbarch,
 static int
 xtensa_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   if (tdep->isa_use_density_instructions)
     return 2;
@@ -2182,7 +2182,7 @@ call0_track_op (struct gdbarch *gdbarch, xtensa_c0reg_t dst[], xtensa_c0reg_t sr
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   unsigned litbase, litaddr, litval;
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   switch (opclass)
     {
@@ -2557,7 +2557,7 @@ call0_frame_cache (struct frame_info *this_frame,
   CORE_ADDR body_pc=UINT_MAX;	/* PC, where prologue analysis stopped.  */
   CORE_ADDR sp, fp, ra;
   int fp_regnum = C0_SP, c0_hasfp = 0, c0_frmsz = 0, prev_sp = 0, to_stk;
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
  
   sp = get_frame_register_unsigned
     (this_frame, tdep->a0_base + 1);
@@ -2710,7 +2710,7 @@ static int a11_was_saved;
 static void
 execute_l32e (struct gdbarch *gdbarch, int at, int as, int offset, CORE_ADDR wb)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   int atreg = arreg_number (gdbarch, tdep->a0_base + at, wb);
   int asreg = arreg_number (gdbarch, tdep->a0_base + as, wb);
   CORE_ADDR addr = xtensa_read_register (asreg) + offset;
@@ -2740,7 +2740,7 @@ execute_l32e (struct gdbarch *gdbarch, int at, int as, int offset, CORE_ADDR wb)
 static void
 execute_s32e (struct gdbarch *gdbarch, int at, int as, int offset, CORE_ADDR wb)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   int atreg = arreg_number (gdbarch, tdep->a0_base + at, wb);
   int asreg = arreg_number (gdbarch, tdep->a0_base + as, wb);
   CORE_ADDR addr = xtensa_read_register (asreg) + offset;
@@ -2774,7 +2774,7 @@ execute_code (struct gdbarch *gdbarch, CORE_ADDR current_pc, CORE_ADDR wb)
   xtensa_opcode opc;
   int insn_num = 0;
   void (*func) (struct gdbarch *, int, int, int, CORE_ADDR);
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   uint32_t at, as, offset;
 
@@ -2905,7 +2905,7 @@ xtensa_window_interrupt_frame_cache (struct frame_info *this_frame,
   CORE_ADDR ps, wb, ws, ra;
   int epc1_regnum, i, regnum;
   xtensa_exception_handler_t eh_type;
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   /* Read PS, WB, and WS from the hardware. Note that PS register
      must be present, if Windowed ABI is supported.  */
@@ -3019,7 +3019,7 @@ xtensa_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
 
       CORE_ADDR end_func;
 
-      xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
       if ((tdep->call_abi == CallAbiCall0Only)
 	  && call0_ret (start_pc, prologue_sal.end))
 	return start_pc;
@@ -3041,7 +3041,7 @@ xtensa_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
 static void
 xtensa_verify_config (struct gdbarch *gdbarch)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   string_file log;
 
   /* Verify that we got a reasonable number of AREGS.  */
diff --git a/gdb/z80-tdep.c b/gdb/z80-tdep.c
index d27e567c358..6a11883e7b4 100644
--- a/gdb/z80-tdep.c
+++ b/gdb/z80-tdep.c
@@ -308,7 +308,7 @@ z80_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR pc_beg, CORE_ADDR pc_end,
 		   struct z80_unwind_cache *info)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  z80_gdbarch_tdep *tdep = (z80_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  z80_gdbarch_tdep *tdep = gdbarch_tdep<z80_gdbarch_tdep> (gdbarch);
   int addr_len = tdep->addr_length;
   gdb_byte prologue[32]; /* max prologue is 24 bytes: __interrupt with local array */
   int pos = 0;
@@ -564,7 +564,7 @@ z80_frame_unwind_cache (struct frame_info *this_frame,
   gdb_byte buf[sizeof(void*)];
   struct z80_unwind_cache *info;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  z80_gdbarch_tdep *tdep = (z80_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  z80_gdbarch_tdep *tdep = gdbarch_tdep<z80_gdbarch_tdep> (gdbarch);
   int addr_len = tdep->addr_length;
 
   if (*this_prologue_cache)
@@ -697,7 +697,7 @@ z80_frame_prev_register (struct frame_info *this_frame,
 	  ULONGEST pc;
 	  gdb_byte buf[3];
 	  struct gdbarch *gdbarch = get_frame_arch (this_frame);
-	  z80_gdbarch_tdep *tdep = (z80_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	  z80_gdbarch_tdep *tdep = gdbarch_tdep<z80_gdbarch_tdep> (gdbarch);
 	  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
 	  read_memory (info->saved_regs[Z80_PC_REGNUM].addr (),
@@ -750,7 +750,7 @@ z80_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
     }
   else /* kind is non-RST address, use CALL instead, but it is dungerous */
     {
-      z80_gdbarch_tdep *tdep = (z80_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      z80_gdbarch_tdep *tdep = gdbarch_tdep<z80_gdbarch_tdep> (gdbarch);
       gdb_byte *p = break_insn;
       *p++ = 0xcd;
       *p++ = (kind >> 0) & 0xff;
-- 
2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCHv3 5/6] gdb: ensure the cast in gdbarch_tdep is valid
  2022-06-13 16:15   ` [PATCHv3 0/6] Handle trying to use a native target with the wrong binary Andrew Burgess
                       ` (3 preceding siblings ...)
  2022-06-13 16:15     ` [PATCHv3 4/6] gdb: move the type cast into gdbarch_tdep Andrew Burgess
@ 2022-06-13 16:15     ` Andrew Burgess
  2022-06-24 18:15       ` Pedro Alves
  2022-06-13 16:15     ` [PATCHv3 6/6] gdb: native target invalid architecture detection Andrew Burgess
                       ` (2 subsequent siblings)
  7 siblings, 1 reply; 83+ messages in thread
From: Andrew Burgess @ 2022-06-13 16:15 UTC (permalink / raw)
  To: gdb-patches; +Cc: Luis Machado, Andrew Burgess

This commit builds on the previous commit and modifies the
gdbarch_tdep function to ensure that the cast being performed is
valid.

To do this I make use of dynamic_cast to ensure that the generic
gdbarch_tdep pointer that we have is of the correct type.

The only problem with this approach is that, in order to use
dynamic_cast, we need RTTI information, which requires the class to
have a vtable, which currently, is not something the various tdep
classes have.

And so, in this commit, I add a virtual destructor to the gdbarch_tdep
class.

With this change I can now add an assert in the gdbarch_tdep function.

Obviously, this change comes at a cost, creation of the tdep classes
is now slightly more expensive (due to vtable initialisation),
however, this only happens when a new gdbarch is created, which is not
that frequent, so I don't see that as a huge concern.

Then, there is an increased cost each time the tdep is accessed.  This
is much more frequent, but I don't believe the cost is excessive (a
vtable pointer comparison), at least, no worse than many of our other
asserts.

If we consider the motivating example that was discussed in the
previous commit; build GDB for all targets on an x86-64 GNU/Linux
system, and then attempt to "run" a RISC-V binary using the native
x86-64 Linux target.  Previously this would trigger an assert while
accessing fields within a i386_gdbarch_tdep, like this:

  ../../src/gdb/i387-tdep.c:596: internal-error: i387_supply_fxsave: Assertion `tdep->st0_regnum >= I386_ST0_REGNUM' failed.

But with the changes from this commit in place, we now see an
assertion failure like this:

  ../../src/gdb/gdbarch.h:166: internal-error: gdbarch_tdep: Assertion `dynamic_cast<TDepType *> (tdep) != nullptr' failed.

On the face of it, this might not seem like much of an improvement,
but I think it is.

The previous assert was triggered by undefined behaviour.  There's no
guarantee that we would see an assertion at all, a different
combination of native target and binary format might not trigger an
assert (and just do the wrong thing), or might crash GDB completely.

In contrast, the new assert is based on defined behaviour, we'll
always assert if GDB goes wrong, and we assert early, at the point the
mistake is being made (casting the result of gdbarch_tdep to the wrong
type), rather than at some later point after the incorrect cast has
completed.

Obviously, when we consider the original example, trying to run a
binary of the wrong architecture on a native target, having GDB fail
with an assertion is not a real solution.  No user action should be
able to trigger an assertion failure.  In a later commit I will offer
a real solution to this architecture mismatch problem.
---
 gdb/gdbarch.h | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index b2c91db0c4f..a47aa8cc8fa 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -58,7 +58,13 @@ struct inferior;
 
 #include "regcache.h"
 
-struct gdbarch_tdep {};
+/* The base class for every architecture's tdep sub-class.  We include a
+   virtual destructor so that sub-classes will have RTTI information.  */
+
+struct gdbarch_tdep
+{
+  virtual ~gdbarch_tdep() = default;
+};
 
 /* The architecture associated with the inferior through the
    connection to the target.
@@ -156,8 +162,9 @@ template<typename TDepType>
 static inline TDepType *
 gdbarch_tdep (struct gdbarch *gdbarch)
 {
-  struct gdbarch_tdep *tdep = gdbarch_tdep_1 (gdbarch);
-  return static_cast<TDepType *> (tdep);
+  TDepType *tdep = dynamic_cast<TDepType *> (gdbarch_tdep_1 (gdbarch));
+  gdb_assert (tdep != nullptr);
+  return tdep;
 }
 
 /* Mechanism for co-ordinating the selection of a specific
-- 
2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCHv3 6/6] gdb: native target invalid architecture detection
  2022-06-13 16:15   ` [PATCHv3 0/6] Handle trying to use a native target with the wrong binary Andrew Burgess
                       ` (4 preceding siblings ...)
  2022-06-13 16:15     ` [PATCHv3 5/6] gdb: ensure the cast in gdbarch_tdep is valid Andrew Burgess
@ 2022-06-13 16:15     ` Andrew Burgess
  2022-06-24 19:23       ` Pedro Alves
  2022-06-24 10:15     ` [PATCHv3 0/6] Handle trying to use a native target with the wrong binary Andrew Burgess
  2022-06-28 14:28     ` [PATCHv4 0/6] Detect invalid casts of gdbarch_tdep structures Andrew Burgess
  7 siblings, 1 reply; 83+ messages in thread
From: Andrew Burgess @ 2022-06-13 16:15 UTC (permalink / raw)
  To: gdb-patches; +Cc: Luis Machado, Andrew Burgess

If GDB is asked to start a new inferior, or attach to an existing
process, using a binary file for an architecture that does not match
the current native target, then, currently, GDB will assert.  Here's
an example session using current HEAD of master with GDB built for an
x86-64 GNU/Linux native target, the binary being used is a RISC-V ELF:

  $ ./gdb/gdb -q --data-directory ./gdb/data-directory/
  (gdb) file /tmp/hello.rv32imc.x
  Reading symbols from /tmp/hello.rv32imc.x...
  (gdb) start
  Temporary breakpoint 1 at 0x101b2: file hello.rv32.c, line 23.
  Starting program: /tmp/hello.rv32imc.x
  ../../src/gdb/gdbarch.h:166: internal-error: gdbarch_tdep: Assertion `dynamic_cast<TDepType *> (tdep) != nullptr' failed.
  A problem internal to GDB has been detected,
  further debugging may prove unreliable.

The same error is encountered if, instead of starting a new inferior,
the user tries to attach to an x86-64 process with a RISC-V binary set
as the current executable.

These errors are not specific to the x86-64/RISC-V pairing I'm using
here, any attempt to use a binary for one architecture with a native
target of a different architecture will result in a similar error.

Clearly, attempting to use this cross-architecture combination is a
user error, but I think GDB should do better than an assert; ideally a
nice error should be printed.

The problem we run into is that, when the user starts a new inferior,
or attaches to an inferior, the inferior stops.  At this point GDB
attempts to handle the stop, and this involves reading registers from
the inferior.

These register reads end up being done through the native target, so
in the example above, we end up in the amd64_supply_fxsave function.
However, these functions need a gdbarch.  The gdbarch is fetched from
the register set, which was constructed using the gdbarch from the
binary currently in use.  And so we end up in amd64_supply_fxsave
using a RISC-V gdbarch.

When we call:

  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);

this will assert as the gdbarch_tdep data within the RISC-V gdbarch is
of the type riscv_gdbarch_tdep not i386_gdbarch_tdep.

The solution I propose in this commit is to add a new target_ops
method supports_architecture_p.  This method will return true if a
target can safely be used with a specific architecture, otherwise, the
method returns false.

I imagine that a result of true from this method doesn't guarantee
that GDB can start an inferior of a given architecture, it just means
that GDB will not crash if such an attempt is made.  A result of false
is a hard stop; attempting to use this target with this architecture
is not supported, and may cause GDB to crash.

This distinction is important I think for things like remote targets,
and possibly simulator targets.  We might imagine that GDB can ask a
remote (or simulator) to start with a particular executable, and the
target might still refuse for some reason.  But my thinking is that
these refusals should be well handled (i.e. GDB should give a user
friendly error), rather than crashing, as is the case with the native
targets.

For example, if I start gdbserver on an x86-64 machine like this:

  gdbserver --multi :54321

Then use GDB to try and load a RISC-V binary, like this:

  $ ./gdb/gdb -q --data-directory ./gdb/data-directory/
  (gdb) file /tmp/hello.rv32imc.x
  Reading symbols from /tmp/hello.rv32imc.x...
  (gdb) target extended-remote :54321
  Remote debugging using :54321
  (gdb) run
  Starting program: /tmp/hello.rv32imc.x
  Running the default executable on the remote target failed; try "set remote exec-file"?
  (gdb)

Though the error is not very helpful in diagnosing the problem, we can
see that GDB has not crashed, but has given the user an error.

And so, the supports_architecture_p method is created to return true
by default, then I override this in inf_child_target, where I compare
the architecture in question with the default_bfd_arch.

Finally, I've added calls to supports_architecture_p for the
run (which covers run, start, starti) and attach commands.

This leaves just one question, what about native targets that support
multiple architectures?

These targets can be split into two groups.  First, we have targets
like x86-64, which also supports i386 binaries.  This case is easy to
handle, as far as BFD is concerned there is only one architecture,
bfd_arch_i386, and we then use machine types to split this
architecture into x86-64 and i386 (and others).  As the new
supports_architecture_p function only checks the bfd architecture,
then there is nothing additional needed for this case.

The second group of multi-architecture targets requires more work.
The only targets that I'm aware of that fall into this group are the
rs6000-aix-nat.c, ppc-*-nat.c targets, and the aarch64-linux-nat.c
target.

The first group (rs600/ppc) support bfd_arch_rs6000 and
bfd_arch_powerpc, while the second (aarch64) supports bfd_arch_arm and
bfd_arch_aarch64.

To deal with these targets I have overridden the
supports_architecture_p function in each of the separate target files,
these overrides check both of the supported architectures.

One final note, in the rs6000/ppc case, the FreeBSD target supports
both architectures, and so we override supports_architecture_p.  In
contrast, the aarch64_fbsd_nat_target target does not (yet) support
bfd_arch_arm, and so there is no supports_architecture_p here.  This
can always be added later if/when support is added.

You will notice a lack of tests for this change.  I'm not sure of a
good way that I can build a binary for a different architecture as
part of a test, but if anyone has any ideas then I'll be happy to add
a test here.  The gdb.base/multi-arch.exp test exists, which for
AArch64 will test compiling and running something as both AArch64 and
ARM, but this doesn't cover the error case, just that the overridden
supports_architecture_p works in that case.
---
 gdb/aarch64-linux-nat.c |  8 ++++++++
 gdb/arch-utils.c        |  8 ++++++++
 gdb/arch-utils.h        |  5 +++++
 gdb/inf-child.c         | 19 +++++++++++++++++++
 gdb/inf-child.h         |  2 ++
 gdb/infcmd.c            |  8 ++++++++
 gdb/ppc-fbsd-nat.c      |  8 ++++++++
 gdb/ppc-linux-nat.c     |  8 ++++++++
 gdb/ppc-obsd-nat.c      |  8 ++++++++
 gdb/rs6000-aix-nat.c    |  8 ++++++++
 gdb/target-delegates.c  | 28 ++++++++++++++++++++++++++++
 gdb/target.h            | 13 ++++++++++++-
 12 files changed, 122 insertions(+), 1 deletion(-)

diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c
index a457fcd48ad..6114c4c6638 100644
--- a/gdb/aarch64-linux-nat.c
+++ b/gdb/aarch64-linux-nat.c
@@ -108,6 +108,14 @@ class aarch64_linux_nat_target final
   /* Write allocation tags to memory via PTRACE.  */
   bool store_memtags (CORE_ADDR address, size_t len,
 		      const gdb::byte_vector &tags, int type) override;
+
+  /* This target supports two architectures, check for them both here.  */
+
+  bool supports_architecture_p (struct gdbarch *gdbarch) override
+  {
+    bfd_architecture the_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
+    return (the_arch == bfd_arch_aarch64 || the_arch == bfd_arch_arm);
+  }
 };
 
 static aarch64_linux_nat_target the_aarch64_linux_nat_target;
diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index 360b8d694be..efba17e1d5d 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -1570,6 +1570,14 @@ target_gdbarch (void)
   return current_inferior ()->gdbarch;
 }
 
+/* See arch-utils.h.  */
+
+bool
+gdbarch_matches_default_arch (struct gdbarch *gdbarch)
+{
+  return gdbarch_bfd_arch_info (gdbarch)->arch == default_bfd_arch->arch;
+}
+
 void _initialize_gdbarch_utils ();
 void
 _initialize_gdbarch_utils ()
diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h
index f850e5fd6e7..5d61be36c26 100644
--- a/gdb/arch-utils.h
+++ b/gdb/arch-utils.h
@@ -300,4 +300,9 @@ extern void default_read_core_file_mappings
    struct bfd *cbfd,
    read_core_file_mappings_pre_loop_ftype pre_loop_cb,
    read_core_file_mappings_loop_ftype loop_cb);
+
+/* Return true if the bfd architecture of GDBARCH matches the default bfd
+   architecture.  */
+
+extern bool gdbarch_matches_default_arch (struct gdbarch *gdbarch);
 #endif /* ARCH_UTILS_H */
diff --git a/gdb/inf-child.c b/gdb/inf-child.c
index 56ebd2a5549..0c47a367c68 100644
--- a/gdb/inf-child.c
+++ b/gdb/inf-child.c
@@ -30,6 +30,8 @@
 #include "inferior.h"
 #include <sys/stat.h>
 #include "inf-child.h"
+#include "gdbarch.h"
+#include "arch-utils.h"
 #include "gdbsupport/fileio.h"
 #include "gdbsupport/agent.h"
 #include "gdbsupport/gdb_wait.h"
@@ -412,6 +414,23 @@ inf_child_target::follow_exec (inferior *follow_inf, ptid_t ptid,
     }
 }
 
+/* The inf_child_target represents the native target built into GDB, of
+   which there is only ever one.  If we attempt to start a native inferior
+   using a binary for an architecture not matching the native target then,
+   when we handle the first stop, we will end up trying to read registers
+   using the gdbarch functions from the native target, but passing in a
+   gdbarch object based on the architecture of the binary file.  This will
+   result in errors.
+
+   This check prevents this so long as everywhere user command that might
+   cause a new inferior to be created calls this function.  */
+
+bool
+inf_child_target::supports_architecture_p (struct gdbarch *gdbarch)
+{
+  return gdbarch_matches_default_arch (gdbarch);
+}
+
 /* See inf-child.h.  */
 
 void
diff --git a/gdb/inf-child.h b/gdb/inf-child.h
index ae5ace46f30..01a8164b0c2 100644
--- a/gdb/inf-child.h
+++ b/gdb/inf-child.h
@@ -92,6 +92,8 @@ class inf_child_target
 
   bool can_use_agent () override;
 
+  bool supports_architecture_p (struct gdbarch *gdbarch) override;
+
 protected:
   /* Unpush the target if it wasn't explicitly open with "target native"
      and there are no live inferiors left.  Note: if calling this as a
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index e909d4d4c81..b8acf858b3a 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -413,6 +413,10 @@ run_command_1 (const char *args, int from_tty, enum run_how run_how)
   if (non_stop && !run_target->supports_non_stop ())
     error (_("The target does not support running in non-stop mode."));
 
+  if (!run_target->supports_architecture_p (get_current_arch ()))
+    error (_("The target does not support architecture \"%s\"."),
+	   gdbarch_bfd_arch_info (get_current_arch ())->printable_name);
+
   /* Done.  Can now set breakpoints, change inferior args, etc.  */
 
   /* Insert temporary breakpoint in main function if requested.  */
@@ -2590,6 +2594,10 @@ attach_command (const char *args, int from_tty)
   if (non_stop && !attach_target->supports_non_stop ())
     error (_("Cannot attach to this target in non-stop mode"));
 
+  if (!attach_target->supports_architecture_p (get_current_arch ()))
+    error (_("The target does not support architecture \"%s\"."),
+	   gdbarch_bfd_arch_info (get_current_arch ())->printable_name);
+
   attach_target->attach (args, from_tty);
   /* to_attach should push the target, so after this point we
      shouldn't refer to attach_target again.  */
diff --git a/gdb/ppc-fbsd-nat.c b/gdb/ppc-fbsd-nat.c
index d0a5778e2d3..f7c36c33958 100644
--- a/gdb/ppc-fbsd-nat.c
+++ b/gdb/ppc-fbsd-nat.c
@@ -41,6 +41,14 @@ struct ppc_fbsd_nat_target final : public fbsd_nat_target
 {
   void fetch_registers (struct regcache *, int) override;
   void store_registers (struct regcache *, int) override;
+
+  /* This target supports two architectures, check for them both here.  */
+
+  bool supports_architecture_p (struct gdbarch *gdbarch) override
+  {
+    bfd_architecture the_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
+    return (the_arch == bfd_arch_rs6000 || the_arch == bfd_arch_powerpc);
+  }
 };
 
 static ppc_fbsd_nat_target the_ppc_fbsd_nat_target;
diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c
index de4158c411a..e302b15925a 100644
--- a/gdb/ppc-linux-nat.c
+++ b/gdb/ppc-linux-nat.c
@@ -551,6 +551,14 @@ struct ppc_linux_nat_target final : public linux_nat_target
 
   void low_prepare_to_resume (struct lwp_info *) override;
 
+  /* This target supports two architectures, check for them both here.  */
+
+  bool supports_architecture_p (struct gdbarch *gdbarch) override
+  {
+    bfd_architecture the_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
+    return (the_arch == bfd_arch_rs6000 || the_arch == bfd_arch_powerpc);
+  }
+
 private:
 
   void copy_thread_dreg_state (const ptid_t &parent_ptid,
diff --git a/gdb/ppc-obsd-nat.c b/gdb/ppc-obsd-nat.c
index e480f19dc73..2fdccc3085d 100644
--- a/gdb/ppc-obsd-nat.c
+++ b/gdb/ppc-obsd-nat.c
@@ -39,6 +39,14 @@ struct ppc_obsd_nat_target final : public obsd_nat_target
 {
   void fetch_registers (struct regcache *, int) override;
   void store_registers (struct regcache *, int) override;
+
+  /* This target supports two architectures, check for them both here.  */
+
+  bool supports_architecture_p (struct gdbarch *gdbarch) override
+  {
+    bfd_architecture the_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
+    return (the_arch == bfd_arch_rs6000 || the_arch == bfd_arch_powerpc);
+  }
 };
 
 static ppc_obsd_nat_target the_ppc_obsd_nat_target;
diff --git a/gdb/rs6000-aix-nat.c b/gdb/rs6000-aix-nat.c
index 8697d27b4ed..603caa8fb1e 100644
--- a/gdb/rs6000-aix-nat.c
+++ b/gdb/rs6000-aix-nat.c
@@ -91,6 +91,14 @@ class rs6000_nat_target final : public inf_ptrace_target
 
   ptid_t wait (ptid_t, struct target_waitstatus *, target_wait_flags) override;
 
+  /* This target supports two architectures, check for them both here.  */
+
+  bool supports_architecture_p (struct gdbarch *gdbarch) override
+  {
+    bfd_architecture the_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
+    return (the_arch == bfd_arch_rs6000 || the_arch == bfd_arch_powerpc);
+  }
+
 protected:
 
   void post_startup_inferior (ptid_t ptid) override
diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c
index 8a9986454dd..cb7bb1f2062 100644
--- a/gdb/target-delegates.c
+++ b/gdb/target-delegates.c
@@ -196,6 +196,7 @@ struct dummy_target : public target_ops
   bool supports_memory_tagging () override;
   bool fetch_memtags (CORE_ADDR arg0, size_t arg1, gdb::byte_vector &arg2, int arg3) override;
   bool store_memtags (CORE_ADDR arg0, size_t arg1, const gdb::byte_vector &arg2, int arg3) override;
+  bool supports_architecture_p (struct gdbarch *arg0) override;
 };
 
 struct debug_target : public target_ops
@@ -370,6 +371,7 @@ struct debug_target : public target_ops
   bool supports_memory_tagging () override;
   bool fetch_memtags (CORE_ADDR arg0, size_t arg1, gdb::byte_vector &arg2, int arg3) override;
   bool store_memtags (CORE_ADDR arg0, size_t arg1, const gdb::byte_vector &arg2, int arg3) override;
+  bool supports_architecture_p (struct gdbarch *arg0) override;
 };
 
 void
@@ -4536,3 +4538,29 @@ debug_target::store_memtags (CORE_ADDR arg0, size_t arg1, const gdb::byte_vector
   return result;
 }
 
+bool
+target_ops::supports_architecture_p (struct gdbarch *arg0)
+{
+  return this->beneath ()->supports_architecture_p (arg0);
+}
+
+bool
+dummy_target::supports_architecture_p (struct gdbarch *arg0)
+{
+  return true;
+}
+
+bool
+debug_target::supports_architecture_p (struct gdbarch *arg0)
+{
+  bool result;
+  gdb_printf (gdb_stdlog, "-> %s->supports_architecture_p (...)\n", this->beneath ()->shortname ());
+  result = this->beneath ()->supports_architecture_p (arg0);
+  gdb_printf (gdb_stdlog, "<- %s->supports_architecture_p (", this->beneath ()->shortname ());
+  target_debug_print_struct_gdbarch_p (arg0);
+  gdb_puts (") = ", gdb_stdlog);
+  target_debug_print_bool (result);
+  gdb_puts ("\n", gdb_stdlog);
+  return result;
+}
+
diff --git a/gdb/target.h b/gdb/target.h
index 18559feef89..5f3ae77f559 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -1320,7 +1320,18 @@ struct target_ops
     virtual bool store_memtags (CORE_ADDR address, size_t len,
 				const gdb::byte_vector &tags, int type)
       TARGET_DEFAULT_NORETURN (tcomplain ());
-  };
+
+    /* Return false if the target does not support GDBARCH, otherwise,
+       return true.
+
+       The default reply of true does not guarantee that debugging an
+       inferior with architecture GDBARCH will succeed, other errors might
+       be thrown later on, but a return value of false is a clear
+       indication that we should not proceed attempting to use this
+       architecture with this target.  */
+    virtual bool supports_architecture_p (struct gdbarch *gdbarch)
+      TARGET_DEFAULT_RETURN (true);
+};
 
 /* Deleter for std::unique_ptr.  See comments in
    target_ops::~target_ops and target_ops::close about heap-allocated
-- 
2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCHv3 3/6] gdb: select suitable thread for gdbarch_adjust_breakpoint_address
  2022-06-13 16:15     ` [PATCHv3 3/6] gdb: select suitable thread for gdbarch_adjust_breakpoint_address Andrew Burgess
@ 2022-06-14  9:45       ` Luis Machado
  2022-06-14 14:05         ` Andrew Burgess
  2022-06-24 16:58       ` Pedro Alves
  1 sibling, 1 reply; 83+ messages in thread
From: Luis Machado @ 2022-06-14  9:45 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

Hi!

On 6/13/22 17:15, Andrew Burgess wrote:
> The three targets that implement gdbarch_adjust_breakpoint_address are
> arm, frv, and mips.  In each of these targets the adjust breakpoint
> address function does some combination of reading the symbol table, or
> reading memory at the location the breakpoint could be placed.
> 
> The problem is that performing these actions requires that the current
> inferior and program space be the one in which the breakpoint will be
> placed, and this is not currently always the case.
> 
> Consider a GDB session with multiple inferiors.  One inferior might be
> a native target while another could be a remote target of a completely
> different architecture.  Alternatively, if we consider ARM and
> AArch64, one native inferior might be AArch64, while a second native
> inferior could be ARM.
> 
> In these cases it is possible, and valid, for a user to have one
> inferior selected, and place a breakpoint in the other inferior by
> placing a breakpoint on a particular symbol.
> 
> If this happens, then currently, when
> gdbarch_adjust_breakpoint_address is called, the wrong inferior (and
> program space) will be selected, and memory reads, and symbol look
> ups, will not return the expected results, this could lead to
> breakpoints being placed in the wrong location.
> 
> There are currently two places where gdbarch_adjust_breakpoint_address
> is called:
> 
>    1. In infrun.c, in the function handle_step_into_function.  In this
>    case, I believe that the correct inferior and program space will
>    already be selected as this is called as part of the stop event
>    handling, so I don't think we need to worry about this case, and
> 
>    2. In breakpoint.c, in the function adjust_breakpoint_address, which
>    is itself called from code_breakpoint::add_location and
>    watch_command_1.
> 
>    The watch_command_1 case I don't think we need to worry about, this
>    is for when a local watch expression is created, which can only be
>    in the currently selected inferior, so this case should be fine.
> 
>    The code_breakpoint::add_location case is the one that needs fixing,
>    this is what allows a breakpoint to be created between inferiors.
> 
> To fix the code_breakpoint::add_location case, I propose that we pass
> the "correct" program_space (i.e. the program space in which the
> breakpoint will be created) to the adjust_breakpoint_address function.
> Then in adjust_breakpoint_address we can make use of
> switch_to_program_space_and_thread to switch program_space and
> inferior before calling gdbarch_adjust_breakpoint_address.
> 
> I discovered this issue while working on a later patch in this
> series.  This later patch will detect when we cast the result of
> gdbarch_tdep to the wrong type.
> 
> With this later patch in place I ran gdb.multi/multi-arch.exp on an
> AArch64 target.  In this situation, two inferiors are created, an
> AArch64 inferior, and an ARM inferior.  The test selected the AArch64
> inferior and tries to create a breakpoint in the ARM inferior.
> 
> As a result of this we end up in arm_adjust_breakpoint_address, which
> calls arm_pc_is_thumb.  Before this commit the AArch64 inferior would
> be current.  As a result, all of the checks in arm_pc_is_thumb would
> fail (they rely on reading symbols from the current program space),
> and so, at the end of arm_pc_is_thumb we would call
> arm_frame_is_thumb.  However, remember, at this point the current
> inferior is the AArch64 inferior, so the current frame is an AArch64
> frame.
> 
> In arm_frame_is_thumb we call arm_psr_thumb_bit, which calls
> gdbarch_tdep and casts the result to arm_gdbarch_tdep.  This is wrong,
> the tdep field is of type aarch64_gdbarch_tdep.  After this we have
> undefined behaviour.
> 
> With this patch in place, we will have switched to a thread in the ARM
> program space before calling arm_adjust_breakpoint_address.  As a
> result, we now succeed in looking up the required symbols in
> arm_pc_is_thumb, and so we never call arm_frame_is_thumb.
> 
> However, in the worst case scenario, if we did end up calling
> arm_frame_is_thumb, as the current inferior should now be the ARM
> inferior, the current frame should be an ARM frame, so we still should
> not hit undefined behaviour.
> 
> I have added an assert to arm_frame_is_thumb.
> ---
>   gdb/arm-tdep.c   | 12 ++++++++----
>   gdb/breakpoint.c | 24 ++++++++++++++++++------
>   2 files changed, 26 insertions(+), 10 deletions(-)
> 
> diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
> index 7f27d4bd6e8..e0e5c7efd63 100644
> --- a/gdb/arm-tdep.c
> +++ b/gdb/arm-tdep.c
> @@ -541,20 +541,24 @@ arm_is_thumb (struct regcache *regcache)
>     return (cpsr & t_bit) != 0;
>   }
>   
> -/* Determine if FRAME is executing in Thumb mode.  */
> +/* Determine if FRAME is executing in Thumb mode.  FRAME must be an ARM
> +   frame.  */
>   
>   int
>   arm_frame_is_thumb (struct frame_info *frame)
>   {
> -  CORE_ADDR cpsr;
> -  ULONGEST t_bit = arm_psr_thumb_bit (get_frame_arch (frame));
> +  /* Check the architecture of FRAME.  */
> +  struct gdbarch *gdbarch = get_frame_arch (frame);
> +  gdb_assert (gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm);
>   
>     /* Every ARM frame unwinder can unwind the T bit of the CPSR, either
>        directly (from a signal frame or dummy frame) or by interpreting
>        the saved LR (from a prologue or DWARF frame).  So consult it and
>        trust the unwinders.  */
> -  cpsr = get_frame_register_unsigned (frame, ARM_PS_REGNUM);
> +  CORE_ADDR cpsr = get_frame_register_unsigned (frame, ARM_PS_REGNUM);
>   
> +  /* Find and extract the thumb bit.  */
> +  ULONGEST t_bit = arm_psr_thumb_bit (gdbarch);
>     return (cpsr & t_bit) != 0;
>   }
>   
> diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
> index ed932a19ed7..5370e70f15e 100644
> --- a/gdb/breakpoint.c
> +++ b/gdb/breakpoint.c
> @@ -124,7 +124,8 @@ static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
>   
>   static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
>   					    CORE_ADDR bpaddr,
> -					    enum bptype bptype);
> +					    enum bptype bptype,
> +					    struct program_space *pspace);
>   
>   static int watchpoint_locations_match (struct bp_location *loc1,
>   				       struct bp_location *loc2);
> @@ -7114,8 +7115,11 @@ breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
>   
>   static CORE_ADDR
>   adjust_breakpoint_address (struct gdbarch *gdbarch,
> -			   CORE_ADDR bpaddr, enum bptype bptype)
> +			   CORE_ADDR bpaddr, enum bptype bptype,
> +			   struct program_space *pspace)
>   {
> +  gdb_assert (pspace != nullptr);
> +
>     if (bptype == bp_watchpoint
>         || bptype == bp_hardware_watchpoint
>         || bptype == bp_read_watchpoint
> @@ -7140,10 +7144,16 @@ adjust_breakpoint_address (struct gdbarch *gdbarch,
>       {
>         CORE_ADDR adjusted_bpaddr = bpaddr;
>   
> +      /* Some targets have architectural constraints on the placement
> +	 of breakpoint instructions.  Obtain the adjusted address.  */
>         if (gdbarch_adjust_breakpoint_address_p (gdbarch))
>   	{
> -	  /* Some targets have architectural constraints on the placement
> -	     of breakpoint instructions.  Obtain the adjusted address.  */
> +	  /* Targets that implement this adjustment function will
> +	     likely inspect either the symbol table, or target memory
> +	     add BPADDR, so ensure a suitable thread (and its

Is there something funny in the above line? Should add->and?

Other than this, LGTM.

Again, thanks for taking the time to address this.

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCHv3 3/6] gdb: select suitable thread for gdbarch_adjust_breakpoint_address
  2022-06-14  9:45       ` Luis Machado
@ 2022-06-14 14:05         ` Andrew Burgess
  0 siblings, 0 replies; 83+ messages in thread
From: Andrew Burgess @ 2022-06-14 14:05 UTC (permalink / raw)
  To: Luis Machado, gdb-patches

Luis Machado <luis.machado@arm.com> writes:

> Hi!
>
> On 6/13/22 17:15, Andrew Burgess wrote:
>> The three targets that implement gdbarch_adjust_breakpoint_address are
>> arm, frv, and mips.  In each of these targets the adjust breakpoint
>> address function does some combination of reading the symbol table, or
>> reading memory at the location the breakpoint could be placed.
>> 
>> The problem is that performing these actions requires that the current
>> inferior and program space be the one in which the breakpoint will be
>> placed, and this is not currently always the case.
>> 
>> Consider a GDB session with multiple inferiors.  One inferior might be
>> a native target while another could be a remote target of a completely
>> different architecture.  Alternatively, if we consider ARM and
>> AArch64, one native inferior might be AArch64, while a second native
>> inferior could be ARM.
>> 
>> In these cases it is possible, and valid, for a user to have one
>> inferior selected, and place a breakpoint in the other inferior by
>> placing a breakpoint on a particular symbol.
>> 
>> If this happens, then currently, when
>> gdbarch_adjust_breakpoint_address is called, the wrong inferior (and
>> program space) will be selected, and memory reads, and symbol look
>> ups, will not return the expected results, this could lead to
>> breakpoints being placed in the wrong location.
>> 
>> There are currently two places where gdbarch_adjust_breakpoint_address
>> is called:
>> 
>>    1. In infrun.c, in the function handle_step_into_function.  In this
>>    case, I believe that the correct inferior and program space will
>>    already be selected as this is called as part of the stop event
>>    handling, so I don't think we need to worry about this case, and
>> 
>>    2. In breakpoint.c, in the function adjust_breakpoint_address, which
>>    is itself called from code_breakpoint::add_location and
>>    watch_command_1.
>> 
>>    The watch_command_1 case I don't think we need to worry about, this
>>    is for when a local watch expression is created, which can only be
>>    in the currently selected inferior, so this case should be fine.
>> 
>>    The code_breakpoint::add_location case is the one that needs fixing,
>>    this is what allows a breakpoint to be created between inferiors.
>> 
>> To fix the code_breakpoint::add_location case, I propose that we pass
>> the "correct" program_space (i.e. the program space in which the
>> breakpoint will be created) to the adjust_breakpoint_address function.
>> Then in adjust_breakpoint_address we can make use of
>> switch_to_program_space_and_thread to switch program_space and
>> inferior before calling gdbarch_adjust_breakpoint_address.
>> 
>> I discovered this issue while working on a later patch in this
>> series.  This later patch will detect when we cast the result of
>> gdbarch_tdep to the wrong type.
>> 
>> With this later patch in place I ran gdb.multi/multi-arch.exp on an
>> AArch64 target.  In this situation, two inferiors are created, an
>> AArch64 inferior, and an ARM inferior.  The test selected the AArch64
>> inferior and tries to create a breakpoint in the ARM inferior.
>> 
>> As a result of this we end up in arm_adjust_breakpoint_address, which
>> calls arm_pc_is_thumb.  Before this commit the AArch64 inferior would
>> be current.  As a result, all of the checks in arm_pc_is_thumb would
>> fail (they rely on reading symbols from the current program space),
>> and so, at the end of arm_pc_is_thumb we would call
>> arm_frame_is_thumb.  However, remember, at this point the current
>> inferior is the AArch64 inferior, so the current frame is an AArch64
>> frame.
>> 
>> In arm_frame_is_thumb we call arm_psr_thumb_bit, which calls
>> gdbarch_tdep and casts the result to arm_gdbarch_tdep.  This is wrong,
>> the tdep field is of type aarch64_gdbarch_tdep.  After this we have
>> undefined behaviour.
>> 
>> With this patch in place, we will have switched to a thread in the ARM
>> program space before calling arm_adjust_breakpoint_address.  As a
>> result, we now succeed in looking up the required symbols in
>> arm_pc_is_thumb, and so we never call arm_frame_is_thumb.
>> 
>> However, in the worst case scenario, if we did end up calling
>> arm_frame_is_thumb, as the current inferior should now be the ARM
>> inferior, the current frame should be an ARM frame, so we still should
>> not hit undefined behaviour.
>> 
>> I have added an assert to arm_frame_is_thumb.
>> ---
>>   gdb/arm-tdep.c   | 12 ++++++++----
>>   gdb/breakpoint.c | 24 ++++++++++++++++++------
>>   2 files changed, 26 insertions(+), 10 deletions(-)
>> 
>> diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
>> index 7f27d4bd6e8..e0e5c7efd63 100644
>> --- a/gdb/arm-tdep.c
>> +++ b/gdb/arm-tdep.c
>> @@ -541,20 +541,24 @@ arm_is_thumb (struct regcache *regcache)
>>     return (cpsr & t_bit) != 0;
>>   }
>>   
>> -/* Determine if FRAME is executing in Thumb mode.  */
>> +/* Determine if FRAME is executing in Thumb mode.  FRAME must be an ARM
>> +   frame.  */
>>   
>>   int
>>   arm_frame_is_thumb (struct frame_info *frame)
>>   {
>> -  CORE_ADDR cpsr;
>> -  ULONGEST t_bit = arm_psr_thumb_bit (get_frame_arch (frame));
>> +  /* Check the architecture of FRAME.  */
>> +  struct gdbarch *gdbarch = get_frame_arch (frame);
>> +  gdb_assert (gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm);
>>   
>>     /* Every ARM frame unwinder can unwind the T bit of the CPSR, either
>>        directly (from a signal frame or dummy frame) or by interpreting
>>        the saved LR (from a prologue or DWARF frame).  So consult it and
>>        trust the unwinders.  */
>> -  cpsr = get_frame_register_unsigned (frame, ARM_PS_REGNUM);
>> +  CORE_ADDR cpsr = get_frame_register_unsigned (frame, ARM_PS_REGNUM);
>>   
>> +  /* Find and extract the thumb bit.  */
>> +  ULONGEST t_bit = arm_psr_thumb_bit (gdbarch);
>>     return (cpsr & t_bit) != 0;
>>   }
>>   
>> diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
>> index ed932a19ed7..5370e70f15e 100644
>> --- a/gdb/breakpoint.c
>> +++ b/gdb/breakpoint.c
>> @@ -124,7 +124,8 @@ static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
>>   
>>   static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
>>   					    CORE_ADDR bpaddr,
>> -					    enum bptype bptype);
>> +					    enum bptype bptype,
>> +					    struct program_space *pspace);
>>   
>>   static int watchpoint_locations_match (struct bp_location *loc1,
>>   				       struct bp_location *loc2);
>> @@ -7114,8 +7115,11 @@ breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
>>   
>>   static CORE_ADDR
>>   adjust_breakpoint_address (struct gdbarch *gdbarch,
>> -			   CORE_ADDR bpaddr, enum bptype bptype)
>> +			   CORE_ADDR bpaddr, enum bptype bptype,
>> +			   struct program_space *pspace)
>>   {
>> +  gdb_assert (pspace != nullptr);
>> +
>>     if (bptype == bp_watchpoint
>>         || bptype == bp_hardware_watchpoint
>>         || bptype == bp_read_watchpoint
>> @@ -7140,10 +7144,16 @@ adjust_breakpoint_address (struct gdbarch *gdbarch,
>>       {
>>         CORE_ADDR adjusted_bpaddr = bpaddr;
>>   
>> +      /* Some targets have architectural constraints on the placement
>> +	 of breakpoint instructions.  Obtain the adjusted address.  */
>>         if (gdbarch_adjust_breakpoint_address_p (gdbarch))
>>   	{
>> -	  /* Some targets have architectural constraints on the placement
>> -	     of breakpoint instructions.  Obtain the adjusted address.  */
>> +	  /* Targets that implement this adjustment function will
>> +	     likely inspect either the symbol table, or target memory
>> +	     add BPADDR, so ensure a suitable thread (and its
>
> Is there something funny in the above line? Should add->and?
>

Yeah, that doesn't seem right.  I think I meant to see 'target memory at
BPADDR'.

The patch below has this fix, nothing else changed.

Thanks,
Andrew

---

commit b72622f7f8c979ebf2f923fe3f8bfb304843c2d3
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Mon Jun 13 14:34:01 2022 +0100

    gdb: select suitable thread for gdbarch_adjust_breakpoint_address
    
    The three targets that implement gdbarch_adjust_breakpoint_address are
    arm, frv, and mips.  In each of these targets the adjust breakpoint
    address function does some combination of reading the symbol table, or
    reading memory at the location the breakpoint could be placed.
    
    The problem is that performing these actions requires that the current
    inferior and program space be the one in which the breakpoint will be
    placed, and this is not currently always the case.
    
    Consider a GDB session with multiple inferiors.  One inferior might be
    a native target while another could be a remote target of a completely
    different architecture.  Alternatively, if we consider ARM and
    AArch64, one native inferior might be AArch64, while a second native
    inferior could be ARM.
    
    In these cases it is possible, and valid, for a user to have one
    inferior selected, and place a breakpoint in the other inferior by
    placing a breakpoint on a particular symbol.
    
    If this happens, then currently, when
    gdbarch_adjust_breakpoint_address is called, the wrong inferior (and
    program space) will be selected, and memory reads, and symbol look
    ups, will not return the expected results, this could lead to
    breakpoints being placed in the wrong location.
    
    There are currently two places where gdbarch_adjust_breakpoint_address
    is called:
    
      1. In infrun.c, in the function handle_step_into_function.  In this
      case, I believe that the correct inferior and program space will
      already be selected as this is called as part of the stop event
      handling, so I don't think we need to worry about this case, and
    
      2. In breakpoint.c, in the function adjust_breakpoint_address, which
      is itself called from code_breakpoint::add_location and
      watch_command_1.
    
      The watch_command_1 case I don't think we need to worry about, this
      is for when a local watch expression is created, which can only be
      in the currently selected inferior, so this case should be fine.
    
      The code_breakpoint::add_location case is the one that needs fixing,
      this is what allows a breakpoint to be created between inferiors.
    
    To fix the code_breakpoint::add_location case, I propose that we pass
    the "correct" program_space (i.e. the program space in which the
    breakpoint will be created) to the adjust_breakpoint_address function.
    Then in adjust_breakpoint_address we can make use of
    switch_to_program_space_and_thread to switch program_space and
    inferior before calling gdbarch_adjust_breakpoint_address.
    
    I discovered this issue while working on a later patch in this
    series.  This later patch will detect when we cast the result of
    gdbarch_tdep to the wrong type.
    
    With this later patch in place I ran gdb.multi/multi-arch.exp on an
    AArch64 target.  In this situation, two inferiors are created, an
    AArch64 inferior, and an ARM inferior.  The test selected the AArch64
    inferior and tries to create a breakpoint in the ARM inferior.
    
    As a result of this we end up in arm_adjust_breakpoint_address, which
    calls arm_pc_is_thumb.  Before this commit the AArch64 inferior would
    be current.  As a result, all of the checks in arm_pc_is_thumb would
    fail (they rely on reading symbols from the current program space),
    and so, at the end of arm_pc_is_thumb we would call
    arm_frame_is_thumb.  However, remember, at this point the current
    inferior is the AArch64 inferior, so the current frame is an AArch64
    frame.
    
    In arm_frame_is_thumb we call arm_psr_thumb_bit, which calls
    gdbarch_tdep and casts the result to arm_gdbarch_tdep.  This is wrong,
    the tdep field is of type aarch64_gdbarch_tdep.  After this we have
    undefined behaviour.
    
    With this patch in place, we will have switched to a thread in the ARM
    program space before calling arm_adjust_breakpoint_address.  As a
    result, we now succeed in looking up the required symbols in
    arm_pc_is_thumb, and so we never call arm_frame_is_thumb.
    
    However, in the worst case scenario, if we did end up calling
    arm_frame_is_thumb, as the current inferior should now be the ARM
    inferior, the current frame should be an ARM frame, so we still should
    not hit undefined behaviour.
    
    I have added an assert to arm_frame_is_thumb.

diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 7f27d4bd6e8..e0e5c7efd63 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -541,20 +541,24 @@ arm_is_thumb (struct regcache *regcache)
   return (cpsr & t_bit) != 0;
 }
 
-/* Determine if FRAME is executing in Thumb mode.  */
+/* Determine if FRAME is executing in Thumb mode.  FRAME must be an ARM
+   frame.  */
 
 int
 arm_frame_is_thumb (struct frame_info *frame)
 {
-  CORE_ADDR cpsr;
-  ULONGEST t_bit = arm_psr_thumb_bit (get_frame_arch (frame));
+  /* Check the architecture of FRAME.  */
+  struct gdbarch *gdbarch = get_frame_arch (frame);
+  gdb_assert (gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm);
 
   /* Every ARM frame unwinder can unwind the T bit of the CPSR, either
      directly (from a signal frame or dummy frame) or by interpreting
      the saved LR (from a prologue or DWARF frame).  So consult it and
      trust the unwinders.  */
-  cpsr = get_frame_register_unsigned (frame, ARM_PS_REGNUM);
+  CORE_ADDR cpsr = get_frame_register_unsigned (frame, ARM_PS_REGNUM);
 
+  /* Find and extract the thumb bit.  */
+  ULONGEST t_bit = arm_psr_thumb_bit (gdbarch);
   return (cpsr & t_bit) != 0;
 }
 
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index ed932a19ed7..4b8e2d66267 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -124,7 +124,8 @@ static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
 
 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
 					    CORE_ADDR bpaddr,
-					    enum bptype bptype);
+					    enum bptype bptype,
+					    struct program_space *pspace);
 
 static int watchpoint_locations_match (struct bp_location *loc1,
 				       struct bp_location *loc2);
@@ -7114,8 +7115,11 @@ breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
 
 static CORE_ADDR
 adjust_breakpoint_address (struct gdbarch *gdbarch,
-			   CORE_ADDR bpaddr, enum bptype bptype)
+			   CORE_ADDR bpaddr, enum bptype bptype,
+			   struct program_space *pspace)
 {
+  gdb_assert (pspace != nullptr);
+
   if (bptype == bp_watchpoint
       || bptype == bp_hardware_watchpoint
       || bptype == bp_read_watchpoint
@@ -7140,11 +7144,18 @@ adjust_breakpoint_address (struct gdbarch *gdbarch,
     {
       CORE_ADDR adjusted_bpaddr = bpaddr;
 
+      /* Some targets have architectural constraints on the placement
+	 of breakpoint instructions.  Obtain the adjusted address.  */
       if (gdbarch_adjust_breakpoint_address_p (gdbarch))
 	{
-	  /* Some targets have architectural constraints on the placement
-	     of breakpoint instructions.  Obtain the adjusted address.  */
-	  adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
+	  /* Targets that implement this adjustment function will likely
+	     inspect either the symbol table, or target memory at BPADDR,
+	     so ensure a suitable thread (and its associated program space)
+	     are currently selected.  */
+	  scoped_restore_current_pspace_and_thread restore_pspace_thread;
+	  switch_to_program_space_and_thread (pspace);
+	  adjusted_bpaddr
+	    = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
 	}
 
       adjusted_bpaddr = address_significant (gdbarch, adjusted_bpaddr);
@@ -8098,7 +8109,8 @@ code_breakpoint::add_location (const symtab_and_line &sal)
      not want its scan of the location chain to find a breakpoint and
      location that's only been partially initialized.  */
   adjusted_address = adjust_breakpoint_address (loc_gdbarch,
-						sal.pc, type);
+						sal.pc, type,
+						sal.pspace);
 
   /* Sort the locations by their ADDRESS.  */
   new_loc = allocate_location ();
@@ -10085,7 +10097,8 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
 	  scope_breakpoint->loc->address
 	    = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
 					 scope_breakpoint->loc->requested_address,
-					 scope_breakpoint->type);
+					 scope_breakpoint->type,
+					 current_program_space);
 	}
     }
 


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCHv3 0/6] Handle trying to use a native target with the wrong binary
  2022-06-13 16:15   ` [PATCHv3 0/6] Handle trying to use a native target with the wrong binary Andrew Burgess
                       ` (5 preceding siblings ...)
  2022-06-13 16:15     ` [PATCHv3 6/6] gdb: native target invalid architecture detection Andrew Burgess
@ 2022-06-24 10:15     ` Andrew Burgess
  2022-06-28 14:28     ` [PATCHv4 0/6] Detect invalid casts of gdbarch_tdep structures Andrew Burgess
  7 siblings, 0 replies; 83+ messages in thread
From: Andrew Burgess @ 2022-06-24 10:15 UTC (permalink / raw)
  To: gdb-patches


Ping!

I'm planning to push this next week unless someone objects:

  Patches #1 -> #3 are obvious fixes,

  Patches #4 -> #5, are useful for finding real bugs in GDB (see the
  first 3 patches), so I think are a good thing, even if it will be
  slightly annoying for anyone with an out of tree GDB (though the
  updates required are pretty straight forward),

  Patch #6, this is the one I'd most appreciate feedback on, is this
  strategy acceptable?

Thanks,
Andrew


Andrew Burgess <aburgess@redhat.com> writes:

> Changes since v2:
>
>  - Patch #3 has been replaced after feedback from Luis.  New patch
>    fixes sider issues for arm, mips, and frv targets, this includes
>    the issue the v2 patch fixed.
>
>  - Nothing else has changed.
>
> Changes since v1:
>
>  - Patches #1 and #2 are unchanged.
>
>  - Patch #3 is new in this version.
>
>  - Patch #4 is unchanged (was patch 3).
>
>  - Patch #5 is updated inline with John's feedback (was patch 4).
>
>  - Patch #6 is extended to handle multi-arch case for rs6000/ppc and
>    arm/aarch64, commit message is updated to discuss these cases, as
>    well as mentioning i386/x86-64 (was patch 5).
>
> Series has been tested on x86-64/linux and aarch64/linux.
>
> ---
>
> Andrew Burgess (6):
>   gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope
>   gdb/mips: rewrite show_mask_address
>   gdb: select suitable thread for gdbarch_adjust_breakpoint_address
>   gdb: move the type cast into gdbarch_tdep
>   gdb: ensure the cast in gdbarch_tdep is valid
>   gdb: native target invalid architecture detection
>
>  gdb/aarch64-fbsd-nat.c     |   4 +-
>  gdb/aarch64-fbsd-tdep.c    |   6 +-
>  gdb/aarch64-linux-nat.c    |  28 +++++---
>  gdb/aarch64-linux-tdep.c   |  10 +--
>  gdb/aarch64-newlib-tdep.c  |   2 +-
>  gdb/aarch64-tdep.c         |  48 ++++++-------
>  gdb/aix-thread.c           |  28 ++++----
>  gdb/alpha-linux-tdep.c     |   2 +-
>  gdb/alpha-netbsd-tdep.c    |   2 +-
>  gdb/alpha-obsd-tdep.c      |   2 +-
>  gdb/alpha-tdep.c           |  14 ++--
>  gdb/amd64-darwin-tdep.c    |   2 +-
>  gdb/amd64-fbsd-nat.c       |   4 +-
>  gdb/amd64-fbsd-tdep.c      |   4 +-
>  gdb/amd64-linux-tdep.c     |   8 +--
>  gdb/amd64-netbsd-tdep.c    |   2 +-
>  gdb/amd64-obsd-tdep.c      |   2 +-
>  gdb/amd64-sol2-tdep.c      |   2 +-
>  gdb/amd64-tdep.c           |  34 ++++-----
>  gdb/amd64-windows-tdep.c   |   2 +-
>  gdb/arc-linux-tdep.c       |   4 +-
>  gdb/arc-newlib-tdep.c      |   2 +-
>  gdb/arc-tdep.c             |   8 +--
>  gdb/arch-utils.c           |  14 +++-
>  gdb/arch-utils.h           |   5 ++
>  gdb/arm-fbsd-nat.c         |   4 +-
>  gdb/arm-fbsd-tdep.c        |   6 +-
>  gdb/arm-linux-nat.c        |   8 +--
>  gdb/arm-linux-tdep.c       |   4 +-
>  gdb/arm-netbsd-nat.c       |   8 +--
>  gdb/arm-netbsd-tdep.c      |   4 +-
>  gdb/arm-none-tdep.c        |   2 +-
>  gdb/arm-obsd-tdep.c        |   2 +-
>  gdb/arm-tdep.c             | 142 ++++++++++++++++++++-----------------
>  gdb/arm-wince-tdep.c       |   2 +-
>  gdb/avr-tdep.c             |  12 ++--
>  gdb/bfin-tdep.c            |   4 +-
>  gdb/breakpoint.c           |  24 +++++--
>  gdb/cris-linux-tdep.c      |   2 +-
>  gdb/cris-tdep.c            |  18 ++---
>  gdb/csky-tdep.c            |   2 +-
>  gdb/frv-tdep.c             |   4 +-
>  gdb/ft32-tdep.c            |   2 +-
>  gdb/gdbarch.h              |  26 ++++++-
>  gdb/hppa-bsd-tdep.c        |   2 +-
>  gdb/hppa-linux-tdep.c      |   4 +-
>  gdb/hppa-tdep.c            |  12 ++--
>  gdb/i386-bsd-tdep.c        |   2 +-
>  gdb/i386-darwin-tdep.c     |   4 +-
>  gdb/i386-fbsd-tdep.c       |   4 +-
>  gdb/i386-gnu-tdep.c        |   2 +-
>  gdb/i386-go32-tdep.c       |   2 +-
>  gdb/i386-linux-tdep.c      |   4 +-
>  gdb/i386-netbsd-tdep.c     |   4 +-
>  gdb/i386-nto-tdep.c        |   6 +-
>  gdb/i386-obsd-tdep.c       |   2 +-
>  gdb/i386-sol2-tdep.c       |   2 +-
>  gdb/i386-tdep.c            |  98 ++++++++++++-------------
>  gdb/i386-windows-tdep.c    |   2 +-
>  gdb/i387-tdep.c            |  20 +++---
>  gdb/ia64-linux-tdep.c      |   2 +-
>  gdb/ia64-tdep.c            |  12 ++--
>  gdb/inf-child.c            |  19 +++++
>  gdb/inf-child.h            |   2 +
>  gdb/infcmd.c               |   8 +++
>  gdb/loongarch-linux-nat.c  |   6 +-
>  gdb/loongarch-linux-tdep.c |   8 +--
>  gdb/loongarch-tdep.c       |  10 +--
>  gdb/m32c-tdep.c            |  58 +++++++--------
>  gdb/m68hc11-tdep.c         |  12 ++--
>  gdb/m68k-bsd-tdep.c        |   2 +-
>  gdb/m68k-linux-tdep.c      |   2 +-
>  gdb/m68k-tdep.c            |  38 +++++-----
>  gdb/mep-tdep.c             |   6 +-
>  gdb/mips-linux-tdep.c      |   4 +-
>  gdb/mips-tdep.c            |  85 +++++++++++-----------
>  gdb/mn10300-tdep.c         |   2 +-
>  gdb/mn10300-tdep.h         |   2 +-
>  gdb/msp430-tdep.c          |  12 ++--
>  gdb/nds32-tdep.c           |  20 +++---
>  gdb/nios2-linux-tdep.c     |   2 +-
>  gdb/nios2-tdep.c           |   4 +-
>  gdb/or1k-tdep.c            |   8 +--
>  gdb/ppc-fbsd-nat.c         |  12 +++-
>  gdb/ppc-fbsd-tdep.c        |   8 +--
>  gdb/ppc-linux-nat.c        |  30 +++++---
>  gdb/ppc-linux-tdep.c       |  18 ++---
>  gdb/ppc-netbsd-nat.c       |   6 +-
>  gdb/ppc-netbsd-tdep.c      |   2 +-
>  gdb/ppc-obsd-nat.c         |  12 +++-
>  gdb/ppc-obsd-tdep.c        |   2 +-
>  gdb/ppc-sysv-tdep.c        |  22 +++---
>  gdb/ppc64-tdep.c           |   2 +-
>  gdb/riscv-linux-tdep.c     |   2 +-
>  gdb/riscv-tdep.c           |  26 +++----
>  gdb/rl78-tdep.c            |   8 +--
>  gdb/rs6000-aix-nat.c       |  14 +++-
>  gdb/rs6000-aix-tdep.c      |  16 ++---
>  gdb/rs6000-lynx178-tdep.c  |   4 +-
>  gdb/rs6000-tdep.c          | 132 +++++++++++++++++-----------------
>  gdb/rx-tdep.c              |   2 +-
>  gdb/s390-linux-tdep.c      |  20 +++---
>  gdb/s390-tdep.c            |  42 +++++------
>  gdb/sh-linux-tdep.c        |   2 +-
>  gdb/sh-netbsd-tdep.c       |   2 +-
>  gdb/sh-tdep.c              |   8 +--
>  gdb/sparc-linux-tdep.c     |   4 +-
>  gdb/sparc-netbsd-tdep.c    |   2 +-
>  gdb/sparc-sol2-tdep.c      |   2 +-
>  gdb/sparc-tdep.c           |  14 ++--
>  gdb/sparc64-fbsd-tdep.c    |   2 +-
>  gdb/sparc64-linux-tdep.c   |   4 +-
>  gdb/sparc64-netbsd-tdep.c  |   2 +-
>  gdb/sparc64-obsd-tdep.c    |   2 +-
>  gdb/sparc64-sol2-tdep.c    |   2 +-
>  gdb/sparc64-tdep.c         |  10 +--
>  gdb/target-delegates.c     |  28 ++++++++
>  gdb/target.h               |  13 +++-
>  gdb/tic6x-linux-tdep.c     |   6 +-
>  gdb/tic6x-tdep.c           |   6 +-
>  gdb/v850-tdep.c            |   6 +-
>  gdb/windows-nat.c          |   2 +-
>  gdb/xtensa-linux-nat.c     |   4 +-
>  gdb/xtensa-linux-tdep.c    |   2 +-
>  gdb/xtensa-tdep.c          |  54 +++++++-------
>  gdb/z80-tdep.c             |   8 +--
>  126 files changed, 868 insertions(+), 706 deletions(-)
>
> -- 
> 2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCHv3 3/6] gdb: select suitable thread for gdbarch_adjust_breakpoint_address
  2022-06-13 16:15     ` [PATCHv3 3/6] gdb: select suitable thread for gdbarch_adjust_breakpoint_address Andrew Burgess
  2022-06-14  9:45       ` Luis Machado
@ 2022-06-24 16:58       ` Pedro Alves
  1 sibling, 0 replies; 83+ messages in thread
From: Pedro Alves @ 2022-06-24 16:58 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

On 2022-06-13 17:15, Andrew Burgess via Gdb-patches wrote:

> ---
>  gdb/arm-tdep.c   | 12 ++++++++----
>  gdb/breakpoint.c | 24 ++++++++++++++++++------
>  2 files changed, 26 insertions(+), 10 deletions(-)
> 
> diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
> index 7f27d4bd6e8..e0e5c7efd63 100644
> --- a/gdb/arm-tdep.c
> +++ b/gdb/arm-tdep.c
> @@ -541,20 +541,24 @@ arm_is_thumb (struct regcache *regcache)
>    return (cpsr & t_bit) != 0;
>  }
>  
> -/* Determine if FRAME is executing in Thumb mode.  */
> +/* Determine if FRAME is executing in Thumb mode.  FRAME must be an ARM
> +   frame.  */
>  
>  int
>  arm_frame_is_thumb (struct frame_info *frame)
>  {
> -  CORE_ADDR cpsr;
> -  ULONGEST t_bit = arm_psr_thumb_bit (get_frame_arch (frame));
> +  /* Check the architecture of FRAME.  */
> +  struct gdbarch *gdbarch = get_frame_arch (frame);
> +  gdb_assert (gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm);

I think you wanted instead:

  gdb_assert (gdbarch_bfd_arch_info (gdbarch)->arch == bfd_arch_arm);

?

>  
>    /* Every ARM frame unwinder can unwind the T bit of the CPSR, either
>       directly (from a signal frame or dummy frame) or by interpreting
>       the saved LR (from a prologue or DWARF frame).  So consult it and
>       trust the unwinders.  */
> -  cpsr = get_frame_register_unsigned (frame, ARM_PS_REGNUM);
> +  CORE_ADDR cpsr = get_frame_register_unsigned (frame, ARM_PS_REGNUM);
>  
> +  /* Find and extract the thumb bit.  */
> +  ULONGEST t_bit = arm_psr_thumb_bit (gdbarch);
>    return (cpsr & t_bit) != 0;
>  }

>  static CORE_ADDR
>  adjust_breakpoint_address (struct gdbarch *gdbarch,
> -			   CORE_ADDR bpaddr, enum bptype bptype)
> +			   CORE_ADDR bpaddr, enum bptype bptype,
> +			   struct program_space *pspace)
>  {
> +  gdb_assert (pspace != nullptr);
> +
>    if (bptype == bp_watchpoint
>        || bptype == bp_hardware_watchpoint
>        || bptype == bp_read_watchpoint
> @@ -7140,10 +7144,16 @@ adjust_breakpoint_address (struct gdbarch *gdbarch,
>      {
>        CORE_ADDR adjusted_bpaddr = bpaddr;
>  
> +      /* Some targets have architectural constraints on the placement
> +	 of breakpoint instructions.  Obtain the adjusted address.  */
>        if (gdbarch_adjust_breakpoint_address_p (gdbarch))
>  	{
> -	  /* Some targets have architectural constraints on the placement
> -	     of breakpoint instructions.  Obtain the adjusted address.  */
> +	  /* Targets that implement this adjustment function will
> +	     likely inspect either the symbol table, or target memory
> +	     add BPADDR, so ensure a suitable thread (and its

s/add BPADDR/at BPADDR/, I think.

Note the comment as is doesn't justify why switch to a thread, as opposed
to just switching the inferior (e.g., with switch_to_inferior_no_thread),
as you can read memory without a thread selected (well, modulo a bug
in linux-nat.c).  We want a thread here for the arm fallback.

I'd suggest extending the comment in that direction, like:

  "... or target memory at BPADDR, or even state registers."

> +	     associated program space) are currently selected.  */
> +	  scoped_restore_current_pspace_and_thread restore_pspace_thread;
> +	  switch_to_program_space_and_thread (pspace);
>  	  adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
>  	}
Otherwise LGTM.

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCHv3 5/6] gdb: ensure the cast in gdbarch_tdep is valid
  2022-06-13 16:15     ` [PATCHv3 5/6] gdb: ensure the cast in gdbarch_tdep is valid Andrew Burgess
@ 2022-06-24 18:15       ` Pedro Alves
  0 siblings, 0 replies; 83+ messages in thread
From: Pedro Alves @ 2022-06-24 18:15 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

On 2022-06-13 17:15, Andrew Burgess via Gdb-patches wrote:
> This commit builds on the previous commit and modifies the
> gdbarch_tdep function to ensure that the cast being performed is
> valid.
> 
> To do this I make use of dynamic_cast to ensure that the generic
> gdbarch_tdep pointer that we have is of the correct type.
> 
> The only problem with this approach is that, in order to use
> dynamic_cast, we need RTTI information, which requires the class to
> have a vtable, which currently, is not something the various tdep
> classes have.
> 
> And so, in this commit, I add a virtual destructor to the gdbarch_tdep
> class.
> 
> With this change I can now add an assert in the gdbarch_tdep function.
> 
> Obviously, this change comes at a cost, creation of the tdep classes
> is now slightly more expensive (due to vtable initialisation),
> however, this only happens when a new gdbarch is created, which is not
> that frequent, so I don't see that as a huge concern.
> 

...

> Then, there is an increased cost each time the tdep is accessed.  This
> is much more frequent, but I don't believe the cost is excessive (a
> vtable pointer comparison), at least, no worse than many of our other
> asserts.

I don't think that's true.  dynamic_cast does not really do a vtable
pointer comparison.  It does pointer arithmetic/adjustment, walks the vtables
to find the type info for each type in the hierarchy, and compares the type's
type info objects, which usually mean string-comparing the class names.  Only
some systems can do pointer comparisons to compare types.  See e.g.:

  https://github.com/gcc-mirror/gcc/blob/bb8e93eb1acae30a5fbe7e13149493ce4ccd301a/libstdc%2B%2B-v3/libsupc%2B%2B/typeinfo#L52

See the benchmark I posted in this previous response to Tromey:

  https://sourceware.org/pipermail/gdb-patches/2022-April/188102.html

Maybe we should revisit Tromey's idea of a new cast "operator",
but make it static_cast in release mode?  This patch that I posted today
adds a DEVELOPMENT macro symbol to common-config.h, we can make use of that:

  https://sourceware.org/pipermail/gdb-patches/2022-June/190301.html

Also, dynamic_cast lets you try to cast to completely unrelated types (undefined
behavior instead of compile error), while to me is seems better to make it fail
to compile.  Like:

template<typename T, typename V>
T *
checked_dyn_cast (V *v)
{
  /* dynamic_cast compiles even if V and T are completely unrelated.
     This assert prevent that, only letting you do downcasts, and
     casts to same type.  */
  static_assert (std::is_base_of<V, T>::value
		 || std::is_base_of<T, V>::value,
		 "types must be related");
  /* Check for polymorphism explicitly in case we're in release
     mode.  */
  static_assert (std::is_polymorphic<V>::value,
		 "types must be polymorphic");

#ifdef DEVELOPMENT
  T *result = dynamic_cast<T *> (v);
  assert (result != nullptr);
#else
  T *result = static_cast<T *> (v);
#endif
  return result;
}

With that, this compiles & works as expected:

struct A
{
  virtual ~A() {}
};

struct B : A {};

struct C {};

void func () 
{
  A *a = new A();
  B *b = new B();
  C *c = new C();

  // these work
  checked_dyn_cast<A> (a);
  checked_dyn_cast<B> (a);
  checked_dyn_cast<A> (b);
  checked_dyn_cast<const B> (a);

  // while these fail the static assertions.
  // checked_dyn_cast<C> (a);
  // checked_dyn_cast<A> (c);
  // checked_dyn_cast<A> (123);
}

Anyhow, this can always be done after your patch, I don't mean to suggest
we should do this before.

Other than the nit in the commit log, the patch LGTM.

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCHv3 6/6] gdb: native target invalid architecture detection
  2022-06-13 16:15     ` [PATCHv3 6/6] gdb: native target invalid architecture detection Andrew Burgess
@ 2022-06-24 19:23       ` Pedro Alves
  2022-06-27 16:27         ` Andrew Burgess
  0 siblings, 1 reply; 83+ messages in thread
From: Pedro Alves @ 2022-06-24 19:23 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

On 2022-06-13 17:15, Andrew Burgess via Gdb-patches wrote:

> This leaves just one question, what about native targets that support
> multiple architectures?
> 

I have another question.  I'm confused on how if e.g., on x86-64, you
load a RISC-V binary into GDB, and the try to run it, we don't end up
with architecture of the target description instead.  If the target
reports a target description, and the resulting architecture is not
compatible with the executable, then I think it would make sense to
use the architecture of the target?

If I start a 64-bit program on x86-64, like:

 $ gdb ~/gdb/tests/main64
 GNU gdb (GDB) 13.0.50.20220624-git
 ...
 (gdb) start
 Temporary breakpoint 1 at 0x400492: file main.c, line 11.
 Starting program: /home/pedro/gdb/tests/main64

 Temporary breakpoint 1, main (argc=1, argv=0x7fffffffdc48) at main.c:11
 11        return 0;

and then try to load the executable of an incompatible arch, like:

 (gdb) file ~/gdb/tests/main32
 A program is being debugged already.
 Are you sure you want to change the file? (y or n) y
 warning: Selected architecture i386 is not compatible with reported target architecture i386:x86-64
 Architecture of file not recognized.

then GDB doesn't switch the architecture to the file's architecture, it is still x86-64:

 (gdb) show architecture 
 The target architecture is set to "auto" (currently "i386:x86-64").

and it doesn't let me manually select an incompatible architecture either:

 (gdb) set architecture riscv
 warning: Selected architecture riscv is not compatible with reported target architecture i386:x86-64
 Architecture `riscv' not recognized.
 The target architecture is set to "auto" (currently "i386:x86-64").
 (gdb) 

It kind of sounds like if GDB detected the incompatibility when we first fetch the
target description, similarly to how we detect it in the cases above, and GDB picked
the target arch or errored out after detecting the incompatibility, then we wouldn't
need a patch like yours?  How come the mismatch isn't detected then (when we first
retrieve the target description) today?

> +
>  protected:
>    /* Unpush the target if it wasn't explicitly open with "target native"
>       and there are no live inferiors left.  Note: if calling this as a
> diff --git a/gdb/infcmd.c b/gdb/infcmd.c
> index e909d4d4c81..b8acf858b3a 100644
> --- a/gdb/infcmd.c
> +++ b/gdb/infcmd.c
> @@ -413,6 +413,10 @@ run_command_1 (const char *args, int from_tty, enum run_how run_how)
>    if (non_stop && !run_target->supports_non_stop ())
>      error (_("The target does not support running in non-stop mode."));
>  
> +  if (!run_target->supports_architecture_p (get_current_arch ()))
> +    error (_("The target does not support architecture \"%s\"."),
> +	   gdbarch_bfd_arch_info (get_current_arch ())->printable_name);
> +
>    /* Done.  Can now set breakpoints, change inferior args, etc.  */
>  
>    /* Insert temporary breakpoint in main function if requested.  */
> @@ -2590,6 +2594,10 @@ attach_command (const char *args, int from_tty)
>    if (non_stop && !attach_target->supports_non_stop ())
>      error (_("Cannot attach to this target in non-stop mode"));
>  
> +  if (!attach_target->supports_architecture_p (get_current_arch ()))
> +    error (_("The target does not support architecture \"%s\"."),
> +	   gdbarch_bfd_arch_info (get_current_arch ())->printable_name);
> +

Since the error is the same in both cases, I'd suggest putting it in
a shared routine, like:

 static void
 check_target_supports_current_arch (process_stratum_target *target)
 {
   if (!target->supports_architecture_p (get_current_arch ()))
     error (_("The target does not support architecture \"%s\"."),
 	   gdbarch_bfd_arch_info (get_current_arch ())->printable_name);
 }

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCHv3 6/6] gdb: native target invalid architecture detection
  2022-06-24 19:23       ` Pedro Alves
@ 2022-06-27 16:27         ` Andrew Burgess
  2022-06-27 21:38           ` Pedro Alves
  0 siblings, 1 reply; 83+ messages in thread
From: Andrew Burgess @ 2022-06-27 16:27 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches

Pedro Alves <pedro@palves.net> writes:

> On 2022-06-13 17:15, Andrew Burgess via Gdb-patches wrote:
>
>> This leaves just one question, what about native targets that support
>> multiple architectures?
>> 
>
> I have another question.  I'm confused on how if e.g., on x86-64, you
> load a RISC-V binary into GDB, and the try to run it, we don't end up
> with architecture of the target description instead.

The problem is that we end up trying to read the registers before we
read the target description.  Which I suspect you will say sounds wrong,
and I agree.

I removed the error() calls from this patch, and reran GDB, here's the
stack at the point of failure:

  #0  internal_error (file=0x16bcfc8 "../../src/gdb/../gdbsupport/gdb-checked-static-cast.h", line=60, 
      fmt=0x16bcf80 "%s: Assertion `%s' failed.") at ../../src/gdbsupport/errors.cc:54
  #1  0x00000000004c4f4c in gdb::checked_static_cast<i386_gdbarch_tdep*, gdbarch_tdep> (v=0x337b910)
      at ../../src/gdb/../gdbsupport/gdb-checked-static-cast.h:60
  #2  0x00000000004d09c2 in gdbarch_tdep<i386_gdbarch_tdep> (gdbarch=0x3a4c630) at ../../src/gdb/gdbarch.h:167
  #3  0x00000000004d059e in amd64_supply_fxsave (regcache=0x30f5f10, regnum=-1, fxsave=0x7fffffff9070)
      at ../../src/gdb/amd64-tdep.c:3387
  #4  0x00000000004c5958 in amd64_linux_nat_target::fetch_registers (this=0x2d27140 <the_amd64_linux_nat_target>, 
      regcache=0x30f5f10, regnum=32) at ../../src/gdb/amd64-linux-nat.c:260
  #5  0x0000000000dd74bd in target_fetch_registers (regcache=0x30f5f10, regno=32) at ../../src/gdb/target.c:3948
  #6  0x0000000000bf2540 in regcache::raw_update (this=0x30f5f10, regnum=32) at ../../src/gdb/regcache.c:587
  #7  0x0000000000bf25e5 in readable_regcache::raw_read (this=0x30f5f10, regnum=32, 
      buf=0x7fffffff9c60 "\200\234\377\377\377\177") at ../../src/gdb/regcache.c:601
  #8  0x0000000000bf291d in readable_regcache::cooked_read (this=0x30f5f10, regnum=32, 
      buf=0x7fffffff9c60 "\200\234\377\377\377\177") at ../../src/gdb/regcache.c:690
  #9  0x0000000000bf9d6a in readable_regcache::cooked_read<unsigned long, void> (this=0x30f5f10, regnum=32, 
      val=0x7fffffff9d28) at ../../src/gdb/regcache.c:775
  #10 0x0000000000bf2da9 in regcache_cooked_read_unsigned (regcache=0x30f5f10, regnum=32, val=0x7fffffff9d28)
      at ../../src/gdb/regcache.c:789
  #11 0x0000000000bf43c4 in regcache_read_pc (regcache=0x30f5f10) at ../../src/gdb/regcache.c:1325
  #12 0x00000000009c2e19 in save_stop_reason (lp=0x3a8ff80) at ../../src/gdb/linux-nat.c:2545
  #13 0x00000000009c40f0 in linux_nat_filter_event (lwpid=3990223, status=1407) at ../../src/gdb/linux-nat.c:3003
  #14 0x00000000009c471a in linux_nat_wait_1 (ptid=..., ourstatus=0x7fffffffa4f0, target_options=...)
      at ../../src/gdb/linux-nat.c:3178
  #15 0x00000000009c535a in linux_nat_target::wait (this=0x2d27140 <the_amd64_linux_nat_target>, ptid=..., 
      ourstatus=0x7fffffffa4f0, target_options=...) at ../../src/gdb/linux-nat.c:3416
  #16 0x0000000000dc5f3b in target_wait (ptid=..., status=0x7fffffffa4f0, options=...)
      at ../../src/gdb/target.c:2601
  #17 0x0000000000abd3c4 in startup_inferior (proc_target=0x2d27140 <the_amd64_linux_nat_target>, pid=3990223, 
      ntraps=1, last_waitstatus=0x0, last_ptid=0x0) at ../../src/gdb/nat/fork-inferior.c:482
  #18 0x00000000008a0165 in gdb_startup_inferior (pid=3990223, num_traps=1) at ../../src/gdb/fork-child.c:129
  #19 0x0000000000936f6e in inf_ptrace_target::create_inferior (this=0x2d27140 <the_amd64_linux_nat_target>, 
      exec_file=0x337c1b0 "/tmp/hello.rv32imc.x", allargs=..., env=0x2dba940, from_tty=1)
      at ../../src/gdb/inf-ptrace.c:105
  #20 0x00000000009bef5b in linux_nat_target::create_inferior (this=0x2d27140 <the_amd64_linux_nat_target>, 
      exec_file=0x337c1b0 "/tmp/hello.rv32imc.x", allargs=..., env=0x2dba940, from_tty=1)
      at ../../src/gdb/linux-nat.c:977
  #21 0x00000000009424ee in run_command_1 (args=0x0, from_tty=1, run_how=RUN_NORMAL) at ../../src/gdb/infcmd.c:461
  #22 0x0000000000942784 in run_command (args=0x0, from_tty=1) at ../../src/gdb/infcmd.c:519

In contrast, the call to target_find_description is done (indirectly)
from later in run_command_1, like this:

  #0  target_find_description () at ../../src.dev-4/gdb/target-descriptions.c:521
  #1  0x0000000000941e7c in post_create_inferior (from_tty=0) at ../../src.dev-4/gdb/infcmd.c:253
  #2  0x00000000009425ea in run_command_1 (args=0x0, from_tty=1, run_how=RUN_NORMAL) at ../../src.dev-4/gdb/infcmd.c:494
  #3  0x0000000000942784 in run_command (args=0x0, from_tty=1) at ../../src.dev-4/gdb/infcmd.c:519

So, after I start GDB like:

  $ arch
  x86_64
  $ gdb -q /tmp/hello.rv32imc.x
  Reading symbols from /tmp/hello.rv32imc.x...
  (gdb) show arch
  The target architecture is set to "auto" (currently "riscv:rv32").
  (gdb) run
  ...

The initial architecture is riscv:rv32, and it is this architecture that
is used for handling the initial stop.

So my first thought was, pretty much as you suggest, that we should
fetch the target description earlier, then we'll not run into this
problem at all.

My problem was figuring out the right place to add such a call.

We know it has to be before we enter regcache_read_pc, as at this point
the regcache is already created, and has the wrong architecture.

And it can't really be earlier than linux_nat_filter_event I think, as
before this point we don't know that the target has stopped.  We can't
probe the target for features (I would assume) if the target is not
currently stopped.

This seems to leave either save_stop_reason, or in the early stages of
get_thread_regcache maybe.

The problem with save_stop_reason is that it's Linux specific, so any
non-Linux targets will need to add their own code to catch this
situation.

Inside the get_thread_regcache code is possible I guess, but something
about it seemed off, I guess it was the idea of calling
get_thread_regcache and having the thread's architecture change under
your feet - that seemed pretty unexpected to me.

>                                                       If the target
> reports a target description, and the resulting architecture is not
> compatible with the executable, then I think it would make sense to
> use the architecture of the target?

I agree.  For a native target once the target actually tries to start
the executable I think we'd expect the target itself to report an error
relating to the wrong architecture.

>
> If I start a 64-bit program on x86-64, like:
>
>  $ gdb ~/gdb/tests/main64
>  GNU gdb (GDB) 13.0.50.20220624-git
>  ...
>  (gdb) start
>  Temporary breakpoint 1 at 0x400492: file main.c, line 11.
>  Starting program: /home/pedro/gdb/tests/main64
>
>  Temporary breakpoint 1, main (argc=1, argv=0x7fffffffdc48) at main.c:11
>  11        return 0;
>
> and then try to load the executable of an incompatible arch, like:
>
>  (gdb) file ~/gdb/tests/main32
>  A program is being debugged already.
>  Are you sure you want to change the file? (y or n) y
>  warning: Selected architecture i386 is not compatible with reported target architecture i386:x86-64
>  Architecture of file not recognized.
>
> then GDB doesn't switch the architecture to the file's architecture, it is still x86-64:
>
>  (gdb) show architecture 
>  The target architecture is set to "auto" (currently "i386:x86-64").
>
> and it doesn't let me manually select an incompatible architecture either:
>
>  (gdb) set architecture riscv
>  warning: Selected architecture riscv is not compatible with reported target architecture i386:x86-64
>  Architecture `riscv' not recognized.

[ Unrelated: We should probably remove that 'Architecture `riscv' not
  recognized.' line, as that seems wrong here.  The architecture is
  recognized, it's just not compatible.]

>  The target architecture is set to "auto" (currently "i386:x86-64").
>  (gdb) 
>
> It kind of sounds like if GDB detected the incompatibility when we first fetch the
> target description, similarly to how we detect it in the cases above, and GDB picked
> the target arch or errored out after detecting the incompatibility, then we wouldn't
> need a patch like yours?

I agree.  One other aspect is, do we have any native targets that don't
support reading a target description?  Hopefully not.

>                          How come the mismatch isn't detected then (when we first
> retrieve the target description) today?

Hopefully the above makes that clear, but the TLDR answer is: we attempt
to read the registers using the current architecture before we fetch the
target description.

I suspected that, in part, this patch would be a bit of a straw-man, I'd
appreciate any insight you have for how we might reorder things so that
the target description can be read before we try to read the registers.

Thanks,
Andrew



>
>> +
>>  protected:
>>    /* Unpush the target if it wasn't explicitly open with "target native"
>>       and there are no live inferiors left.  Note: if calling this as a
>> diff --git a/gdb/infcmd.c b/gdb/infcmd.c
>> index e909d4d4c81..b8acf858b3a 100644
>> --- a/gdb/infcmd.c
>> +++ b/gdb/infcmd.c
>> @@ -413,6 +413,10 @@ run_command_1 (const char *args, int from_tty, enum run_how run_how)
>>    if (non_stop && !run_target->supports_non_stop ())
>>      error (_("The target does not support running in non-stop mode."));
>>  
>> +  if (!run_target->supports_architecture_p (get_current_arch ()))
>> +    error (_("The target does not support architecture \"%s\"."),
>> +	   gdbarch_bfd_arch_info (get_current_arch ())->printable_name);
>> +
>>    /* Done.  Can now set breakpoints, change inferior args, etc.  */
>>  
>>    /* Insert temporary breakpoint in main function if requested.  */
>> @@ -2590,6 +2594,10 @@ attach_command (const char *args, int from_tty)
>>    if (non_stop && !attach_target->supports_non_stop ())
>>      error (_("Cannot attach to this target in non-stop mode"));
>>  
>> +  if (!attach_target->supports_architecture_p (get_current_arch ()))
>> +    error (_("The target does not support architecture \"%s\"."),
>> +	   gdbarch_bfd_arch_info (get_current_arch ())->printable_name);
>> +
>
> Since the error is the same in both cases, I'd suggest putting it in
> a shared routine, like:
>
>  static void
>  check_target_supports_current_arch (process_stratum_target *target)
>  {
>    if (!target->supports_architecture_p (get_current_arch ()))
>      error (_("The target does not support architecture \"%s\"."),
>  	   gdbarch_bfd_arch_info (get_current_arch ())->printable_name);
>  }


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCHv3 6/6] gdb: native target invalid architecture detection
  2022-06-27 16:27         ` Andrew Burgess
@ 2022-06-27 21:38           ` Pedro Alves
  2022-06-28 10:37             ` Andrew Burgess
  2022-06-30  9:33             ` [PATCHv3 6/6] gdb: native target invalid architecture detection Andrew Burgess
  0 siblings, 2 replies; 83+ messages in thread
From: Pedro Alves @ 2022-06-27 21:38 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

On 2022-06-27 17:27, Andrew Burgess wrote:
> Pedro Alves <pedro@palves.net> writes:
>> On 2022-06-13 17:15, Andrew Burgess via Gdb-patches wrote:
>> I have another question.  I'm confused on how if e.g., on x86-64, you
>> load a RISC-V binary into GDB, and the try to run it, we don't end up
>> with architecture of the target description instead.
> 
> The problem is that we end up trying to read the registers before we
> read the target description.  Which I suspect you will say sounds wrong,
> and I agree.
> 
> I removed the error() calls from this patch, and reran GDB, here's the
> stack at the point of failure:
> 

...

>   #11 0x0000000000bf43c4 in regcache_read_pc (regcache=0x30f5f10) at ../../src/gdb/regcache.c:1325
>   #12 0x00000000009c2e19 in save_stop_reason (lp=0x3a8ff80) at ../../src/gdb/linux-nat.c:2545
>   #13 0x00000000009c40f0 in linux_nat_filter_event (lwpid=3990223, status=1407) at ../../src/gdb/linux-nat.c:3003
>   #14 0x00000000009c471a in linux_nat_wait_1 (ptid=..., ourstatus=0x7fffffffa4f0, target_options=...)
>       at ../../src/gdb/linux-nat.c:3178
>   #15 0x00000000009c535a in linux_nat_target::wait (this=0x2d27140 <the_amd64_linux_nat_target>, ptid=..., 
>       ourstatus=0x7fffffffa4f0, target_options=...) at ../../src/gdb/linux-nat.c:3416
>   #16 0x0000000000dc5f3b in target_wait (ptid=..., status=0x7fffffffa4f0, options=...)
>       at ../../src/gdb/target.c:2601
>   #17 0x0000000000abd3c4 in startup_inferior (proc_target=0x2d27140 <the_amd64_linux_nat_target>, pid=3990223, 
>       ntraps=1, last_waitstatus=0x0, last_ptid=0x0) at ../../src/gdb/nat/fork-inferior.c:482

Alright, we're inside startup_inferior.

> 
> The initial architecture is riscv:rv32, and it is this architecture that
> is used for handling the initial stop.
> 
> So my first thought was, pretty much as you suggest, that we should
> fetch the target description earlier, then we'll not run into this
> problem at all.
> 

I don't think we should fetch the tdesc earlier, I think that would be incorrect.  Instead,
we should avoid reading registers while going through the shell.  The shell's registers have
nothing to do with the final program's registers.  The shell may even be of a different
architecture from the final inferior's architecture.  Like, if your shell is a 64-bit
bash, and then the inferior you're going to debug, which the shell execs, is a 32-bit program.

> My problem was figuring out the right place to add such a call.
> 
> We know it has to be before we enter regcache_read_pc, as at this point
> the regcache is already created, and has the wrong architecture.
> 
> And it can't really be earlier than linux_nat_filter_event I think, as
> before this point we don't know that the target has stopped.  We can't
> probe the target for features (I would assume) if the target is not
> currently stopped.
> 
> This seems to leave either save_stop_reason, or in the early stages of
> get_thread_regcache maybe.
> 
> The problem with save_stop_reason is that it's Linux specific, so any
> non-Linux targets will need to add their own code to catch this
> situation.

I think we should change save_stop_reason.  But, change it to avoid reading
the PC instead.

I don't think that the fact that other targets need to handle this too
is an issue.

>> It kind of sounds like if GDB detected the incompatibility when we first fetch the
>> target description, similarly to how we detect it in the cases above, and GDB picked
>> the target arch or errored out after detecting the incompatibility, then we wouldn't
>> need a patch like yours?
> 
> I agree.  One other aspect is, do we have any native targets that don't
> support reading a target description?  Hopefully not.

If we do, we have an action plan -- add such support.  I think a tdesc can be just an
<architecture> element, for instance.

> 
>>                          How come the mismatch isn't detected then (when we first
>> retrieve the target description) today?
> 
> Hopefully the above makes that clear, but the TLDR answer is: we attempt
> to read the registers using the current architecture before we fetch the
> target description.
> 
> I suspected that, in part, this patch would be a bit of a straw-man, I'd
> appreciate any insight you have for how we might reorder things so that
> the target description can be read before we try to read the registers.
> 

So I gave the patch below a try, and it seems to works well -- readcache_read_pc
is no longer called before target_find_description, and I saw no testsuite
regressions (this is without your series, just pristine master).

Now, this patch as is makes sense for linux-nat.c, but then I went to do the
same thing for gdbserver, which has an equivalent save_stop_reason in linux-low.cc,
and there this approach won't work as is for the simple fact that lwp->stop_pc
is used in a lot more places.

So to avoid gdb vs gdbserver divergence, it may be better to not take this patch
as is, but instead tweak save_stop_reason to avoid reading the stop pc while
the inferior is going through the shell, based on some per-inferior flag or some
such.  Maybe we can repurpose progspace->executing_startup for this?  That
flag used to be used by Cell (which is gone), but seems unused nowadays.  There's
also other similar flags in inferior itself, like needs_setup, and
in_initial_library_scan.  So we'd add a flag like one of those, set it while the
inferior is going through the startup_inferior dance, and make save_stop_reason avoid
reading the PC while that flag is set.

Note the patch below applies on top of:

  [PATCH] gdb+gdbserver/Linux: Remove USE_SIGTRAP_SIGINFO fallback
  https://sourceware.org/pipermail/gdb-patches/2022-June/190372.html

Attaching will need some other fix, because in that case, the procedure is that the core
requests an attach, and then the target reports an initial stop, and that stop
makes infrun read the thread's PC, before setup_inferior is called.  It may be
we need to call setup_inferior earlier.  Or maybe we can just add a target_find_description
call in linux_nat_target::attach, like remote.c does:

 void
 extended_remote_target::attach (const char *args, int from_tty)
 {
 ...
   /* Next, if the target can specify a description, read it.  We do
      this before anything involving memory or registers.  */
   target_find_description ();

I haven't looked at that in much detail, and I have to leave for tonight.

From 303d216239ba45c8930bd4291b9f49aae105ada7 Mon Sep 17 00:00:00 2001
From: Pedro Alves <pedro@palves.net>
Date: Mon, 27 Jun 2022 20:41:50 +0100
Subject: [PATCH] gdb/Linux: avoid reading registers while going through shell

For every stop, linux-nat.c saves the stopped thread's PC, in
lwp->stop_pc.  This is done in save_stop_reason.  However, while we're
going through the shell after "run", in startup_inferior, we shouldn't
be reading registers, as the shell's architecture may not even be the
same as the final inferior's.

Since lwp->stop_pc is only needed when the thread has stopped for a
breakpoint, and since when going through the shell, no breakpoint is
going to hit, we can simple teach save_stop_reason to only record the
stop pc when the thread stopped for a breakpoint.

Change-Id: If0f01831514d3a74d17efd102875de7d2c6401ad
---
 gdb/linux-nat.c | 38 ++++++++++++++++++++------------------
 1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 008791c12dc..27437da7c94 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -2514,24 +2514,20 @@ select_event_lwp_callback (struct lwp_info *lp, int *selector)
 static void
 save_stop_reason (struct lwp_info *lp)
 {
-  struct regcache *regcache;
-  struct gdbarch *gdbarch;
-  CORE_ADDR pc;
-  CORE_ADDR sw_bp_pc;
-  siginfo_t siginfo;
-
   gdb_assert (lp->stop_reason == TARGET_STOPPED_BY_NO_REASON);
   gdb_assert (lp->status != 0);
 
   if (!linux_target->low_status_is_event (lp->status))
     return;
 
-  regcache = get_thread_regcache (linux_target, lp->ptid);
-  gdbarch = regcache->arch ();
-
-  pc = regcache_read_pc (regcache);
-  sw_bp_pc = pc - gdbarch_decr_pc_after_break (gdbarch);
+  /* Note we avoid reading this until we know we have a sw/hw
+     breakpoint stop, which are the cases we actually need it, see
+     status_callback.  This is to avoid reading registers while we're
+     going through the shell, before we're able to determine the
+     debuggee's target description.  */
+  lp->stop_pc = 0;
 
+  siginfo_t siginfo;
   if (linux_nat_get_siginfo (lp->ptid, &siginfo))
     {
       if (siginfo.si_signo == SIGTRAP)
@@ -2580,25 +2576,31 @@ save_stop_reason (struct lwp_info *lp)
       linux_nat_debug_printf ("%s stopped by software breakpoint",
 			      lp->ptid.to_string ().c_str ());
 
-      /* Back up the PC if necessary.  */
-      if (pc != sw_bp_pc)
-	regcache_write_pc (regcache, sw_bp_pc);
+      struct regcache *regcache = get_thread_regcache (linux_target, lp->ptid);
+
+      lp->stop_pc = regcache_read_pc (regcache);
 
-      /* Update this so we record the correct stop PC below.  */
-      pc = sw_bp_pc;
+      /* Back up the PC if necessary.  */
+      CORE_ADDR decr_pc = gdbarch_decr_pc_after_break (regcache->arch ());
+      if (decr_pc != 0)
+	{
+	  lp->stop_pc -= decr_pc;
+	  regcache_write_pc (regcache, lp->stop_pc);
+	}
     }
   else if (lp->stop_reason == TARGET_STOPPED_BY_HW_BREAKPOINT)
     {
       linux_nat_debug_printf ("%s stopped by hardware breakpoint",
 			      lp->ptid.to_string ().c_str ());
+
+      struct regcache *regcache = get_thread_regcache (linux_target, lp->ptid);
+      lp->stop_pc = regcache_read_pc (regcache);
     }
   else if (lp->stop_reason == TARGET_STOPPED_BY_WATCHPOINT)
     {
       linux_nat_debug_printf ("%s stopped by hardware watchpoint",
 			      lp->ptid.to_string ().c_str ());
     }
-
-  lp->stop_pc = pc;
 }
 
 

base-commit: f18acc9c4e5d18f4783f3a7d59e3ec95d7af0199
prerequisite-patch-id: 9656309f5c298727d3cf993bed0bb8e00c9e9d56
-- 
2.36.0


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCHv3 6/6] gdb: native target invalid architecture detection
  2022-06-27 21:38           ` Pedro Alves
@ 2022-06-28 10:37             ` Andrew Burgess
  2022-06-28 12:42               ` [PATCH v2] gdb+gdbserver/Linux: avoid reading registers while going through shell (was: Re: [PATCHv3 6/6] gdb: native target invalid architecture detection) Pedro Alves
  2022-06-30  9:33             ` [PATCHv3 6/6] gdb: native target invalid architecture detection Andrew Burgess
  1 sibling, 1 reply; 83+ messages in thread
From: Andrew Burgess @ 2022-06-28 10:37 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches

Pedro Alves <pedro@palves.net> writes:

> On 2022-06-27 17:27, Andrew Burgess wrote:
>> Pedro Alves <pedro@palves.net> writes:
>>> On 2022-06-13 17:15, Andrew Burgess via Gdb-patches wrote:
>>> I have another question.  I'm confused on how if e.g., on x86-64, you
>>> load a RISC-V binary into GDB, and the try to run it, we don't end up
>>> with architecture of the target description instead.
>> 
>> The problem is that we end up trying to read the registers before we
>> read the target description.  Which I suspect you will say sounds wrong,
>> and I agree.
>> 
>> I removed the error() calls from this patch, and reran GDB, here's the
>> stack at the point of failure:
>> 
>
> ...
>
>>   #11 0x0000000000bf43c4 in regcache_read_pc (regcache=0x30f5f10) at ../../src/gdb/regcache.c:1325
>>   #12 0x00000000009c2e19 in save_stop_reason (lp=0x3a8ff80) at ../../src/gdb/linux-nat.c:2545
>>   #13 0x00000000009c40f0 in linux_nat_filter_event (lwpid=3990223, status=1407) at ../../src/gdb/linux-nat.c:3003
>>   #14 0x00000000009c471a in linux_nat_wait_1 (ptid=..., ourstatus=0x7fffffffa4f0, target_options=...)
>>       at ../../src/gdb/linux-nat.c:3178
>>   #15 0x00000000009c535a in linux_nat_target::wait (this=0x2d27140 <the_amd64_linux_nat_target>, ptid=..., 
>>       ourstatus=0x7fffffffa4f0, target_options=...) at ../../src/gdb/linux-nat.c:3416
>>   #16 0x0000000000dc5f3b in target_wait (ptid=..., status=0x7fffffffa4f0, options=...)
>>       at ../../src/gdb/target.c:2601
>>   #17 0x0000000000abd3c4 in startup_inferior (proc_target=0x2d27140 <the_amd64_linux_nat_target>, pid=3990223, 
>>       ntraps=1, last_waitstatus=0x0, last_ptid=0x0) at ../../src/gdb/nat/fork-inferior.c:482
>
> Alright, we're inside startup_inferior.
>
>> 
>> The initial architecture is riscv:rv32, and it is this architecture that
>> is used for handling the initial stop.
>> 
>> So my first thought was, pretty much as you suggest, that we should
>> fetch the target description earlier, then we'll not run into this
>> problem at all.
>> 
>
> I don't think we should fetch the tdesc earlier, I think that would be incorrect.  Instead,
> we should avoid reading registers while going through the shell.  The shell's registers have
> nothing to do with the final program's registers.  The shell may even be of a different
> architecture from the final inferior's architecture.  Like, if your shell is a 64-bit
> bash, and then the inferior you're going to debug, which the shell execs, is a 32-bit program.
>
>> My problem was figuring out the right place to add such a call.
>> 
>> We know it has to be before we enter regcache_read_pc, as at this point
>> the regcache is already created, and has the wrong architecture.
>> 
>> And it can't really be earlier than linux_nat_filter_event I think, as
>> before this point we don't know that the target has stopped.  We can't
>> probe the target for features (I would assume) if the target is not
>> currently stopped.
>> 
>> This seems to leave either save_stop_reason, or in the early stages of
>> get_thread_regcache maybe.
>> 
>> The problem with save_stop_reason is that it's Linux specific, so any
>> non-Linux targets will need to add their own code to catch this
>> situation.
>
> I think we should change save_stop_reason.  But, change it to avoid reading
> the PC instead.
>
> I don't think that the fact that other targets need to handle this too
> is an issue.
>
>>> It kind of sounds like if GDB detected the incompatibility when we first fetch the
>>> target description, similarly to how we detect it in the cases above, and GDB picked
>>> the target arch or errored out after detecting the incompatibility, then we wouldn't
>>> need a patch like yours?
>> 
>> I agree.  One other aspect is, do we have any native targets that don't
>> support reading a target description?  Hopefully not.
>
> If we do, we have an action plan -- add such support.  I think a tdesc can be just an
> <architecture> element, for instance.
>
>> 
>>>                          How come the mismatch isn't detected then (when we first
>>> retrieve the target description) today?
>> 
>> Hopefully the above makes that clear, but the TLDR answer is: we attempt
>> to read the registers using the current architecture before we fetch the
>> target description.
>> 
>> I suspected that, in part, this patch would be a bit of a straw-man, I'd
>> appreciate any insight you have for how we might reorder things so that
>> the target description can be read before we try to read the registers.
>> 
>
> So I gave the patch below a try, and it seems to works well -- readcache_read_pc
> is no longer called before target_find_description, and I saw no testsuite
> regressions (this is without your series, just pristine master).
>
> Now, this patch as is makes sense for linux-nat.c, but then I went to do the
> same thing for gdbserver, which has an equivalent save_stop_reason in linux-low.cc,
> and there this approach won't work as is for the simple fact that lwp->stop_pc
> is used in a lot more places.
>
> So to avoid gdb vs gdbserver divergence, it may be better to not take this patch
> as is, but instead tweak save_stop_reason to avoid reading the stop pc while
> the inferior is going through the shell, based on some per-inferior flag or some
> such.  Maybe we can repurpose progspace->executing_startup for this?  That
> flag used to be used by Cell (which is gone), but seems unused nowadays.  There's
> also other similar flags in inferior itself, like needs_setup, and
> in_initial_library_scan.  So we'd add a flag like one of those, set it while the
> inferior is going through the startup_inferior dance, and make save_stop_reason avoid
> reading the PC while that flag is set.
>
> Note the patch below applies on top of:
>
>   [PATCH] gdb+gdbserver/Linux: Remove USE_SIGTRAP_SIGINFO fallback
>   https://sourceware.org/pipermail/gdb-patches/2022-June/190372.html
>
> Attaching will need some other fix, because in that case, the procedure is that the core
> requests an attach, and then the target reports an initial stop, and that stop
> makes infrun read the thread's PC, before setup_inferior is called.  It may be
> we need to call setup_inferior earlier.  Or maybe we can just add a target_find_description
> call in linux_nat_target::attach, like remote.c does:
>
>  void
>  extended_remote_target::attach (const char *args, int from_tty)
>  {
>  ...
>    /* Next, if the target can specify a description, read it.  We do
>       this before anything involving memory or registers.  */
>    target_find_description ();
>
> I haven't looked at that in much detail, and I have to leave for tonight.
>
> From 303d216239ba45c8930bd4291b9f49aae105ada7 Mon Sep 17 00:00:00 2001
> From: Pedro Alves <pedro@palves.net>
> Date: Mon, 27 Jun 2022 20:41:50 +0100
> Subject: [PATCH] gdb/Linux: avoid reading registers while going through shell
>
> For every stop, linux-nat.c saves the stopped thread's PC, in
> lwp->stop_pc.  This is done in save_stop_reason.  However, while we're
> going through the shell after "run", in startup_inferior, we shouldn't
> be reading registers, as the shell's architecture may not even be the
> same as the final inferior's.
>
> Since lwp->stop_pc is only needed when the thread has stopped for a
> breakpoint, and since when going through the shell, no breakpoint is
> going to hit, we can simple teach save_stop_reason to only record the
> stop pc when the thread stopped for a breakpoint.

Thanks, this looks good.  Maybe you should go ahead and merge this, and
the attach problem can be solved separately.

Thanks,
Andrew


>
> Change-Id: If0f01831514d3a74d17efd102875de7d2c6401ad
> ---
>  gdb/linux-nat.c | 38 ++++++++++++++++++++------------------
>  1 file changed, 20 insertions(+), 18 deletions(-)
>
> diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
> index 008791c12dc..27437da7c94 100644
> --- a/gdb/linux-nat.c
> +++ b/gdb/linux-nat.c
> @@ -2514,24 +2514,20 @@ select_event_lwp_callback (struct lwp_info *lp, int *selector)
>  static void
>  save_stop_reason (struct lwp_info *lp)
>  {
> -  struct regcache *regcache;
> -  struct gdbarch *gdbarch;
> -  CORE_ADDR pc;
> -  CORE_ADDR sw_bp_pc;
> -  siginfo_t siginfo;
> -
>    gdb_assert (lp->stop_reason == TARGET_STOPPED_BY_NO_REASON);
>    gdb_assert (lp->status != 0);
>  
>    if (!linux_target->low_status_is_event (lp->status))
>      return;
>  
> -  regcache = get_thread_regcache (linux_target, lp->ptid);
> -  gdbarch = regcache->arch ();
> -
> -  pc = regcache_read_pc (regcache);
> -  sw_bp_pc = pc - gdbarch_decr_pc_after_break (gdbarch);
> +  /* Note we avoid reading this until we know we have a sw/hw
> +     breakpoint stop, which are the cases we actually need it, see
> +     status_callback.  This is to avoid reading registers while we're
> +     going through the shell, before we're able to determine the
> +     debuggee's target description.  */
> +  lp->stop_pc = 0;
>  
> +  siginfo_t siginfo;
>    if (linux_nat_get_siginfo (lp->ptid, &siginfo))
>      {
>        if (siginfo.si_signo == SIGTRAP)
> @@ -2580,25 +2576,31 @@ save_stop_reason (struct lwp_info *lp)
>        linux_nat_debug_printf ("%s stopped by software breakpoint",
>  			      lp->ptid.to_string ().c_str ());
>  
> -      /* Back up the PC if necessary.  */
> -      if (pc != sw_bp_pc)
> -	regcache_write_pc (regcache, sw_bp_pc);
> +      struct regcache *regcache = get_thread_regcache (linux_target, lp->ptid);
> +
> +      lp->stop_pc = regcache_read_pc (regcache);
>  
> -      /* Update this so we record the correct stop PC below.  */
> -      pc = sw_bp_pc;
> +      /* Back up the PC if necessary.  */
> +      CORE_ADDR decr_pc = gdbarch_decr_pc_after_break (regcache->arch ());
> +      if (decr_pc != 0)
> +	{
> +	  lp->stop_pc -= decr_pc;
> +	  regcache_write_pc (regcache, lp->stop_pc);
> +	}
>      }
>    else if (lp->stop_reason == TARGET_STOPPED_BY_HW_BREAKPOINT)
>      {
>        linux_nat_debug_printf ("%s stopped by hardware breakpoint",
>  			      lp->ptid.to_string ().c_str ());
> +
> +      struct regcache *regcache = get_thread_regcache (linux_target, lp->ptid);
> +      lp->stop_pc = regcache_read_pc (regcache);
>      }
>    else if (lp->stop_reason == TARGET_STOPPED_BY_WATCHPOINT)
>      {
>        linux_nat_debug_printf ("%s stopped by hardware watchpoint",
>  			      lp->ptid.to_string ().c_str ());
>      }
> -
> -  lp->stop_pc = pc;
>  }
>  
>  
>
> base-commit: f18acc9c4e5d18f4783f3a7d59e3ec95d7af0199
> prerequisite-patch-id: 9656309f5c298727d3cf993bed0bb8e00c9e9d56
> -- 
> 2.36.0


^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCH v2] gdb+gdbserver/Linux: avoid reading registers while going through shell (was: Re: [PATCHv3 6/6] gdb: native target invalid architecture detection)
  2022-06-28 10:37             ` Andrew Burgess
@ 2022-06-28 12:42               ` Pedro Alves
  2022-06-28 14:21                 ` Andrew Burgess
  2022-06-29 15:17                 ` Simon Marchi
  0 siblings, 2 replies; 83+ messages in thread
From: Pedro Alves @ 2022-06-28 12:42 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

On 2022-06-28 11:37, Andrew Burgess wrote:
> Pedro Alves <pedro@palves.net> writes:
> 
>> On 2022-06-27 17:27, Andrew Burgess wrote:
>>> Pedro Alves <pedro@palves.net> writes:
>> So I gave the patch below a try, and it seems to works well -- readcache_read_pc
>> is no longer called before target_find_description, and I saw no testsuite
>> regressions (this is without your series, just pristine master).
>>
>> Now, this patch as is makes sense for linux-nat.c, but then I went to do the
>> same thing for gdbserver, which has an equivalent save_stop_reason in linux-low.cc,
>> and there this approach won't work as is for the simple fact that lwp->stop_pc
>> is used in a lot more places.
>>
>> So to avoid gdb vs gdbserver divergence, it may be better to not take this patch
>> as is, but instead tweak save_stop_reason to avoid reading the stop pc while
>> the inferior is going through the shell, based on some per-inferior flag or some
>> such.  Maybe we can repurpose progspace->executing_startup for this?  That
>> flag used to be used by Cell (which is gone), but seems unused nowadays.  There's
>> also other similar flags in inferior itself, like needs_setup, and
>> in_initial_library_scan.  So we'd add a flag like one of those, set it while the
>> inferior is going through the startup_inferior dance, and make save_stop_reason avoid
>> reading the PC while that flag is set.

...

> 
> Thanks, this looks good.  Maybe you should go ahead and merge this, and
> the attach problem can be solved separately.

There's the gdb vs gdbserver divergence issue I pointed out above, though.

I was thinking we'd instead fix it with the alternative patch below, which
works for both gdb and gdbserver.

Tested with no regressions on x86-64 Ubuntu 20.04, native and gdbserver.

WDYT?

From 1b7b50e7c8359553af8b8858a82f09d5389d4a1b Mon Sep 17 00:00:00 2001
From: Pedro Alves <pedro@palves.net>
Date: Mon, 27 Jun 2022 20:41:50 +0100
Subject: [PATCH] gdb+gdbserver/Linux: avoid reading registers while going
 through shell

For every stop, linux-nat.c saves the stopped thread's PC, in
lwp->stop_pc.  This is done in save_stop_reason, in both
gdb/linux-nat.c and gdbserver/linux-low.cc.  However, while we're
going through the shell after "run", in startup_inferior, we shouldn't
be reading registers, as we haven't yet determined the target's
architecture -- the shell's architecture may not even be the same as
the final inferior's.

In linux-nat.c, lwp->stop_pc is only needed when the thread has
stopped for a breakpoint, and since when going through the shell, no
breakpoint is going to hit, we could simply teach save_stop_reason to
only record the stop pc when the thread stopped for a breakpoint.

However, in gdbserver/linux-low.cc, lwp->stop_pc is used in more cases
than breakpoint hits (e.g., it's used in tracepoints & the
"while-stepping" feature).

So to avoid GDB vs GDBserver divergence, we apply the same approach to
both implementations.

We set a flag in the inferior (process in gdbserver) whenever it is
being nursed through the shell, and when that flag is set,
save_stop_reason bails out early.  While going through the shell,
we'll only ever get process exits (normal or signalled), and exec
events, so nothing is lost.

Change-Id: If0f01831514d3a74d17efd102875de7d2c6401ad
---
 gdb/fork-child.c        |  3 +++
 gdb/inferior.h          |  7 +++++++
 gdb/linux-nat.c         |  4 ++++
 gdbserver/fork-child.cc |  5 +++++
 gdbserver/inferiors.h   |  7 +++++++
 gdbserver/linux-low.cc  | 16 ++++++++++++----
 6 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/gdb/fork-child.c b/gdb/fork-child.c
index 89003fa617d..66b523e118d 100644
--- a/gdb/fork-child.c
+++ b/gdb/fork-child.c
@@ -126,6 +126,9 @@ gdb_startup_inferior (pid_t pid, int num_traps)
   inferior *inf = current_inferior ();
   process_stratum_target *proc_target = inf->process_target ();
 
+  scoped_restore save_starting_up
+    = make_scoped_restore (&inf->starting_up, true);
+
   ptid_t ptid = startup_inferior (proc_target, pid, num_traps, NULL, NULL);
 
   /* Mark all threads non-executing.  */
diff --git a/gdb/inferior.h b/gdb/inferior.h
index f6e26a32feb..c376d780de0 100644
--- a/gdb/inferior.h
+++ b/gdb/inferior.h
@@ -551,6 +551,13 @@ class inferior : public refcounted_object,
      architecture/description.  */
   bool needs_setup = false;
 
+  /* True if the inferior is starting up (inside startup_inferior),
+     and we're nursing it along (through the shell) until it is ready
+     to execute its first instruction.  Until that is done, we must
+     not access inferior memory or registers, as we haven't determined
+     the target architecture/description.  */
+  bool starting_up = false;
+
   /* True when we are reading the library list of the inferior during an
      attach or handling a fork child.  */
   bool in_initial_library_scan = false;
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 008791c12dc..9ae02dfc093 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -2523,6 +2523,10 @@ save_stop_reason (struct lwp_info *lp)
   gdb_assert (lp->stop_reason == TARGET_STOPPED_BY_NO_REASON);
   gdb_assert (lp->status != 0);
 
+  inferior *inf = find_inferior_ptid (linux_target, lp->ptid);
+  if (inf->starting_up)
+    return;
+
   if (!linux_target->low_status_is_event (lp->status))
     return;
 
diff --git a/gdbserver/fork-child.cc b/gdbserver/fork-child.cc
index 96dd4d009ab..7ea66f2a435 100644
--- a/gdbserver/fork-child.cc
+++ b/gdbserver/fork-child.cc
@@ -18,6 +18,7 @@
 
 #include "server.h"
 #include "gdbsupport/job-control.h"
+#include "gdbsupport/scoped_restore.h"
 #include "nat/fork-inferior.h"
 #ifdef HAVE_SIGNAL_H
 #include <signal.h>
@@ -103,6 +104,10 @@ post_fork_inferior (int pid, const char *program)
   atexit (restore_old_foreground_pgrp);
 #endif
 
+  process_info *proc = find_process_pid (pid);
+  scoped_restore save_starting_up
+    = make_scoped_restore (&proc->starting_up, true);
+
   startup_inferior (the_target, pid,
 		    START_INFERIOR_TRAPS_EXPECTED,
 		    &cs.last_status, &cs.last_ptid);
diff --git a/gdbserver/inferiors.h b/gdbserver/inferiors.h
index f3ba4d82f71..6de746cb228 100644
--- a/gdbserver/inferiors.h
+++ b/gdbserver/inferiors.h
@@ -75,6 +75,13 @@ struct process_info
 
   /* Flag to mark that the DLL list has changed.  */
   bool dlls_changed = false;
+
+  /* True if the inferior is starting up (inside startup_inferior),
+     and we're nursing it along (through the shell) until it is ready
+     to execute its first instruction.  Until that is done, we must
+     not access inferior memory or registers, as we haven't determined
+     the target architecture/description.  */
+  bool starting_up = false;
 };
 
 /* Get the pid of PROC.  */
diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc
index 9305928bbbf..547e56f6448 100644
--- a/gdbserver/linux-low.cc
+++ b/gdbserver/linux-low.cc
@@ -747,8 +747,8 @@ linux_process_target::handle_extended_wait (lwp_info **orig_event_lwp,
 CORE_ADDR
 linux_process_target::get_pc (lwp_info *lwp)
 {
-  struct regcache *regcache;
-  CORE_ADDR pc;
+  process_info *proc = get_thread_process (get_lwp_thread (lwp));
+  gdb_assert (!proc->starting_up);
 
   if (!low_supports_breakpoints ())
     return 0;
@@ -756,8 +756,8 @@ linux_process_target::get_pc (lwp_info *lwp)
   scoped_restore_current_thread restore_thread;
   switch_to_thread (get_lwp_thread (lwp));
 
-  regcache = get_thread_regcache (current_thread, 1);
-  pc = low_get_pc (regcache);
+  struct regcache *regcache = get_thread_regcache (current_thread, 1);
+  CORE_ADDR pc = low_get_pc (regcache);
 
   threads_debug_printf ("pc is 0x%lx", (long) pc);
 
@@ -795,6 +795,14 @@ linux_process_target::save_stop_reason (lwp_info *lwp)
   if (!low_supports_breakpoints ())
     return false;
 
+  process_info *proc = get_thread_process (get_lwp_thread (lwp));
+  if (proc->starting_up)
+    {
+      /* Claim we have the stop PC so that the caller doesn't try to
+	 fetch it itself.  */
+      return true;
+    }
+
   pc = get_pc (lwp);
   sw_breakpoint_pc = pc - low_decr_pc_after_break ();
 

base-commit: dbcbf67ca565ec29f13a2302dcdf9b01ef7832ca
prerequisite-patch-id: 9656309f5c298727d3cf993bed0bb8e00c9e9d56
-- 
2.36.0


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v2] gdb+gdbserver/Linux: avoid reading registers while going through shell (was: Re: [PATCHv3 6/6] gdb: native target invalid architecture detection)
  2022-06-28 12:42               ` [PATCH v2] gdb+gdbserver/Linux: avoid reading registers while going through shell (was: Re: [PATCHv3 6/6] gdb: native target invalid architecture detection) Pedro Alves
@ 2022-06-28 14:21                 ` Andrew Burgess
  2022-06-29 15:17                 ` Simon Marchi
  1 sibling, 0 replies; 83+ messages in thread
From: Andrew Burgess @ 2022-06-28 14:21 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches

Pedro Alves <pedro@palves.net> writes:

> On 2022-06-28 11:37, Andrew Burgess wrote:
>> Pedro Alves <pedro@palves.net> writes:
>> 
>>> On 2022-06-27 17:27, Andrew Burgess wrote:
>>>> Pedro Alves <pedro@palves.net> writes:
>>> So I gave the patch below a try, and it seems to works well -- readcache_read_pc
>>> is no longer called before target_find_description, and I saw no testsuite
>>> regressions (this is without your series, just pristine master).
>>>
>>> Now, this patch as is makes sense for linux-nat.c, but then I went to do the
>>> same thing for gdbserver, which has an equivalent save_stop_reason in linux-low.cc,
>>> and there this approach won't work as is for the simple fact that lwp->stop_pc
>>> is used in a lot more places.
>>>
>>> So to avoid gdb vs gdbserver divergence, it may be better to not take this patch
>>> as is, but instead tweak save_stop_reason to avoid reading the stop pc while
>>> the inferior is going through the shell, based on some per-inferior flag or some
>>> such.  Maybe we can repurpose progspace->executing_startup for this?  That
>>> flag used to be used by Cell (which is gone), but seems unused nowadays.  There's
>>> also other similar flags in inferior itself, like needs_setup, and
>>> in_initial_library_scan.  So we'd add a flag like one of those, set it while the
>>> inferior is going through the startup_inferior dance, and make save_stop_reason avoid
>>> reading the PC while that flag is set.
>
> ...
>
>> 
>> Thanks, this looks good.  Maybe you should go ahead and merge this, and
>> the attach problem can be solved separately.
>
> There's the gdb vs gdbserver divergence issue I pointed out above, though.
>
> I was thinking we'd instead fix it with the alternative patch below, which
> works for both gdb and gdbserver.
>
> Tested with no regressions on x86-64 Ubuntu 20.04, native and gdbserver.
>
> WDYT?
>
> From 1b7b50e7c8359553af8b8858a82f09d5389d4a1b Mon Sep 17 00:00:00 2001
> From: Pedro Alves <pedro@palves.net>
> Date: Mon, 27 Jun 2022 20:41:50 +0100
> Subject: [PATCH] gdb+gdbserver/Linux: avoid reading registers while going
>  through shell
>
> For every stop, linux-nat.c saves the stopped thread's PC, in
> lwp->stop_pc.  This is done in save_stop_reason, in both
> gdb/linux-nat.c and gdbserver/linux-low.cc.  However, while we're
> going through the shell after "run", in startup_inferior, we shouldn't
> be reading registers, as we haven't yet determined the target's
> architecture -- the shell's architecture may not even be the same as
> the final inferior's.
>
> In linux-nat.c, lwp->stop_pc is only needed when the thread has
> stopped for a breakpoint, and since when going through the shell, no
> breakpoint is going to hit, we could simply teach save_stop_reason to
> only record the stop pc when the thread stopped for a breakpoint.
>
> However, in gdbserver/linux-low.cc, lwp->stop_pc is used in more cases
> than breakpoint hits (e.g., it's used in tracepoints & the
> "while-stepping" feature).
>
> So to avoid GDB vs GDBserver divergence, we apply the same approach to
> both implementations.
>
> We set a flag in the inferior (process in gdbserver) whenever it is
> being nursed through the shell, and when that flag is set,
> save_stop_reason bails out early.  While going through the shell,
> we'll only ever get process exits (normal or signalled), and exec
> events, so nothing is lost.

LGTM.

Thanks,
Andrew


>
> Change-Id: If0f01831514d3a74d17efd102875de7d2c6401ad
> ---
>  gdb/fork-child.c        |  3 +++
>  gdb/inferior.h          |  7 +++++++
>  gdb/linux-nat.c         |  4 ++++
>  gdbserver/fork-child.cc |  5 +++++
>  gdbserver/inferiors.h   |  7 +++++++
>  gdbserver/linux-low.cc  | 16 ++++++++++++----
>  6 files changed, 38 insertions(+), 4 deletions(-)
>
> diff --git a/gdb/fork-child.c b/gdb/fork-child.c
> index 89003fa617d..66b523e118d 100644
> --- a/gdb/fork-child.c
> +++ b/gdb/fork-child.c
> @@ -126,6 +126,9 @@ gdb_startup_inferior (pid_t pid, int num_traps)
>    inferior *inf = current_inferior ();
>    process_stratum_target *proc_target = inf->process_target ();
>  
> +  scoped_restore save_starting_up
> +    = make_scoped_restore (&inf->starting_up, true);
> +
>    ptid_t ptid = startup_inferior (proc_target, pid, num_traps, NULL, NULL);
>  
>    /* Mark all threads non-executing.  */
> diff --git a/gdb/inferior.h b/gdb/inferior.h
> index f6e26a32feb..c376d780de0 100644
> --- a/gdb/inferior.h
> +++ b/gdb/inferior.h
> @@ -551,6 +551,13 @@ class inferior : public refcounted_object,
>       architecture/description.  */
>    bool needs_setup = false;
>  
> +  /* True if the inferior is starting up (inside startup_inferior),
> +     and we're nursing it along (through the shell) until it is ready
> +     to execute its first instruction.  Until that is done, we must
> +     not access inferior memory or registers, as we haven't determined
> +     the target architecture/description.  */
> +  bool starting_up = false;
> +
>    /* True when we are reading the library list of the inferior during an
>       attach or handling a fork child.  */
>    bool in_initial_library_scan = false;
> diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
> index 008791c12dc..9ae02dfc093 100644
> --- a/gdb/linux-nat.c
> +++ b/gdb/linux-nat.c
> @@ -2523,6 +2523,10 @@ save_stop_reason (struct lwp_info *lp)
>    gdb_assert (lp->stop_reason == TARGET_STOPPED_BY_NO_REASON);
>    gdb_assert (lp->status != 0);
>  
> +  inferior *inf = find_inferior_ptid (linux_target, lp->ptid);
> +  if (inf->starting_up)
> +    return;
> +
>    if (!linux_target->low_status_is_event (lp->status))
>      return;
>  
> diff --git a/gdbserver/fork-child.cc b/gdbserver/fork-child.cc
> index 96dd4d009ab..7ea66f2a435 100644
> --- a/gdbserver/fork-child.cc
> +++ b/gdbserver/fork-child.cc
> @@ -18,6 +18,7 @@
>  
>  #include "server.h"
>  #include "gdbsupport/job-control.h"
> +#include "gdbsupport/scoped_restore.h"
>  #include "nat/fork-inferior.h"
>  #ifdef HAVE_SIGNAL_H
>  #include <signal.h>
> @@ -103,6 +104,10 @@ post_fork_inferior (int pid, const char *program)
>    atexit (restore_old_foreground_pgrp);
>  #endif
>  
> +  process_info *proc = find_process_pid (pid);
> +  scoped_restore save_starting_up
> +    = make_scoped_restore (&proc->starting_up, true);
> +
>    startup_inferior (the_target, pid,
>  		    START_INFERIOR_TRAPS_EXPECTED,
>  		    &cs.last_status, &cs.last_ptid);
> diff --git a/gdbserver/inferiors.h b/gdbserver/inferiors.h
> index f3ba4d82f71..6de746cb228 100644
> --- a/gdbserver/inferiors.h
> +++ b/gdbserver/inferiors.h
> @@ -75,6 +75,13 @@ struct process_info
>  
>    /* Flag to mark that the DLL list has changed.  */
>    bool dlls_changed = false;
> +
> +  /* True if the inferior is starting up (inside startup_inferior),
> +     and we're nursing it along (through the shell) until it is ready
> +     to execute its first instruction.  Until that is done, we must
> +     not access inferior memory or registers, as we haven't determined
> +     the target architecture/description.  */
> +  bool starting_up = false;
>  };
>  
>  /* Get the pid of PROC.  */
> diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc
> index 9305928bbbf..547e56f6448 100644
> --- a/gdbserver/linux-low.cc
> +++ b/gdbserver/linux-low.cc
> @@ -747,8 +747,8 @@ linux_process_target::handle_extended_wait (lwp_info **orig_event_lwp,
>  CORE_ADDR
>  linux_process_target::get_pc (lwp_info *lwp)
>  {
> -  struct regcache *regcache;
> -  CORE_ADDR pc;
> +  process_info *proc = get_thread_process (get_lwp_thread (lwp));
> +  gdb_assert (!proc->starting_up);
>  
>    if (!low_supports_breakpoints ())
>      return 0;
> @@ -756,8 +756,8 @@ linux_process_target::get_pc (lwp_info *lwp)
>    scoped_restore_current_thread restore_thread;
>    switch_to_thread (get_lwp_thread (lwp));
>  
> -  regcache = get_thread_regcache (current_thread, 1);
> -  pc = low_get_pc (regcache);
> +  struct regcache *regcache = get_thread_regcache (current_thread, 1);
> +  CORE_ADDR pc = low_get_pc (regcache);
>  
>    threads_debug_printf ("pc is 0x%lx", (long) pc);
>  
> @@ -795,6 +795,14 @@ linux_process_target::save_stop_reason (lwp_info *lwp)
>    if (!low_supports_breakpoints ())
>      return false;
>  
> +  process_info *proc = get_thread_process (get_lwp_thread (lwp));
> +  if (proc->starting_up)
> +    {
> +      /* Claim we have the stop PC so that the caller doesn't try to
> +	 fetch it itself.  */
> +      return true;
> +    }
> +
>    pc = get_pc (lwp);
>    sw_breakpoint_pc = pc - low_decr_pc_after_break ();
>  
>
> base-commit: dbcbf67ca565ec29f13a2302dcdf9b01ef7832ca
> prerequisite-patch-id: 9656309f5c298727d3cf993bed0bb8e00c9e9d56
> -- 
> 2.36.0


^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCHv4 0/6] Detect invalid casts of gdbarch_tdep structures
  2022-06-13 16:15   ` [PATCHv3 0/6] Handle trying to use a native target with the wrong binary Andrew Burgess
                       ` (6 preceding siblings ...)
  2022-06-24 10:15     ` [PATCHv3 0/6] Handle trying to use a native target with the wrong binary Andrew Burgess
@ 2022-06-28 14:28     ` Andrew Burgess
  2022-06-28 14:28       ` [PATCHv4 1/6] gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope Andrew Burgess
                         ` (6 more replies)
  7 siblings, 7 replies; 83+ messages in thread
From: Andrew Burgess @ 2022-06-28 14:28 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

Changes since v3:

 - Title of series has changed as the last patch, relating to
   detection of incorrect architecture with a native target, have been
   dropped.

 - Patches #1 and #2 are unchanged,

 - Patch #3 has had minor updates based on feedback from Luis and Pedro,

 - Patch #4 is unchanged,

 - Patch #5 is new, based on Pedro's feedback,

 - Patch #6 has been updated to make use of the work added in patch
   #5.

Changes since v2:

 - Patch #3 has been replaced after feedback from Luis.  New patch
   fixes sider issues for arm, mips, and frv targets, this includes
   the issue the v2 patch fixed.

 - Nothing else has changed.

Changes since v1:

 - Patches #1 and #2 are unchanged.

 - Patch #3 is new in this version.

 - Patch #4 is unchanged (was patch 3).

 - Patch #5 is updated inline with John's feedback (was patch 4).

 - Patch #6 is extended to handle multi-arch case for rs6000/ppc and
   arm/aarch64, commit message is updated to discuss these cases, as
   well as mentioning i386/x86-64 (was patch 5).

---

Andrew Burgess (6):
  gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope
  gdb/mips: rewrite show_mask_address
  gdb: select suitable thread for gdbarch_adjust_breakpoint_address
  gdb: move the type cast into gdbarch_tdep
  gdbsupport: add checked_static_cast
  gdb: ensure the cast in gdbarch_tdep is valid

 gdb/aarch64-fbsd-nat.c               |   4 +-
 gdb/aarch64-fbsd-tdep.c              |   6 +-
 gdb/aarch64-linux-nat.c              |  20 ++--
 gdb/aarch64-linux-tdep.c             |  10 +-
 gdb/aarch64-newlib-tdep.c            |   2 +-
 gdb/aarch64-tdep.c                   |  48 ++++-----
 gdb/aix-thread.c                     |  28 +++---
 gdb/alpha-linux-tdep.c               |   2 +-
 gdb/alpha-netbsd-tdep.c              |   2 +-
 gdb/alpha-obsd-tdep.c                |   2 +-
 gdb/alpha-tdep.c                     |  14 +--
 gdb/amd64-darwin-tdep.c              |   2 +-
 gdb/amd64-fbsd-nat.c                 |   4 +-
 gdb/amd64-fbsd-tdep.c                |   4 +-
 gdb/amd64-linux-tdep.c               |   8 +-
 gdb/amd64-netbsd-tdep.c              |   2 +-
 gdb/amd64-obsd-tdep.c                |   2 +-
 gdb/amd64-sol2-tdep.c                |   2 +-
 gdb/amd64-tdep.c                     |  34 +++----
 gdb/amd64-windows-tdep.c             |   2 +-
 gdb/arc-linux-tdep.c                 |   4 +-
 gdb/arc-newlib-tdep.c                |   2 +-
 gdb/arc-tdep.c                       |   8 +-
 gdb/arch-utils.c                     |   6 +-
 gdb/arm-fbsd-nat.c                   |   4 +-
 gdb/arm-fbsd-tdep.c                  |   6 +-
 gdb/arm-linux-nat.c                  |   8 +-
 gdb/arm-linux-tdep.c                 |   4 +-
 gdb/arm-netbsd-nat.c                 |   8 +-
 gdb/arm-netbsd-tdep.c                |   4 +-
 gdb/arm-none-tdep.c                  |   2 +-
 gdb/arm-obsd-tdep.c                  |   2 +-
 gdb/arm-tdep.c                       | 142 ++++++++++++++-------------
 gdb/arm-wince-tdep.c                 |   2 +-
 gdb/avr-tdep.c                       |  12 +--
 gdb/bfin-tdep.c                      |   4 +-
 gdb/breakpoint.c                     |  27 +++--
 gdb/cris-linux-tdep.c                |   2 +-
 gdb/cris-tdep.c                      |  18 ++--
 gdb/csky-tdep.c                      |   8 +-
 gdb/frv-tdep.c                       |   4 +-
 gdb/ft32-tdep.c                      |   2 +-
 gdb/gdbarch.h                        |  27 ++++-
 gdb/hppa-bsd-tdep.c                  |   2 +-
 gdb/hppa-linux-tdep.c                |   4 +-
 gdb/hppa-tdep.c                      |  12 +--
 gdb/i386-bsd-tdep.c                  |   2 +-
 gdb/i386-darwin-tdep.c               |   4 +-
 gdb/i386-fbsd-tdep.c                 |   4 +-
 gdb/i386-gnu-tdep.c                  |   2 +-
 gdb/i386-go32-tdep.c                 |   2 +-
 gdb/i386-linux-tdep.c                |   4 +-
 gdb/i386-netbsd-tdep.c               |   4 +-
 gdb/i386-nto-tdep.c                  |   6 +-
 gdb/i386-obsd-tdep.c                 |   2 +-
 gdb/i386-sol2-tdep.c                 |   2 +-
 gdb/i386-tdep.c                      |  98 +++++++++---------
 gdb/i386-windows-tdep.c              |   2 +-
 gdb/i387-tdep.c                      |  20 ++--
 gdb/ia64-linux-tdep.c                |   2 +-
 gdb/ia64-tdep.c                      |  12 +--
 gdb/loongarch-linux-tdep.c           |   2 +-
 gdb/loongarch-tdep.c                 |   4 +-
 gdb/m32c-tdep.c                      |  58 +++++------
 gdb/m68hc11-tdep.c                   |  12 +--
 gdb/m68k-bsd-tdep.c                  |   2 +-
 gdb/m68k-linux-tdep.c                |   2 +-
 gdb/m68k-tdep.c                      |  38 +++----
 gdb/mep-tdep.c                       |   6 +-
 gdb/mips-linux-tdep.c                |   4 +-
 gdb/mips-tdep.c                      |  85 ++++++++--------
 gdb/mn10300-tdep.c                   |   2 +-
 gdb/mn10300-tdep.h                   |   2 +-
 gdb/msp430-tdep.c                    |  12 +--
 gdb/nds32-tdep.c                     |  20 ++--
 gdb/nios2-linux-tdep.c               |   2 +-
 gdb/nios2-tdep.c                     |   4 +-
 gdb/or1k-tdep.c                      |   8 +-
 gdb/ppc-fbsd-nat.c                   |   4 +-
 gdb/ppc-fbsd-tdep.c                  |   8 +-
 gdb/ppc-linux-nat.c                  |  22 ++---
 gdb/ppc-linux-tdep.c                 |  18 ++--
 gdb/ppc-netbsd-nat.c                 |   6 +-
 gdb/ppc-netbsd-tdep.c                |   2 +-
 gdb/ppc-obsd-nat.c                   |   4 +-
 gdb/ppc-obsd-tdep.c                  |   2 +-
 gdb/ppc-sysv-tdep.c                  |  22 ++---
 gdb/ppc64-tdep.c                     |   2 +-
 gdb/riscv-linux-tdep.c               |   2 +-
 gdb/riscv-tdep.c                     |  26 ++---
 gdb/rl78-tdep.c                      |   8 +-
 gdb/rs6000-aix-nat.c                 |   6 +-
 gdb/rs6000-aix-tdep.c                |  16 +--
 gdb/rs6000-lynx178-tdep.c            |   4 +-
 gdb/rs6000-tdep.c                    | 132 ++++++++++++-------------
 gdb/rx-tdep.c                        |   2 +-
 gdb/s390-linux-tdep.c                |  20 ++--
 gdb/s390-tdep.c                      |  42 ++++----
 gdb/sh-linux-tdep.c                  |   2 +-
 gdb/sh-netbsd-tdep.c                 |   2 +-
 gdb/sh-tdep.c                        |   8 +-
 gdb/sparc-linux-tdep.c               |   4 +-
 gdb/sparc-netbsd-tdep.c              |   2 +-
 gdb/sparc-sol2-tdep.c                |   2 +-
 gdb/sparc-tdep.c                     |  14 +--
 gdb/sparc64-fbsd-tdep.c              |   2 +-
 gdb/sparc64-linux-tdep.c             |   4 +-
 gdb/sparc64-netbsd-tdep.c            |   2 +-
 gdb/sparc64-obsd-tdep.c              |   2 +-
 gdb/sparc64-sol2-tdep.c              |   2 +-
 gdb/sparc64-tdep.c                   |  10 +-
 gdb/tic6x-linux-tdep.c               |   6 +-
 gdb/tic6x-tdep.c                     |   6 +-
 gdb/v850-tdep.c                      |   6 +-
 gdb/windows-nat.c                    |   2 +-
 gdb/xtensa-linux-nat.c               |   4 +-
 gdb/xtensa-linux-tdep.c              |   2 +-
 gdb/xtensa-tdep.c                    |  54 +++++-----
 gdb/z80-tdep.c                       |   8 +-
 gdbsupport/gdb-checked-static-cast.h |  68 +++++++++++++
 120 files changed, 811 insertions(+), 700 deletions(-)
 create mode 100644 gdbsupport/gdb-checked-static-cast.h

-- 
2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCHv4 1/6] gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope
  2022-06-28 14:28     ` [PATCHv4 0/6] Detect invalid casts of gdbarch_tdep structures Andrew Burgess
@ 2022-06-28 14:28       ` Andrew Burgess
  2022-06-28 14:28       ` [PATCHv4 2/6] gdb/mips: rewrite show_mask_address Andrew Burgess
                         ` (5 subsequent siblings)
  6 siblings, 0 replies; 83+ messages in thread
From: Andrew Burgess @ 2022-06-28 14:28 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

This is a small refactor to resolve an issue before it becomes a
problem in a later commit.

Move the fetching of an arm_gdbarch_tdep into a more inner scope
within two functions in arm-tdep.c.

The problem with the current code is that the functions in question
are used as the callbacks for two set/show parameters.  These set/show
parameters are available no matter the current architecture, but are
really about controlling an ARM architecture specific setting.  And
so, if I build GDB for all targets on an x86-64/GNU-Linux system, I
can still do this:

  (gdb) show arm fpu
  (gdb) show arm abi

After these calls we end up in show_fp_model and arm_show_abi
respectively, where we unconditionally do this:

  arm_gdbarch_tdep *tdep
    = (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());

However, the gdbarch_tdep() result will only be a arm_gdbarch_tdep if
the current architecture is ARM, otherwise the result will actually be
of some other type.

This isn't actually a problem, as in both cases the use of tdep is
guarded by a later check that the gdbarch architecture is
bfd_arch_arm.

This commit just moves the call to gdbarch_tdep() after the
architecture check.

In a later commit gdbarch_tdep() will be able to spot when we are
casting the result to the wrong type, and this function will trigger
assertion failures if things are not fixed.

There should be not user visible changes after this commit.
---
 gdb/arm-tdep.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index e36bde9b3da..86d870048cf 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -9158,14 +9158,16 @@ static void
 show_fp_model (struct ui_file *file, int from_tty,
 	       struct cmd_list_element *c, const char *value)
 {
-  arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
-
   if (arm_fp_model == ARM_FLOAT_AUTO
       && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm)
-    gdb_printf (file, _("\
+    {
+      arm_gdbarch_tdep *tdep
+	= (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+
+      gdb_printf (file, _("\
 The current ARM floating point model is \"auto\" (currently \"%s\").\n"),
-		fp_model_strings[tdep->fp_model]);
+		  fp_model_strings[tdep->fp_model]);
+    }
   else
     gdb_printf (file, _("\
 The current ARM floating point model is \"%s\".\n"),
@@ -9196,14 +9198,16 @@ static void
 arm_show_abi (struct ui_file *file, int from_tty,
 	     struct cmd_list_element *c, const char *value)
 {
-  arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
-
   if (arm_abi_global == ARM_ABI_AUTO
       && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm)
-    gdb_printf (file, _("\
+    {
+      arm_gdbarch_tdep *tdep
+	= (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+
+      gdb_printf (file, _("\
 The current ARM ABI is \"auto\" (currently \"%s\").\n"),
-		arm_abi_strings[tdep->arm_abi]);
+		  arm_abi_strings[tdep->arm_abi]);
+    }
   else
     gdb_printf (file, _("The current ARM ABI is \"%s\".\n"),
 		arm_abi_string);
-- 
2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCHv4 2/6] gdb/mips: rewrite show_mask_address
  2022-06-28 14:28     ` [PATCHv4 0/6] Detect invalid casts of gdbarch_tdep structures Andrew Burgess
  2022-06-28 14:28       ` [PATCHv4 1/6] gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope Andrew Burgess
@ 2022-06-28 14:28       ` Andrew Burgess
  2022-06-28 14:28       ` [PATCHv4 3/6] gdb: select suitable thread for gdbarch_adjust_breakpoint_address Andrew Burgess
                         ` (4 subsequent siblings)
  6 siblings, 0 replies; 83+ messages in thread
From: Andrew Burgess @ 2022-06-28 14:28 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

This commit is similar to the previous commit, but in this case GDB is
actually relying on undefined behaviour.

Consider building GDB for all targets on x86-64/GNU-Linux, then doing
this:

  (gdb) show mips mask-address
  Zeroing of upper 32 bits of 64-bit addresses is auto.
  The 32 bit address mask is set automatically.  Currently disabled
  (gdb)

The 'show mips mask-address' command ends up in show_mask_address in
mips-tdep.c, and this function does this:

  mips_gdbarch_tdep *tdep
    = (mips_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());

Later we might pass TDEP to mips_mask_address_p.  However, in my
example above, on an x86-64 native target, the current target
architecture will be an x86-64 gdbarch, and the tdep field within the
gdbarch will be of type i386_gdbarch_tdep, not of type
mips_gdbarch_tdep, as a result the cast above was incorrect, and TDEP
is not pointing at what it thinks it is.

I also think the current output is a little confusing, we appear to
have two lines that show the same information, but using different
words.

The first line comes from calling deprecated_show_value_hack, while
the second line is printed directly from show_mask_address.  However,
both of these lines are printing the same mask_address_var value.  I
don't think the two lines actually adds any value here.

Finally, none of the text in this function is passed through the
internationalisation mechanism.

It would be nice to remove another use of deprecated_show_value_hack
if possible, so this commit does a complete rewrite of
show_mask_address.

After this commit the output of the above example command, still on my
x86-64 native target is:

    (gdb) show mips mask-address
    Zeroing of upper 32 bits of 64-bit addresses is "auto" (current architecture is not MIPS).

The 'current architecture is not MIPS' text is only displayed when the
current architecture is not MIPS.  If the architecture is mips then we
get the more commonly seen 'currently "on"' or 'currently "off"', like
this:

  (gdb) set architecture mips
  The target architecture is set to "mips".
  (gdb) show mips mask-address
  Zeroing of upper 32 bits of 64-bit addresses is "auto" (currently "off").
  (gdb)

All the text is passed through the internationalisation mechanism, and
we only call gdbarch_tdep when we know the gdbarch architecture is
bfd_arch_mips.
---
 gdb/mips-tdep.c | 37 +++++++++++++++++--------------------
 1 file changed, 17 insertions(+), 20 deletions(-)

diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index 65aa86dd98d..071319ccc73 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -1183,28 +1183,25 @@ static void
 show_mask_address (struct ui_file *file, int from_tty,
 		   struct cmd_list_element *c, const char *value)
 {
-  mips_gdbarch_tdep *tdep
-    = (mips_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
-
-  deprecated_show_value_hack (file, from_tty, c, value);
-  switch (mask_address_var)
+  const char *additional_text = "";
+  if (mask_address_var == AUTO_BOOLEAN_AUTO)
     {
-    case AUTO_BOOLEAN_TRUE:
-      gdb_printf (file, "The 32 bit mips address mask is enabled\n");
-      break;
-    case AUTO_BOOLEAN_FALSE:
-      gdb_printf (file, "The 32 bit mips address mask is disabled\n");
-      break;
-    case AUTO_BOOLEAN_AUTO:
-      gdb_printf
-	(file,
-	 "The 32 bit address mask is set automatically.  Currently %s\n",
-	 mips_mask_address_p (tdep) ? "enabled" : "disabled");
-      break;
-    default:
-      internal_error (__FILE__, __LINE__, _("show_mask_address: bad switch"));
-      break;
+      if (gdbarch_bfd_arch_info (target_gdbarch ())->arch != bfd_arch_mips)
+	additional_text = _(" (current architecture is not MIPS)");
+      else
+	{
+	  mips_gdbarch_tdep *tdep
+	    = (mips_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+
+	  if (mips_mask_address_p (tdep))
+	    additional_text = _(" (currently \"on\")");
+	  else
+	    additional_text = _(" (currently \"off\")");
+	}
     }
+
+  gdb_printf (file, _("Zeroing of upper 32 bits of 64-bit addresses is \"%s\"%s.\n"),
+	      value, additional_text);
 }
 
 /* Tell if the program counter value in MEMADDR is in a standard ISA
-- 
2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCHv4 3/6] gdb: select suitable thread for gdbarch_adjust_breakpoint_address
  2022-06-28 14:28     ` [PATCHv4 0/6] Detect invalid casts of gdbarch_tdep structures Andrew Burgess
  2022-06-28 14:28       ` [PATCHv4 1/6] gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope Andrew Burgess
  2022-06-28 14:28       ` [PATCHv4 2/6] gdb/mips: rewrite show_mask_address Andrew Burgess
@ 2022-06-28 14:28       ` Andrew Burgess
  2022-06-28 14:28       ` [PATCHv4 4/6] gdb: move the type cast into gdbarch_tdep Andrew Burgess
                         ` (3 subsequent siblings)
  6 siblings, 0 replies; 83+ messages in thread
From: Andrew Burgess @ 2022-06-28 14:28 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

The three targets that implement gdbarch_adjust_breakpoint_address are
arm, frv, and mips.  In each of these targets the adjust breakpoint
address function does some combination of reading the symbol table, or
reading memory at the location the breakpoint could be placed.

The problem is that performing these actions requires that the current
inferior and program space be the one in which the breakpoint will be
placed, and this is not currently always the case.

Consider a GDB session with multiple inferiors.  One inferior might be
a native target while another could be a remote target of a completely
different architecture.  Alternatively, if we consider ARM and
AArch64, one native inferior might be AArch64, while a second native
inferior could be ARM.

In these cases it is possible, and valid, for a user to have one
inferior selected, and place a breakpoint in the other inferior by
placing a breakpoint on a particular symbol.

If this happens, then currently, when
gdbarch_adjust_breakpoint_address is called, the wrong inferior (and
program space) will be selected, and memory reads, and symbol look
ups, will not return the expected results, this could lead to
breakpoints being placed in the wrong location.

There are currently two places where gdbarch_adjust_breakpoint_address
is called:

  1. In infrun.c, in the function handle_step_into_function.  In this
  case, I believe that the correct inferior and program space will
  already be selected as this is called as part of the stop event
  handling, so I don't think we need to worry about this case, and

  2. In breakpoint.c, in the function adjust_breakpoint_address, which
  is itself called from code_breakpoint::add_location and
  watch_command_1.

  The watch_command_1 case I don't think we need to worry about, this
  is for when a local watch expression is created, which can only be
  in the currently selected inferior, so this case should be fine.

  The code_breakpoint::add_location case is the one that needs fixing,
  this is what allows a breakpoint to be created between inferiors.

To fix the code_breakpoint::add_location case, I propose that we pass
the "correct" program_space (i.e. the program space in which the
breakpoint will be created) to the adjust_breakpoint_address function.
Then in adjust_breakpoint_address we can make use of
switch_to_program_space_and_thread to switch program_space and
inferior before calling gdbarch_adjust_breakpoint_address.

I discovered this issue while working on a later patch in this
series.  This later patch will detect when we cast the result of
gdbarch_tdep to the wrong type.

With this later patch in place I ran gdb.multi/multi-arch.exp on an
AArch64 target.  In this situation, two inferiors are created, an
AArch64 inferior, and an ARM inferior.  The test selected the AArch64
inferior and tries to create a breakpoint in the ARM inferior.

As a result of this we end up in arm_adjust_breakpoint_address, which
calls arm_pc_is_thumb.  Before this commit the AArch64 inferior would
be current.  As a result, all of the checks in arm_pc_is_thumb would
fail (they rely on reading symbols from the current program space),
and so, at the end of arm_pc_is_thumb we would call
arm_frame_is_thumb.  However, remember, at this point the current
inferior is the AArch64 inferior, so the current frame is an AArch64
frame.

In arm_frame_is_thumb we call arm_psr_thumb_bit, which calls
gdbarch_tdep and casts the result to arm_gdbarch_tdep.  This is wrong,
the tdep field is of type aarch64_gdbarch_tdep.  After this we have
undefined behaviour.

With this patch in place, we will have switched to a thread in the ARM
program space before calling arm_adjust_breakpoint_address.  As a
result, we now succeed in looking up the required symbols in
arm_pc_is_thumb, and so we never call arm_frame_is_thumb.

However, in the worst case scenario, if we did end up calling
arm_frame_is_thumb, as the current inferior should now be the ARM
inferior, the current frame should be an ARM frame, so we still should
not hit undefined behaviour.

I have added an assert to arm_frame_is_thumb.
---
 gdb/arm-tdep.c   | 12 ++++++++----
 gdb/breakpoint.c | 27 ++++++++++++++++++++-------
 2 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 86d870048cf..994af630f34 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -577,20 +577,24 @@ arm_is_thumb (struct regcache *regcache)
   return (cpsr & t_bit) != 0;
 }
 
-/* Determine if FRAME is executing in Thumb mode.  */
+/* Determine if FRAME is executing in Thumb mode.  FRAME must be an ARM
+   frame.  */
 
 int
 arm_frame_is_thumb (struct frame_info *frame)
 {
-  CORE_ADDR cpsr;
-  ULONGEST t_bit = arm_psr_thumb_bit (get_frame_arch (frame));
+  /* Check the architecture of FRAME.  */
+  struct gdbarch *gdbarch = get_frame_arch (frame);
+  gdb_assert (gdbarch_bfd_arch_info (gdbarch)->arch == bfd_arch_arm);
 
   /* Every ARM frame unwinder can unwind the T bit of the CPSR, either
      directly (from a signal frame or dummy frame) or by interpreting
      the saved LR (from a prologue or DWARF frame).  So consult it and
      trust the unwinders.  */
-  cpsr = get_frame_register_unsigned (frame, ARM_PS_REGNUM);
+  CORE_ADDR cpsr = get_frame_register_unsigned (frame, ARM_PS_REGNUM);
 
+  /* Find and extract the thumb bit.  */
+  ULONGEST t_bit = arm_psr_thumb_bit (gdbarch);
   return (cpsr & t_bit) != 0;
 }
 
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index a3be12557f6..d11e87713f4 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -124,7 +124,8 @@ static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
 
 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch,
 					    CORE_ADDR bpaddr,
-					    enum bptype bptype);
+					    enum bptype bptype,
+					    struct program_space *pspace);
 
 static int watchpoint_locations_match (struct bp_location *loc1,
 				       struct bp_location *loc2);
@@ -7103,8 +7104,11 @@ breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
 
 static CORE_ADDR
 adjust_breakpoint_address (struct gdbarch *gdbarch,
-			   CORE_ADDR bpaddr, enum bptype bptype)
+			   CORE_ADDR bpaddr, enum bptype bptype,
+			   struct program_space *pspace)
 {
+  gdb_assert (pspace != nullptr);
+
   if (bptype == bp_watchpoint
       || bptype == bp_hardware_watchpoint
       || bptype == bp_read_watchpoint
@@ -7129,11 +7133,18 @@ adjust_breakpoint_address (struct gdbarch *gdbarch,
     {
       CORE_ADDR adjusted_bpaddr = bpaddr;
 
+      /* Some targets have architectural constraints on the placement
+	 of breakpoint instructions.  Obtain the adjusted address.  */
       if (gdbarch_adjust_breakpoint_address_p (gdbarch))
 	{
-	  /* Some targets have architectural constraints on the placement
-	     of breakpoint instructions.  Obtain the adjusted address.  */
-	  adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
+	  /* Targets that implement this adjustment function will likely
+	     inspect either the symbol table, target memory at BPADDR, or
+	     even state registers, so ensure a suitable thread (and its
+	     associated program space) are currently selected.  */
+	  scoped_restore_current_pspace_and_thread restore_pspace_thread;
+	  switch_to_program_space_and_thread (pspace);
+	  adjusted_bpaddr
+	    = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr);
 	}
 
       adjusted_bpaddr = address_significant (gdbarch, adjusted_bpaddr);
@@ -8087,7 +8098,8 @@ code_breakpoint::add_location (const symtab_and_line &sal)
      not want its scan of the location chain to find a breakpoint and
      location that's only been partially initialized.  */
   adjusted_address = adjust_breakpoint_address (loc_gdbarch,
-						sal.pc, type);
+						sal.pc, type,
+						sal.pspace);
 
   /* Sort the locations by their ADDRESS.  */
   new_loc = allocate_location ();
@@ -10077,7 +10089,8 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
 	  scope_breakpoint->loc->address
 	    = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch,
 					 scope_breakpoint->loc->requested_address,
-					 scope_breakpoint->type);
+					 scope_breakpoint->type,
+					 current_program_space);
 	}
     }
 
-- 
2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCHv4 4/6] gdb: move the type cast into gdbarch_tdep
  2022-06-28 14:28     ` [PATCHv4 0/6] Detect invalid casts of gdbarch_tdep structures Andrew Burgess
                         ` (2 preceding siblings ...)
  2022-06-28 14:28       ` [PATCHv4 3/6] gdb: select suitable thread for gdbarch_adjust_breakpoint_address Andrew Burgess
@ 2022-06-28 14:28       ` Andrew Burgess
  2022-06-28 14:28       ` [PATCHv4 5/6] gdbsupport: add checked_static_cast Andrew Burgess
                         ` (2 subsequent siblings)
  6 siblings, 0 replies; 83+ messages in thread
From: Andrew Burgess @ 2022-06-28 14:28 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

I built GDB for all targets on a x86-64/GNU-Linux system, and
then (accidentally) passed GDB a RISC-V binary, and asked GDB to "run"
the binary on the native target.  I got this error:

  (gdb) show architecture
  The target architecture is set to "auto" (currently "i386").
  (gdb) file /tmp/hello.rv32.exe
  Reading symbols from /tmp/hello.rv32.exe...
  (gdb) show architecture
  The target architecture is set to "auto" (currently "riscv:rv32").
  (gdb) run
  Starting program: /tmp/hello.rv32.exe
  ../../src/gdb/i387-tdep.c:596: internal-error: i387_supply_fxsave: Assertion `tdep->st0_regnum >= I386_ST0_REGNUM' failed.

What's going on here is this; initially the architecture is i386, this
is based on the default architecture, which is set based on the native
target.  After loading the RISC-V executable the architecture of the
current inferior is updated based on the architecture of the
executable.

When we "run", GDB does a fork & exec, with the inferior being
controlled through ptrace.  GDB sees an initial stop from the inferior
as soon as the inferior comes to life.  In response to this stop GDB
ends up calling save_stop_reason (linux-nat.c), which ends up trying
to read register from the inferior, to do this we end up calling
target_ops::fetch_registers, which, for the x86-64 native target,
calls amd64_linux_nat_target::fetch_registers.

After this I eventually end up in i387_supply_fxsave, different x86
based targets will end in different functions to fetch registers, but
it doesn't really matter which function we end up in, the problem is
this line, which is repeated in many places:

  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);

The problem here is that the ARCH in this line comes from the current
inferior, which, as we discussed above, will be a RISC-V gdbarch, the
tdep field will actually be of type riscv_gdbarch_tdep, not
i386_gdbarch_tdep.  After this cast we are relying on undefined
behaviour, in my case I happen to trigger an assert, but this might
not always be the case.

The thing I tried that exposed this problem was of course, trying to
start an executable of the wrong architecture on a native target.  I
don't think that the correct solution for this problem is to detect,
at the point of cast, that the gdbarch_tdep object is of the wrong
type, but, I did wonder, is there a way that we could protect
ourselves from incorrectly casting the gdbarch_tdep object?

I think that there is something we can do here, and this commit is the
first step in that direction, though no actual check is added by this
commit.

This commit can be split into two parts:

 (1) In gdbarch.h and arch-utils.c.  In these files I have modified
 gdbarch_tdep (the function) so that it now takes a template argument,
 like this:

    template<typename TDepType>
    static inline TDepType *
    gdbarch_tdep (struct gdbarch *gdbarch)
    {
      struct gdbarch_tdep *tdep = gdbarch_tdep_1 (gdbarch);
      return static_cast<TDepType *> (tdep);
    }

  After this change we are no better protected, but the cast is now
  done within the gdbarch_tdep function rather than at the call sites,
  this leads to the second, much larger change in this commit,

  (2) Everywhere gdbarch_tdep is called, we make changes like this:

    -  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
    +  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);

There should be no functional change after this commit.

In the next commit I will build on this change to add an assertion in
gdbarch_tdep that checks we are casting to the correct type.
---
 gdb/aarch64-fbsd-nat.c     |   4 +-
 gdb/aarch64-fbsd-tdep.c    |   6 +-
 gdb/aarch64-linux-nat.c    |  20 +++---
 gdb/aarch64-linux-tdep.c   |  10 +--
 gdb/aarch64-newlib-tdep.c  |   2 +-
 gdb/aarch64-tdep.c         |  48 +++++++-------
 gdb/aix-thread.c           |  28 ++++----
 gdb/alpha-linux-tdep.c     |   2 +-
 gdb/alpha-netbsd-tdep.c    |   2 +-
 gdb/alpha-obsd-tdep.c      |   2 +-
 gdb/alpha-tdep.c           |  14 ++--
 gdb/amd64-darwin-tdep.c    |   2 +-
 gdb/amd64-fbsd-nat.c       |   4 +-
 gdb/amd64-fbsd-tdep.c      |   4 +-
 gdb/amd64-linux-tdep.c     |   8 +--
 gdb/amd64-netbsd-tdep.c    |   2 +-
 gdb/amd64-obsd-tdep.c      |   2 +-
 gdb/amd64-sol2-tdep.c      |   2 +-
 gdb/amd64-tdep.c           |  34 +++++-----
 gdb/amd64-windows-tdep.c   |   2 +-
 gdb/arc-linux-tdep.c       |   4 +-
 gdb/arc-newlib-tdep.c      |   2 +-
 gdb/arc-tdep.c             |   8 +--
 gdb/arch-utils.c           |   6 +-
 gdb/arm-fbsd-nat.c         |   4 +-
 gdb/arm-fbsd-tdep.c        |   6 +-
 gdb/arm-linux-nat.c        |   8 +--
 gdb/arm-linux-tdep.c       |   4 +-
 gdb/arm-netbsd-nat.c       |   8 +--
 gdb/arm-netbsd-tdep.c      |   4 +-
 gdb/arm-none-tdep.c        |   2 +-
 gdb/arm-obsd-tdep.c        |   2 +-
 gdb/arm-tdep.c             | 110 +++++++++++++++----------------
 gdb/arm-wince-tdep.c       |   2 +-
 gdb/avr-tdep.c             |  12 ++--
 gdb/bfin-tdep.c            |   4 +-
 gdb/cris-linux-tdep.c      |   2 +-
 gdb/cris-tdep.c            |  18 ++---
 gdb/csky-tdep.c            |   8 +--
 gdb/frv-tdep.c             |   4 +-
 gdb/ft32-tdep.c            |   2 +-
 gdb/gdbarch.h              |  17 ++++-
 gdb/hppa-bsd-tdep.c        |   2 +-
 gdb/hppa-linux-tdep.c      |   4 +-
 gdb/hppa-tdep.c            |  12 ++--
 gdb/i386-bsd-tdep.c        |   2 +-
 gdb/i386-darwin-tdep.c     |   4 +-
 gdb/i386-fbsd-tdep.c       |   4 +-
 gdb/i386-gnu-tdep.c        |   2 +-
 gdb/i386-go32-tdep.c       |   2 +-
 gdb/i386-linux-tdep.c      |   4 +-
 gdb/i386-netbsd-tdep.c     |   4 +-
 gdb/i386-nto-tdep.c        |   6 +-
 gdb/i386-obsd-tdep.c       |   2 +-
 gdb/i386-sol2-tdep.c       |   2 +-
 gdb/i386-tdep.c            |  98 +++++++++++++--------------
 gdb/i386-windows-tdep.c    |   2 +-
 gdb/i387-tdep.c            |  20 +++---
 gdb/ia64-linux-tdep.c      |   2 +-
 gdb/ia64-tdep.c            |  12 ++--
 gdb/loongarch-linux-tdep.c |   2 +-
 gdb/loongarch-tdep.c       |   4 +-
 gdb/m32c-tdep.c            |  58 ++++++++--------
 gdb/m68hc11-tdep.c         |  12 ++--
 gdb/m68k-bsd-tdep.c        |   2 +-
 gdb/m68k-linux-tdep.c      |   2 +-
 gdb/m68k-tdep.c            |  38 +++++------
 gdb/mep-tdep.c             |   6 +-
 gdb/mips-linux-tdep.c      |   4 +-
 gdb/mips-tdep.c            |  50 +++++++-------
 gdb/mn10300-tdep.c         |   2 +-
 gdb/mn10300-tdep.h         |   2 +-
 gdb/msp430-tdep.c          |  12 ++--
 gdb/nds32-tdep.c           |  20 +++---
 gdb/nios2-linux-tdep.c     |   2 +-
 gdb/nios2-tdep.c           |   4 +-
 gdb/or1k-tdep.c            |   8 +--
 gdb/ppc-fbsd-nat.c         |   4 +-
 gdb/ppc-fbsd-tdep.c        |   8 +--
 gdb/ppc-linux-nat.c        |  22 +++----
 gdb/ppc-linux-tdep.c       |  18 ++---
 gdb/ppc-netbsd-nat.c       |   6 +-
 gdb/ppc-netbsd-tdep.c      |   2 +-
 gdb/ppc-obsd-nat.c         |   4 +-
 gdb/ppc-obsd-tdep.c        |   2 +-
 gdb/ppc-sysv-tdep.c        |  22 +++----
 gdb/ppc64-tdep.c           |   2 +-
 gdb/riscv-linux-tdep.c     |   2 +-
 gdb/riscv-tdep.c           |  26 ++++----
 gdb/rl78-tdep.c            |   8 +--
 gdb/rs6000-aix-nat.c       |   6 +-
 gdb/rs6000-aix-tdep.c      |  16 ++---
 gdb/rs6000-lynx178-tdep.c  |   4 +-
 gdb/rs6000-tdep.c          | 132 ++++++++++++++++++-------------------
 gdb/rx-tdep.c              |   2 +-
 gdb/s390-linux-tdep.c      |  20 +++---
 gdb/s390-tdep.c            |  42 ++++++------
 gdb/sh-linux-tdep.c        |   2 +-
 gdb/sh-netbsd-tdep.c       |   2 +-
 gdb/sh-tdep.c              |   8 +--
 gdb/sparc-linux-tdep.c     |   4 +-
 gdb/sparc-netbsd-tdep.c    |   2 +-
 gdb/sparc-sol2-tdep.c      |   2 +-
 gdb/sparc-tdep.c           |  14 ++--
 gdb/sparc64-fbsd-tdep.c    |   2 +-
 gdb/sparc64-linux-tdep.c   |   4 +-
 gdb/sparc64-netbsd-tdep.c  |   2 +-
 gdb/sparc64-obsd-tdep.c    |   2 +-
 gdb/sparc64-sol2-tdep.c    |   2 +-
 gdb/sparc64-tdep.c         |  10 +--
 gdb/tic6x-linux-tdep.c     |   6 +-
 gdb/tic6x-tdep.c           |   6 +-
 gdb/v850-tdep.c            |   6 +-
 gdb/windows-nat.c          |   2 +-
 gdb/xtensa-linux-nat.c     |   4 +-
 gdb/xtensa-linux-tdep.c    |   2 +-
 gdb/xtensa-tdep.c          |  54 +++++++--------
 gdb/z80-tdep.c             |   8 +--
 118 files changed, 678 insertions(+), 661 deletions(-)

diff --git a/gdb/aarch64-fbsd-nat.c b/gdb/aarch64-fbsd-nat.c
index d8cf6227e73..708ddc40d58 100644
--- a/gdb/aarch64-fbsd-nat.c
+++ b/gdb/aarch64-fbsd-nat.c
@@ -90,7 +90,7 @@ aarch64_fbsd_nat_target::fetch_registers (struct regcache *regcache,
 				    &aarch64_fbsd_fpregset);
 
   gdbarch *gdbarch = regcache->arch ();
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   if (tdep->has_tls ())
     {
       const struct regcache_map_entry aarch64_fbsd_tls_regmap[] =
@@ -123,7 +123,7 @@ aarch64_fbsd_nat_target::store_registers (struct regcache *regcache,
 				    PT_SETFPREGS, &aarch64_fbsd_fpregset);
 
   gdbarch *gdbarch = regcache->arch ();
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   if (tdep->has_tls ())
     {
       const struct regcache_map_entry aarch64_fbsd_tls_regmap[] =
diff --git a/gdb/aarch64-fbsd-tdep.c b/gdb/aarch64-fbsd-tdep.c
index 891546b3c64..4a6b4115234 100644
--- a/gdb/aarch64-fbsd-tdep.c
+++ b/gdb/aarch64-fbsd-tdep.c
@@ -143,7 +143,7 @@ aarch64_fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					   void *cb_data,
 					   const struct regcache *regcache)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   cb (".reg", AARCH64_FBSD_SIZEOF_GREGSET, AARCH64_FBSD_SIZEOF_GREGSET,
       &aarch64_fbsd_gregset, NULL, cb_data);
@@ -190,7 +190,7 @@ static CORE_ADDR
 aarch64_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 				       CORE_ADDR lm_addr, CORE_ADDR offset)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   struct regcache *regcache;
 
   regcache = get_thread_arch_regcache (current_inferior ()->process_target (),
@@ -213,7 +213,7 @@ aarch64_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 static void
 aarch64_fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support.  */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c
index d58ad0143a2..a457fcd48ad 100644
--- a/gdb/aarch64-linux-nat.c
+++ b/gdb/aarch64-linux-nat.c
@@ -359,7 +359,7 @@ static void
 fetch_pauth_masks_from_thread (struct regcache *regcache)
 {
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
   int ret;
   struct iovec iovec;
   uint64_t pauth_regset[2] = {0, 0};
@@ -385,7 +385,7 @@ static void
 fetch_mteregs_from_thread (struct regcache *regcache)
 {
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
   int regno = tdep->mte_reg_base;
 
   gdb_assert (regno != -1);
@@ -410,7 +410,7 @@ static void
 store_mteregs_to_thread (struct regcache *regcache)
 {
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
   int regno = tdep->mte_reg_base;
 
   gdb_assert (regno != -1);
@@ -439,7 +439,7 @@ static void
 fetch_tlsregs_from_thread (struct regcache *regcache)
 {
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
   int regno = tdep->tls_regnum;
 
   gdb_assert (regno != -1);
@@ -464,7 +464,7 @@ static void
 store_tlsregs_to_thread (struct regcache *regcache)
 {
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
   int regno = tdep->tls_regnum;
 
   gdb_assert (regno != -1);
@@ -493,7 +493,7 @@ static void
 aarch64_fetch_registers (struct regcache *regcache, int regno)
 {
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
 
   if (regno == -1)
     {
@@ -543,7 +543,7 @@ static void
 aarch32_fetch_registers (struct regcache *regcache, int regno)
 {
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
 
   if (regno == -1)
     {
@@ -579,7 +579,7 @@ static void
 aarch64_store_registers (struct regcache *regcache, int regno)
 {
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
 
   if (regno == -1)
     {
@@ -619,7 +619,7 @@ static void
 aarch32_store_registers (struct regcache *regcache, int regno)
 {
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
 
   if (regno == -1)
     {
@@ -893,7 +893,7 @@ aarch64_linux_nat_target::thread_architecture (ptid_t ptid)
 
   /* Only return it if the current vector length matches the one in the tdep.  */
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (inf->gdbarch);
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (inf->gdbarch);
   uint64_t vq = aarch64_sve_get_vq (ptid.lwp ());
   if (vq == tdep->vq)
     return inf->gdbarch;
diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c
index 453692df2f4..4c96662efb3 100644
--- a/gdb/aarch64-linux-tdep.c
+++ b/gdb/aarch64-linux-tdep.c
@@ -286,7 +286,7 @@ aarch64_linux_sigframe_init (const struct tramp_frame *self,
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   CORE_ADDR sp = get_frame_register_unsigned (this_frame, AARCH64_SP_REGNUM);
   CORE_ADDR sigcontext_addr = (sp + AARCH64_RT_SIGFRAME_UCONTEXT_OFFSET
 			       + AARCH64_UCONTEXT_SIGCONTEXT_OFFSET );
@@ -640,7 +640,7 @@ aarch64_linux_collect_sve_regset (const struct regset *regset,
   gdb_byte *header = (gdb_byte *) buf;
   struct gdbarch *gdbarch = regcache->arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   uint64_t vq = tdep->vq;
 
   gdb_assert (buf != NULL);
@@ -676,7 +676,7 @@ aarch64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					    void *cb_data,
 					    const struct regcache *regcache)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   cb (".reg", AARCH64_LINUX_SIZEOF_GREGSET, AARCH64_LINUX_SIZEOF_GREGSET,
       &aarch64_linux_gregset, NULL, cb_data);
@@ -1743,7 +1743,7 @@ aarch64_linux_report_signal_info (struct gdbarch *gdbarch,
 				  struct ui_out *uiout,
 				  enum gdb_signal siggnal)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (!tdep->has_mte () || siggnal != GDB_SIGNAL_SEGV)
     return;
@@ -1812,7 +1812,7 @@ aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 								    NULL };
   static const char *const stap_register_indirection_suffixes[] = { "]",
 								    NULL };
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   tdep->lowest_pc = 0x8000;
 
diff --git a/gdb/aarch64-newlib-tdep.c b/gdb/aarch64-newlib-tdep.c
index 507b7fc5a51..c9236b17801 100644
--- a/gdb/aarch64-newlib-tdep.c
+++ b/gdb/aarch64-newlib-tdep.c
@@ -29,7 +29,7 @@
 static void
 aarch64_newlib_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   /* Jump buffer - support for longjmp.
      Offset of original PC in jump buffer (in registers).  */
diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
index 15b577c8a00..8670197a888 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -502,7 +502,7 @@ aarch64_analyze_prologue (struct gdbarch *gdbarch,
       else if (inst.opcode->iclass == ic_system)
 	{
 	  aarch64_gdbarch_tdep *tdep
-	    = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	    = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 	  int ra_state_val = 0;
 
 	  if (insn == 0xd503233f /* paciasp.  */
@@ -640,7 +640,7 @@ aarch64_analyze_prologue_test (void)
   struct aarch64_prologue_cache cache;
   cache.saved_regs = trad_frame_alloc_saved_regs (gdbarch);
 
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   /* Test the simple prologue in which frame pointer is used.  */
   {
@@ -1076,7 +1076,7 @@ aarch64_prologue_frame_unwind_stop_reason (struct frame_info *this_frame,
 
   /* Halt the backtrace at "_start".  */
   gdbarch *arch = get_frame_arch (this_frame);
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (arch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (arch);
   if (cache->prev_pc <= tdep->lowest_pc)
     return UNWIND_OUTERMOST;
 
@@ -1120,7 +1120,7 @@ aarch64_prologue_prev_register (struct frame_info *this_frame,
       CORE_ADDR lr;
       struct gdbarch *gdbarch = get_frame_arch (this_frame);
       aarch64_gdbarch_tdep *tdep
-	= (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	= gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
       lr = frame_unwind_register_unsigned (this_frame, AARCH64_LR_REGNUM);
 
@@ -1289,7 +1289,7 @@ aarch64_dwarf2_prev_register (struct frame_info *this_frame,
 			      void **this_cache, int regnum)
 {
   gdbarch *arch = get_frame_arch (this_frame);
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (arch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (arch);
   CORE_ADDR lr;
 
   switch (regnum)
@@ -1315,7 +1315,7 @@ aarch64_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
 			       struct dwarf2_frame_state_reg *reg,
 			       struct frame_info *this_frame)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   switch (regnum)
     {
@@ -1355,7 +1355,7 @@ static bool
 aarch64_execute_dwarf_cfa_vendor_op (struct gdbarch *gdbarch, gdb_byte op,
 				     struct dwarf2_frame_state *fs)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   struct dwarf2_frame_state_reg *ra_state;
 
   if (op == DW_CFA_AARCH64_negate_ra_state)
@@ -1996,7 +1996,7 @@ aarch64_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
 static struct type *
 aarch64_vnq_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vnq_type == NULL)
     {
@@ -2023,7 +2023,7 @@ aarch64_vnq_type (struct gdbarch *gdbarch)
 static struct type *
 aarch64_vnd_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vnd_type == NULL)
     {
@@ -2053,7 +2053,7 @@ aarch64_vnd_type (struct gdbarch *gdbarch)
 static struct type *
 aarch64_vns_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vns_type == NULL)
     {
@@ -2083,7 +2083,7 @@ aarch64_vns_type (struct gdbarch *gdbarch)
 static struct type *
 aarch64_vnh_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vnh_type == NULL)
     {
@@ -2116,7 +2116,7 @@ aarch64_vnh_type (struct gdbarch *gdbarch)
 static struct type *
 aarch64_vnb_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vnb_type == NULL)
     {
@@ -2143,7 +2143,7 @@ aarch64_vnb_type (struct gdbarch *gdbarch)
 static struct type *
 aarch64_vnv_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vnv_type == NULL)
     {
@@ -2214,7 +2214,7 @@ aarch64_vnv_type (struct gdbarch *gdbarch)
 static int
 aarch64_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (reg >= AARCH64_DWARF_X0 && reg <= AARCH64_DWARF_X0 + 30)
     return AARCH64_X0_REGNUM + reg - AARCH64_DWARF_X0;
@@ -2518,7 +2518,7 @@ aarch64_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
   CORE_ADDR jb_addr;
   gdb_byte buf[X_REGISTER_SIZE];
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   jb_addr = get_frame_register_unsigned (frame, AARCH64_X0_REGNUM);
@@ -2549,7 +2549,7 @@ aarch64_gen_return_address (struct gdbarch *gdbarch,
 static const char *
 aarch64_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   static const char *const q_name[] =
     {
@@ -2663,7 +2663,7 @@ aarch64_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 static struct type *
 aarch64_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   int p_regnum = regnum - gdbarch_num_regs (gdbarch);
 
@@ -2700,7 +2700,7 @@ static int
 aarch64_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 				    const struct reggroup *group)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   int p_regnum = regnum - gdbarch_num_regs (gdbarch);
 
@@ -2754,7 +2754,7 @@ static struct value *
 aarch64_pseudo_read_value (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int regnum)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   struct value *result_value = allocate_value (register_type (gdbarch, regnum));
 
   VALUE_LVAL (result_value) = lval_register;
@@ -2824,7 +2824,7 @@ static void
 aarch64_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache,
 		      int regnum, const gdb_byte *buf)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
   regnum -= gdbarch_num_regs (gdbarch);
 
   if (regnum >= AARCH64_Q0_REGNUM && regnum < AARCH64_Q0_REGNUM + 32)
@@ -3377,7 +3377,7 @@ aarch64_get_tdesc_vq (const struct target_desc *tdesc)
 static int
 aarch64_cannot_store_register (struct gdbarch *gdbarch, int regnum)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (!tdep->has_pauth ())
     return 0;
@@ -3444,7 +3444,7 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
     {
       aarch64_gdbarch_tdep *tdep
-	= (aarch64_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
+	= gdbarch_tdep<aarch64_gdbarch_tdep> (best_arch->gdbarch);
       if (tdep && tdep->vq == vq)
 	return best_arch->gdbarch;
     }
@@ -3693,7 +3693,7 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 aarch64_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep == NULL)
     return;
@@ -3915,7 +3915,7 @@ aarch64_record_branch_except_sys (aarch64_insn_decode_record *aarch64_insn_r)
 {
 
   aarch64_gdbarch_tdep *tdep
-    = (aarch64_gdbarch_tdep *) gdbarch_tdep (aarch64_insn_r->gdbarch);
+    = gdbarch_tdep<aarch64_gdbarch_tdep> (aarch64_insn_r->gdbarch);
   uint8_t insn_bits24_27, insn_bits28_31, insn_bits22_23;
   uint32_t record_buf[4];
 
diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c
index ecd8200b692..3d76b8c6d01 100644
--- a/gdb/aix-thread.c
+++ b/gdb/aix-thread.c
@@ -1114,7 +1114,7 @@ static void
 supply_gprs64 (struct regcache *regcache, uint64_t *vals)
 {
   ppc_gdbarch_tdep *tdep
-    = (ppc_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<ppc_gdbarch_tdep> (regcache->arch ());
   int regno;
 
   for (regno = 0; regno < ppc_num_gprs; regno++)
@@ -1136,7 +1136,7 @@ static void
 supply_fprs (struct regcache *regcache, double *vals)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int regno;
 
   /* This function should never be called on architectures without
@@ -1154,7 +1154,7 @@ supply_fprs (struct regcache *regcache, double *vals)
 static int
 special_register_p (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   return regno == gdbarch_pc_regnum (gdbarch)
       || regno == tdep->ppc_ps_regnum
@@ -1177,7 +1177,7 @@ supply_sprs64 (struct regcache *regcache,
 	       uint32_t fpscr)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   regcache->raw_supply (gdbarch_pc_regnum (gdbarch), (char *) &iar);
   regcache->raw_supply (tdep->ppc_ps_regnum, (char *) &msr);
@@ -1199,7 +1199,7 @@ supply_sprs32 (struct regcache *regcache,
 	       uint32_t fpscr)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   regcache->raw_supply (gdbarch_pc_regnum (gdbarch), (char *) &iar);
   regcache->raw_supply (tdep->ppc_ps_regnum, (char *) &msr);
@@ -1222,7 +1222,7 @@ static void
 fetch_regs_user_thread (struct regcache *regcache, pthdb_pthread_t pdtid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int status, i;
   pthdb_context_t ctx;
 
@@ -1277,7 +1277,7 @@ fetch_regs_kernel_thread (struct regcache *regcache, int regno,
 			  pthdb_tid_t tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   uint64_t gprs64[ppc_num_gprs];
   uint32_t gprs32[ppc_num_gprs];
   double fprs[ppc_num_fprs];
@@ -1380,7 +1380,7 @@ static void
 fill_gprs64 (const struct regcache *regcache, uint64_t *vals)
 {
   ppc_gdbarch_tdep *tdep
-    = (ppc_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<ppc_gdbarch_tdep> (regcache->arch ());
   int regno;
 
   for (regno = 0; regno < ppc_num_gprs; regno++)
@@ -1393,7 +1393,7 @@ static void
 fill_gprs32 (const struct regcache *regcache, uint32_t *vals)
 {
   ppc_gdbarch_tdep *tdep
-    = (ppc_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+    = gdbarch_tdep<ppc_gdbarch_tdep> (regcache->arch ());
   int regno;
 
   for (regno = 0; regno < ppc_num_gprs; regno++)
@@ -1407,7 +1407,7 @@ static void
 fill_fprs (const struct regcache *regcache, double *vals)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int regno;
 
   /* This function should never be called on architectures without
@@ -1431,7 +1431,7 @@ fill_sprs64 (const struct regcache *regcache,
 	     uint32_t *fpscr)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* Verify that the size of the size of the IAR buffer is the
      same as the raw size of the PC (in the register cache).  If
@@ -1465,7 +1465,7 @@ fill_sprs32 (const struct regcache *regcache,
 	     uint32_t *fpscr)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* Verify that the size of the size of the IAR buffer is the
      same as the raw size of the PC (in the register cache).  If
@@ -1502,7 +1502,7 @@ static void
 store_regs_user_thread (const struct regcache *regcache, pthdb_pthread_t pdtid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int status, i;
   pthdb_context_t ctx;
   uint32_t int32;
@@ -1592,7 +1592,7 @@ store_regs_kernel_thread (const struct regcache *regcache, int regno,
 			  pthdb_tid_t tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   uint64_t gprs64[ppc_num_gprs];
   uint32_t gprs32[ppc_num_gprs];
   double fprs[ppc_num_fprs];
diff --git a/gdb/alpha-linux-tdep.c b/gdb/alpha-linux-tdep.c
index 6cea40d3f34..c103aafc1ff 100644
--- a/gdb/alpha-linux-tdep.c
+++ b/gdb/alpha-linux-tdep.c
@@ -362,7 +362,7 @@ alpha_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   /* Hook into the MDEBUG frame unwinder.  */
   alpha_mdebug_init_abi (info, gdbarch);
 
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
   tdep->dynamic_sigtramp_offset = alpha_linux_sigtramp_offset;
   tdep->sigcontext_addr = alpha_linux_sigcontext_addr;
   tdep->pc_in_sigtramp = alpha_linux_pc_in_sigtramp;
diff --git a/gdb/alpha-netbsd-tdep.c b/gdb/alpha-netbsd-tdep.c
index 6b604cfa9c6..72d7019377f 100644
--- a/gdb/alpha-netbsd-tdep.c
+++ b/gdb/alpha-netbsd-tdep.c
@@ -250,7 +250,7 @@ static void
 alphanbsd_init_abi (struct gdbarch_info info,
 		    struct gdbarch *gdbarch)
 {
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
 
   /* Hook into the DWARF CFI frame unwinder.  */
   alpha_dwarf2_init_abi (info, gdbarch);
diff --git a/gdb/alpha-obsd-tdep.c b/gdb/alpha-obsd-tdep.c
index 8baa8cc32c4..c0d672c3f72 100644
--- a/gdb/alpha-obsd-tdep.c
+++ b/gdb/alpha-obsd-tdep.c
@@ -97,7 +97,7 @@ alphaobsd_sigcontext_addr (struct frame_info *this_frame)
 static void
 alphaobsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
 
   /* Hook into the DWARF CFI frame unwinder.  */
   alpha_dwarf2_init_abi (info, gdbarch);
diff --git a/gdb/alpha-tdep.c b/gdb/alpha-tdep.c
index f04bad6bed8..44efc8e4bbb 100644
--- a/gdb/alpha-tdep.c
+++ b/gdb/alpha-tdep.c
@@ -615,7 +615,7 @@ alpha_return_value (struct gdbarch *gdbarch, struct value *function,
 		    gdb_byte *readbuf, const gdb_byte *writebuf)
 {
   enum type_code code = type->code ();
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
 
   if ((code == TYPE_CODE_STRUCT
        || code == TYPE_CODE_UNION
@@ -851,7 +851,7 @@ static int
 alpha_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR jb_addr;
   gdb_byte raw_buffer[ALPHA_REGISTER_SIZE];
@@ -891,7 +891,7 @@ alpha_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
   *this_prologue_cache = info;
 
   gdbarch *arch = get_frame_arch (this_frame);
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (arch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (arch);
   info->sigcontext_addr = tdep->sigcontext_addr (this_frame);
 
   return info;
@@ -904,7 +904,7 @@ static CORE_ADDR
 alpha_sigtramp_register_address (struct gdbarch *gdbarch,
 				 CORE_ADDR sigcontext_addr, int regnum)
 { 
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
 
   if (regnum >= 0 && regnum < 32)
     return sigcontext_addr + tdep->sc_regs_offset + regnum * 8;
@@ -925,7 +925,7 @@ alpha_sigtramp_frame_this_id (struct frame_info *this_frame,
 			      struct frame_id *this_id)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
   struct alpha_sigtramp_unwind_cache *info
     = alpha_sigtramp_frame_unwind_cache (this_frame, this_prologue_cache);
   CORE_ADDR stack_addr, code_addr;
@@ -1000,7 +1000,7 @@ alpha_sigtramp_frame_sniffer (const struct frame_unwind *self,
 
   /* We shouldn't even bother to try if the OSABI didn't register a
      sigcontext_addr handler or pc_in_sigtramp handler.  */
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
   if (tdep->sigcontext_addr == NULL)
     return 0;
 
@@ -1041,7 +1041,7 @@ static int heuristic_fence_post = 0;
 static CORE_ADDR
 alpha_heuristic_proc_start (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
-  alpha_gdbarch_tdep *tdep = (alpha_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
   CORE_ADDR last_non_nop = pc;
   CORE_ADDR fence = pc - heuristic_fence_post;
   CORE_ADDR orig_pc = pc;
diff --git a/gdb/amd64-darwin-tdep.c b/gdb/amd64-darwin-tdep.c
index 74906f6a02d..7fc35536bc6 100644
--- a/gdb/amd64-darwin-tdep.c
+++ b/gdb/amd64-darwin-tdep.c
@@ -97,7 +97,7 @@ amd64_darwin_sigcontext_addr (struct frame_info *this_frame)
 static void
 x86_darwin_init_abi_64 (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   amd64_init_abi (info, gdbarch,
 		  amd64_target_description (X86_XSTATE_SSE_MASK, true));
diff --git a/gdb/amd64-fbsd-nat.c b/gdb/amd64-fbsd-nat.c
index d125d582a21..7023a182e78 100644
--- a/gdb/amd64-fbsd-nat.c
+++ b/gdb/amd64-fbsd-nat.c
@@ -102,7 +102,7 @@ amd64_fbsd_nat_target::fetch_registers (struct regcache *regcache, int regnum)
 {
   struct gdbarch *gdbarch = regcache->arch ();
 #if defined(PT_GETFSBASE) || defined(PT_GETGSBASE)
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 #endif
   pid_t pid = get_ptrace_pid (regcache->ptid ());
   const struct regset *gregset = find_gregset (gdbarch);
@@ -174,7 +174,7 @@ amd64_fbsd_nat_target::store_registers (struct regcache *regcache, int regnum)
 {
   struct gdbarch *gdbarch = regcache->arch ();
 #if defined(PT_GETFSBASE) || defined(PT_GETGSBASE)
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 #endif
   pid_t pid = get_ptrace_pid (regcache->ptid ());
   const struct regset *gregset = find_gregset (gdbarch);
diff --git a/gdb/amd64-fbsd-tdep.c b/gdb/amd64-fbsd-tdep.c
index 55764beaad2..8e40283d838 100644
--- a/gdb/amd64-fbsd-tdep.c
+++ b/gdb/amd64-fbsd-tdep.c
@@ -262,7 +262,7 @@ amd64fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					void *cb_data,
 					const struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   cb (".reg", AMD64_FBSD_SIZEOF_GREGSET, AMD64_FBSD_SIZEOF_GREGSET,
       &amd64_fbsd_gregset, NULL, cb_data);
@@ -299,7 +299,7 @@ amd64fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 static void
 amd64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support. */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
index 9a0759d639c..aa9c56586ab 100644
--- a/gdb/amd64-linux-tdep.c
+++ b/gdb/amd64-linux-tdep.c
@@ -1656,7 +1656,7 @@ amd64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					  void *cb_data,
 					  const struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   cb (".reg", 27 * 8, 27 * 8, &i386_gregset, NULL, cb_data);
   cb (".reg2", 512, 512, &amd64_fpregset, NULL, cb_data);
@@ -1793,7 +1793,7 @@ static void
 amd64_linux_init_abi_common(struct gdbarch_info info, struct gdbarch *gdbarch,
 			    int num_disp_step_buffers)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, num_disp_step_buffers);
 
@@ -1846,7 +1846,7 @@ amd64_linux_init_abi_common(struct gdbarch_info info, struct gdbarch *gdbarch,
 static void
 amd64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   struct tdesc_arch_data *tdesc_data = info.tdesc_data;
   const struct tdesc_feature *feature;
   int valid_p;
@@ -2060,7 +2060,7 @@ amd64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 static void
 amd64_x32_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   struct tdesc_arch_data *tdesc_data = info.tdesc_data;
   const struct tdesc_feature *feature;
   int valid_p;
diff --git a/gdb/amd64-netbsd-tdep.c b/gdb/amd64-netbsd-tdep.c
index 3ab0267060d..59d723caa55 100644
--- a/gdb/amd64-netbsd-tdep.c
+++ b/gdb/amd64-netbsd-tdep.c
@@ -97,7 +97,7 @@ int amd64nbsd_r_reg_offset[] =
 static void
 amd64nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* Initialize general-purpose register set details first.  */
   tdep->gregset_reg_offset = amd64nbsd_r_reg_offset;
diff --git a/gdb/amd64-obsd-tdep.c b/gdb/amd64-obsd-tdep.c
index 3cb64fe924f..f0bc7c474a6 100644
--- a/gdb/amd64-obsd-tdep.c
+++ b/gdb/amd64-obsd-tdep.c
@@ -420,7 +420,7 @@ static const struct frame_unwind amd64obsd_trapframe_unwind =
 static void
 amd64obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   amd64_init_abi (info, gdbarch,
 		  amd64_target_description (X86_XSTATE_SSE_MASK, true));
diff --git a/gdb/amd64-sol2-tdep.c b/gdb/amd64-sol2-tdep.c
index 22a48e476a5..ce96eb045ec 100644
--- a/gdb/amd64-sol2-tdep.c
+++ b/gdb/amd64-sol2-tdep.c
@@ -80,7 +80,7 @@ amd64_sol2_mcontext_addr (struct frame_info *this_frame)
 static void
 amd64_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   tdep->gregset_reg_offset = amd64_sol2_gregset_reg_offset;
   tdep->gregset_num_regs = ARRAY_SIZE (amd64_sol2_gregset_reg_offset);
diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index b95ab1e87b8..0563b32a54b 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -247,7 +247,7 @@ static const int amd64_dwarf_regmap_len =
 static int
 amd64_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int ymm0_regnum = tdep->ymm0_regnum;
   int regnum = -1;
 
@@ -331,7 +331,7 @@ static const char * const amd64_dword_names[] =
 static const char *
 amd64_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   if (i386_byte_regnum_p (gdbarch, regnum))
     return amd64_byte_names[regnum - tdep->al_regnum];
   else if (i386_zmm_regnum_p (gdbarch, regnum))
@@ -353,7 +353,7 @@ amd64_pseudo_register_read_value (struct gdbarch *gdbarch,
 				  readable_regcache *regcache,
 				  int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   value *result_value = allocate_value (register_type (gdbarch, regnum));
   VALUE_LVAL (result_value) = lval_register;
@@ -413,7 +413,7 @@ amd64_pseudo_register_write (struct gdbarch *gdbarch,
 			     struct regcache *regcache,
 			     int regnum, const gdb_byte *buf)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (i386_byte_regnum_p (gdbarch, regnum))
     {
@@ -465,7 +465,7 @@ static int
 amd64_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				  struct agent_expr *ax, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (i386_byte_regnum_p (gdbarch, regnum))
     {
@@ -2749,7 +2749,7 @@ static struct amd64_frame_cache *
 amd64_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct amd64_frame_cache *cache;
   CORE_ADDR addr;
@@ -2832,7 +2832,7 @@ amd64_sigtramp_frame_sniffer (const struct frame_unwind *self,
 			      void **this_cache)
 {
   gdbarch *arch = get_frame_arch (this_frame);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
 
   /* We shouldn't even bother if we don't have a sigcontext_addr
      handler.  */
@@ -3032,7 +3032,7 @@ amd64_supply_fpregset (const struct regset *regset, struct regcache *regcache,
 		       int regnum, const void *fpregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   gdb_assert (len >= tdep->sizeof_fpregset);
   amd64_supply_fxsave (regcache, regnum, fpregs);
@@ -3049,7 +3049,7 @@ amd64_collect_fpregset (const struct regset *regset,
 			int regnum, void *fpregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   gdb_assert (len >= tdep->sizeof_fpregset);
   amd64_collect_fxsave (regcache, regnum, fpregs);
@@ -3073,7 +3073,7 @@ amd64_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
   gdb_byte buf[8];
   CORE_ADDR jb_addr;
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int jb_pc_offset = tdep->jb_pc_offset;
   int len = TYPE_LENGTH (builtin_type (gdbarch)->builtin_func_ptr);
 
@@ -3117,7 +3117,7 @@ void
 amd64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch,
 		const target_desc *default_tdesc)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   const struct target_desc *tdesc = info.target_desc;
   static const char *const stap_integer_prefixes[] = { "$", NULL };
   static const char *const stap_register_prefixes[] = { "%", NULL };
@@ -3296,7 +3296,7 @@ amd64_none_init_abi (gdbarch_info info, gdbarch *arch)
 static struct type *
 amd64_x32_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   switch (regnum - tdep->eax_regnum)
     {
@@ -3314,7 +3314,7 @@ void
 amd64_x32_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch,
 		    const target_desc *default_tdesc)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   amd64_init_abi (info, gdbarch, default_tdesc);
 
@@ -3384,7 +3384,7 @@ amd64_supply_fxsave (struct regcache *regcache, int regnum,
 		     const void *fxsave)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   i387_supply_fxsave (regcache, regnum, fxsave);
 
@@ -3407,7 +3407,7 @@ amd64_supply_xsave (struct regcache *regcache, int regnum,
 		    const void *xsave)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   i387_supply_xsave (regcache, regnum, xsave);
 
@@ -3442,7 +3442,7 @@ amd64_collect_fxsave (const struct regcache *regcache, int regnum,
 		      void *fxsave)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   gdb_byte *regs = (gdb_byte *) fxsave;
 
   i387_collect_fxsave (regcache, regnum, fxsave);
@@ -3463,7 +3463,7 @@ amd64_collect_xsave (const struct regcache *regcache, int regnum,
 		     void *xsave, int gcore)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   gdb_byte *regs = (gdb_byte *) xsave;
 
   i387_collect_xsave (regcache, regnum, xsave, gcore);
diff --git a/gdb/amd64-windows-tdep.c b/gdb/amd64-windows-tdep.c
index eca94f2ea7c..a9aef0bab88 100644
--- a/gdb/amd64-windows-tdep.c
+++ b/gdb/amd64-windows-tdep.c
@@ -1277,7 +1277,7 @@ amd64_windows_auto_wide_charset (void)
 static void
 amd64_windows_init_abi_common (gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* The dwarf2 unwinder (appended very early by i386_gdbarch_init) is
      preferred over the SEH one.  The reasons are:
diff --git a/gdb/arc-linux-tdep.c b/gdb/arc-linux-tdep.c
index 04ca38f1355..d72bdaf24ac 100644
--- a/gdb/arc-linux-tdep.c
+++ b/gdb/arc-linux-tdep.c
@@ -411,7 +411,7 @@ static std::vector<CORE_ADDR>
 arc_linux_software_single_step (struct regcache *regcache)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
   struct gdb_non_printing_memory_disassembler dis (gdbarch);
 
   /* Read current instruction.  */
@@ -694,7 +694,7 @@ arc_linux_core_read_description (struct gdbarch *gdbarch,
 static void
 arc_linux_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
 
   arc_linux_debug_printf ("GNU/Linux OS/ABI initialization.");
 
diff --git a/gdb/arc-newlib-tdep.c b/gdb/arc-newlib-tdep.c
index 7d7406c501c..2499dff43ec 100644
--- a/gdb/arc-newlib-tdep.c
+++ b/gdb/arc-newlib-tdep.c
@@ -36,7 +36,7 @@ arc_newlib_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
   arc_newlib_debug_printf ("Initialization.");
 
-  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
 
   /* Offset of original PC in longjmp jump buffer (in registers).  Value of PC
      offset can be found in newlib/libc/machine/arc/setjmp.S.  */
diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c
index 2f96e24a734..11e0551266e 100644
--- a/gdb/arc-tdep.c
+++ b/gdb/arc-tdep.c
@@ -1002,7 +1002,7 @@ arc_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
   arc_debug_printf ("called");
 
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
   int pc_offset = tdep->jb_pc * ARC_REGISTER_SIZE;
   gdb_byte buf[ARC_REGISTER_SIZE];
   CORE_ADDR jb_addr = get_frame_register_unsigned (frame, ARC_FIRST_ARG_REGNUM);
@@ -1810,7 +1810,7 @@ arc_make_sigtramp_frame_cache (struct frame_info *this_frame)
   arc_debug_printf ("called");
 
   gdbarch *arch = get_frame_arch (this_frame);
-  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (arch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (arch);
 
   /* Allocate new frame cache instance and space for saved register info.  */
   struct arc_frame_cache *cache = FRAME_OBSTACK_ZALLOC (struct arc_frame_cache);
@@ -1887,7 +1887,7 @@ arc_sigtramp_frame_sniffer (const struct frame_unwind *self,
   arc_debug_printf ("called");
 
   gdbarch *arch = get_frame_arch (this_frame);
-  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (arch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (arch);
 
   /* If we have a sigcontext_addr handler, then just return 1 (same as the
      "default_frame_sniffer ()").  */
@@ -2414,7 +2414,7 @@ arc_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 arc_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  arc_gdbarch_tdep *tdep = (arc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
 
   gdb_printf (file, "arc_dump_tdep: jb_pc = %i\n", tdep->jb_pc);
 
diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index ff946ee3767..360b8d694be 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -1198,11 +1198,13 @@ gdbarch_free (struct gdbarch *arch)
   xfree (obstack);
 }
 
+/* See gdbarch.h.  */
+
 struct gdbarch_tdep *
-gdbarch_tdep (struct gdbarch *gdbarch)
+gdbarch_tdep_1 (struct gdbarch *gdbarch)
 {
   if (gdbarch_debug >= 2)
-    gdb_printf (gdb_stdlog, "gdbarch_tdep called\n");
+    gdb_printf (gdb_stdlog, "gdbarch_tdep_1 called\n");
   return gdbarch->tdep;
 }
 
diff --git a/gdb/arm-fbsd-nat.c b/gdb/arm-fbsd-nat.c
index a306e1e2ee0..b161b7ed908 100644
--- a/gdb/arm-fbsd-nat.c
+++ b/gdb/arm-fbsd-nat.c
@@ -55,7 +55,7 @@ arm_fbsd_nat_target::fetch_registers (struct regcache *regcache, int regnum)
 #endif
 #ifdef PT_GETREGSET
   gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->tls_regnum > 0)
     {
@@ -90,7 +90,7 @@ arm_fbsd_nat_target::store_registers (struct regcache *regcache, int regnum)
 #endif
 #ifdef PT_GETREGSET
   gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->tls_regnum > 0)
     {
diff --git a/gdb/arm-fbsd-tdep.c b/gdb/arm-fbsd-tdep.c
index 483820c1092..61c8f0cecad 100644
--- a/gdb/arm-fbsd-tdep.c
+++ b/gdb/arm-fbsd-tdep.c
@@ -159,7 +159,7 @@ arm_fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				       void *cb_data,
 				       const struct regcache *regcache)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   cb (".reg", ARM_FBSD_SIZEOF_GREGSET, ARM_FBSD_SIZEOF_GREGSET,
       &arm_fbsd_gregset, NULL, cb_data);
@@ -233,7 +233,7 @@ static CORE_ADDR
 arm_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 				   CORE_ADDR lm_addr, CORE_ADDR offset)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   struct regcache *regcache;
 
   regcache = get_thread_arch_regcache (current_inferior ()->process_target (),
@@ -256,7 +256,7 @@ arm_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 static void
 arm_fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support.  */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/arm-linux-nat.c b/gdb/arm-linux-nat.c
index 8dac8456282..0188c78fe7a 100644
--- a/gdb/arm-linux-nat.c
+++ b/gdb/arm-linux-nat.c
@@ -339,7 +339,7 @@ fetch_vfp_regs (struct regcache *regcache)
   gdb_byte regbuf[ARM_VFP3_REGS_SIZE];
   int ret, tid;
   struct gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Get the thread id for the ptrace call.  */
   tid = regcache->ptid ().lwp ();
@@ -368,7 +368,7 @@ store_vfp_regs (const struct regcache *regcache)
   gdb_byte regbuf[ARM_VFP3_REGS_SIZE];
   int ret, tid;
   struct gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Get the thread id for the ptrace call.  */
   tid = regcache->ptid ().lwp ();
@@ -413,7 +413,7 @@ void
 arm_linux_nat_target::fetch_registers (struct regcache *regcache, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (-1 == regno)
     {
@@ -450,7 +450,7 @@ void
 arm_linux_nat_target::store_registers (struct regcache *regcache, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (-1 == regno)
     {
diff --git a/gdb/arm-linux-tdep.c b/gdb/arm-linux-tdep.c
index f299e9665d5..d530b7f59a8 100644
--- a/gdb/arm-linux-tdep.c
+++ b/gdb/arm-linux-tdep.c
@@ -712,7 +712,7 @@ arm_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					void *cb_data,
 					const struct regcache *regcache)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   cb (".reg", ARM_LINUX_SIZEOF_GREGSET, ARM_LINUX_SIZEOF_GREGSET,
       &arm_linux_gregset, NULL, cb_data);
@@ -1715,7 +1715,7 @@ arm_linux_init_abi (struct gdbarch_info info,
 								    NULL };
   static const char *const stap_register_indirection_suffixes[] = { "]",
 								    NULL };
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 1);
 
diff --git a/gdb/arm-netbsd-nat.c b/gdb/arm-netbsd-nat.c
index 764bbe8cd3d..251159154c9 100644
--- a/gdb/arm-netbsd-nat.c
+++ b/gdb/arm-netbsd-nat.c
@@ -50,7 +50,7 @@ static arm_netbsd_nat_target the_arm_netbsd_nat_target;
 static void
 arm_supply_vfpregset (struct regcache *regcache, struct fpreg *fpregset)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
   if (tdep->vfp_register_count == 0)
     return;
 
@@ -97,7 +97,7 @@ fetch_fp_register (struct regcache *regcache, int regno)
       return;
     }
 
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
   if (regno == ARM_FPSCR_REGNUM && tdep->vfp_register_count != 0)
     regcache->raw_supply (ARM_FPSCR_REGNUM, (char *) &vfp.vfp_fpscr);
   else if (regno >= ARM_D0_REGNUM
@@ -279,7 +279,7 @@ store_fp_register (const struct regcache *regcache, int regno)
       return;
     }
 
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
   if (regno == ARM_FPSCR_REGNUM && tdep->vfp_register_count != 0)
     regcache->raw_collect (ARM_FPSCR_REGNUM, (char *) &vfp.vfp_fpscr);
   else if (regno >= ARM_D0_REGNUM
@@ -301,7 +301,7 @@ store_fp_register (const struct regcache *regcache, int regno)
 static void
 store_fp_regs (const struct regcache *regcache)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (regcache->arch ());
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
   int lwp = regcache->ptid ().lwp ();
   if (tdep->vfp_register_count == 0)
     return;
diff --git a/gdb/arm-netbsd-tdep.c b/gdb/arm-netbsd-tdep.c
index a6a78f0b893..aa4d15df4c6 100644
--- a/gdb/arm-netbsd-tdep.c
+++ b/gdb/arm-netbsd-tdep.c
@@ -111,7 +111,7 @@ static void
 arm_netbsd_init_abi_common (struct gdbarch_info info,
 			    struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   tdep->lowest_pc = 0x8000;
   switch (info.byte_order)
@@ -148,7 +148,7 @@ static void
 arm_netbsd_elf_init_abi (struct gdbarch_info info,
 			 struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   arm_netbsd_init_abi_common (info, gdbarch);
 
diff --git a/gdb/arm-none-tdep.c b/gdb/arm-none-tdep.c
index 510ce4fa3c5..0d5eb04826e 100644
--- a/gdb/arm-none-tdep.c
+++ b/gdb/arm-none-tdep.c
@@ -177,7 +177,7 @@ arm_none_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				       void *cb_data,
 				       const struct regcache *regcache)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   cb (".reg", ARM_NONE_SIZEOF_GREGSET, ARM_NONE_SIZEOF_GREGSET,
       &arm_none_gregset, nullptr, cb_data);
diff --git a/gdb/arm-obsd-tdep.c b/gdb/arm-obsd-tdep.c
index 37cb30b9a2a..634c76b7561 100644
--- a/gdb/arm-obsd-tdep.c
+++ b/gdb/arm-obsd-tdep.c
@@ -76,7 +76,7 @@ static void
 armobsd_init_abi (struct gdbarch_info info,
 		  struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->fp_model == ARM_FLOAT_AUTO)
     tdep->fp_model = ARM_FLOAT_SOFT_VFP;
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 994af630f34..73fc642ee6b 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -355,7 +355,7 @@ static void
 arm_cache_init (struct arm_prologue_cache *cache, struct frame_info *frame)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   arm_cache_init (cache, gdbarch);
   cache->sp = get_frame_register_unsigned (frame, ARM_SP_REGNUM);
@@ -556,7 +556,7 @@ bool arm_unwind_secure_frames = true;
 int
 arm_psr_thumb_bit (struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->is_m)
     return XPSR_T;
@@ -668,7 +668,7 @@ arm_pc_is_thumb (struct gdbarch *gdbarch, CORE_ADDR memaddr)
   struct bound_minimal_symbol sym;
   char type;
   arm_displaced_step_copy_insn_closure *dsc = nullptr;
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (gdbarch_displaced_step_copy_insn_closure_by_addr_p (gdbarch))
     dsc = ((arm_displaced_step_copy_insn_closure * )
@@ -772,7 +772,7 @@ arm_pc_is_thumb (struct gdbarch *gdbarch, CORE_ADDR memaddr)
 static int
 arm_m_addr_is_magic (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   if (tdep->have_sec_ext)
     {
       switch ((addr & 0xff000000))
@@ -814,7 +814,7 @@ arm_m_addr_is_magic (struct gdbarch *gdbarch, CORE_ADDR addr)
 static CORE_ADDR
 arm_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR val)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* On M-profile devices, do not strip the low bit from EXC_RETURN
      (the magic exception return address).  */
@@ -942,7 +942,7 @@ thumb_analyze_prologue (struct gdbarch *gdbarch,
 			CORE_ADDR start, CORE_ADDR limit,
 			struct arm_prologue_cache *cache)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
   int i;
@@ -1882,7 +1882,7 @@ arm_analyze_prologue (struct gdbarch *gdbarch,
   CORE_ADDR offset, current_pc;
   pv_t regs[ARM_FPS_REGNUM];
   CORE_ADDR unrecognized_pc = 0;
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Search the prologue looking for instructions that set up the
      frame pointer, adjust the stack pointer, and save registers.
@@ -2130,7 +2130,7 @@ arm_scan_prologue (struct frame_info *this_frame,
   CORE_ADDR prologue_start, prologue_end;
   CORE_ADDR prev_pc = get_frame_pc (this_frame);
   CORE_ADDR block_addr = get_frame_address_in_block (this_frame);
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Assume there is no frame until proven otherwise.  */
   cache->framereg = ARM_SP_REGNUM;
@@ -2235,7 +2235,7 @@ arm_make_prologue_cache (struct frame_info *this_frame)
     return cache;
 
   arm_gdbarch_tdep *tdep =
-    (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
 
   prev_sp = unwound_fp + cache->framesize;
   arm_cache_set_active_sp_value (cache, tdep, prev_sp);
@@ -2266,7 +2266,7 @@ arm_prologue_unwind_stop_reason (struct frame_info *this_frame,
   /* This is meant to halt the backtrace at "_start".  */
   pc = get_frame_pc (this_frame);
   gdbarch *arch = get_frame_arch (this_frame);
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (arch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (arch);
   if (pc <= tdep->lowest_pc)
     return UNWIND_OUTERMOST;
 
@@ -2294,7 +2294,7 @@ arm_prologue_this_id (struct frame_info *this_frame,
   cache = (struct arm_prologue_cache *) *this_cache;
 
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
 
   /* Use function start address as part of the frame ID.  If we cannot
      identify the start address (due to missing symbol information),
@@ -2321,7 +2321,7 @@ arm_prologue_prev_register (struct frame_info *this_frame,
     *this_cache = arm_make_prologue_cache (this_frame);
   cache = (struct arm_prologue_cache *) *this_cache;
 
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* If this frame has signed the return address, mark it as so.  */
   if (tdep->have_pacbti && cache->ra_signed_state.has_value ()
@@ -2989,7 +2989,7 @@ arm_exidx_fill_cache (struct frame_info *this_frame, gdb_byte *entry)
 
   /* We already got the previous SP.  */
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   arm_cache_set_active_sp_value (cache, tdep, vsp);
 
   return cache;
@@ -3114,7 +3114,7 @@ arm_make_epilogue_frame_cache (struct frame_info *this_frame)
 
   /* Since we are in epilogue, the SP has been restored.  */
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   arm_cache_set_active_sp_value (cache, tdep,
 				 get_frame_register_unsigned (this_frame,
 							      ARM_SP_REGNUM));
@@ -3153,7 +3153,7 @@ arm_epilogue_frame_this_id (struct frame_info *this_frame,
     func = pc;
 
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   *this_id = frame_id_build (arm_cache_get_prev_sp_value (cache, tdep), pc);
 }
 
@@ -3277,7 +3277,7 @@ arm_make_stub_cache (struct frame_info *this_frame)
   arm_cache_init (cache, this_frame);
 
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   arm_cache_set_active_sp_value (cache, tdep,
 				 get_frame_register_unsigned (this_frame,
 							      ARM_SP_REGNUM));
@@ -3299,7 +3299,7 @@ arm_stub_this_id (struct frame_info *this_frame,
   cache = (struct arm_prologue_cache *) *this_cache;
 
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   *this_id = frame_id_build (arm_cache_get_prev_sp_value (cache, tdep),
 			     get_frame_pc (this_frame));
 }
@@ -3347,7 +3347,7 @@ static struct arm_prologue_cache *
 arm_m_exception_cache (struct frame_info *this_frame)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct arm_prologue_cache *cache;
   CORE_ADDR lr;
@@ -3651,7 +3651,7 @@ arm_m_exception_this_id (struct frame_info *this_frame,
 
   /* Our frame ID for a stub frame is the current SP and LR.  */
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   *this_id = frame_id_build (arm_cache_get_prev_sp_value (cache, tdep),
 			     get_frame_pc (this_frame));
 }
@@ -3673,7 +3673,7 @@ arm_m_exception_prev_register (struct frame_info *this_frame,
 
   /* The value was already reconstructed into PREV_SP.  */
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   if (prev_regnum == ARM_SP_REGNUM)
     return frame_unwind_got_constant (this_frame, prev_regnum,
 				      arm_cache_get_prev_sp_value (cache, tdep));
@@ -3761,7 +3761,7 @@ arm_normal_frame_base (struct frame_info *this_frame, void **this_cache)
   cache = (struct arm_prologue_cache *) *this_cache;
 
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (get_frame_arch (this_frame));
+    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   return arm_cache_get_prev_sp_value (cache, tdep) - cache->framesize;
 }
 
@@ -3777,7 +3777,7 @@ arm_dwarf2_prev_register (struct frame_info *this_frame, void **this_cache,
 			  int regnum)
 {
   struct gdbarch * gdbarch = get_frame_arch (this_frame);
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   CORE_ADDR lr;
   ULONGEST cpsr;
 
@@ -4301,7 +4301,7 @@ arm_vfp_call_candidate (struct type *t, enum arm_vfp_cprc_base_type *base_type,
 static int
 arm_vfp_abi_for_function (struct gdbarch *gdbarch, struct type *func_type)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Variadic functions always use the base ABI.  Assume that functions
      without debug info are not variadic.  */
@@ -4335,7 +4335,7 @@ arm_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   int use_vfp_abi;
   struct type *ftype;
   unsigned vfp_regs_free = (1 << 16) - 1;
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Determine the type of this function and whether the VFP ABI
      applies.  */
@@ -4607,7 +4607,7 @@ arm_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
 static struct type *
 arm_ext_type (struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (!tdep->arm_ext_type)
     tdep->arm_ext_type
@@ -4620,7 +4620,7 @@ arm_ext_type (struct gdbarch *gdbarch)
 static struct type *
 arm_neon_double_type (struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->neon_double_type == NULL)
     {
@@ -4659,7 +4659,7 @@ arm_neon_double_type (struct gdbarch *gdbarch)
 static struct type *
 arm_neon_quad_type (struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->neon_quad_type == NULL)
     {
@@ -4697,7 +4697,7 @@ arm_neon_quad_type (struct gdbarch *gdbarch)
 static bool
 is_q_pseudo (struct gdbarch *gdbarch, int regnum)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* Q pseudo registers are available for both NEON (Q0~Q15) and
      MVE (Q0~Q7) features.  */
@@ -4718,7 +4718,7 @@ is_q_pseudo (struct gdbarch *gdbarch, int regnum)
 static bool
 is_s_pseudo (struct gdbarch *gdbarch, int regnum)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->have_s_pseudos
       && regnum >= tdep->s_pseudo_base
@@ -4737,7 +4737,7 @@ is_s_pseudo (struct gdbarch *gdbarch, int regnum)
 static bool
 is_mve_pseudo (struct gdbarch *gdbarch, int regnum)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->have_mve
       && regnum >= tdep->mve_pseudo_base
@@ -4756,7 +4756,7 @@ is_mve_pseudo (struct gdbarch *gdbarch, int regnum)
 static bool
 is_pacbti_pseudo (struct gdbarch *gdbarch, int regnum)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->have_pacbti
       && regnum >= tdep->pacbti_pseudo_base
@@ -4772,7 +4772,7 @@ is_pacbti_pseudo (struct gdbarch *gdbarch, int regnum)
 static struct type *
 arm_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (is_s_pseudo (gdbarch, regnum))
     return builtin_type (gdbarch)->builtin_float;
@@ -4851,7 +4851,7 @@ arm_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
   /* PACBTI register containing the Pointer Authentication Code.  */
   if (reg == ARM_DWARF_RA_AUTH_CODE)
     {
-      arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
       if (tdep->have_pacbti)
 	return tdep->pacbti_pseudo_base;
@@ -4997,7 +4997,7 @@ arm_adjust_breakpoint_address (struct gdbarch *gdbarch, CORE_ADDR bpaddr)
   int buf_len;
   enum bfd_endian order = gdbarch_byte_order_for_code (gdbarch);
   int i, any, last_it, last_it_count;
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* If we are using BKPT breakpoints, none of this is necessary.  */
   if (tdep->thumb2_breakpoint == NULL)
@@ -8305,7 +8305,7 @@ arm_displaced_init_closure (struct gdbarch *gdbarch, CORE_ADDR from,
 			    CORE_ADDR to,
 			    arm_displaced_step_copy_insn_closure *dsc)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   unsigned int i, len, offset;
   enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
   int size = dsc->is_thumb? 2 : 4;
@@ -8468,7 +8468,7 @@ static const gdb_byte arm_default_thumb_be_breakpoint[] = THUMB_BE_BREAKPOINT;
 static int
 arm_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
 
   if (arm_pc_is_thumb (gdbarch, *pcptr))
@@ -8503,7 +8503,7 @@ arm_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 static const gdb_byte *
 arm_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   switch (kind)
     {
@@ -8575,7 +8575,7 @@ arm_extract_return_value (struct type *type, struct regcache *regs,
 {
   struct gdbarch *gdbarch = regs->arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (TYPE_CODE_FLT == type->code ())
     {
@@ -8686,7 +8686,7 @@ arm_return_in_memory (struct gdbarch *gdbarch, struct type *type)
       return (TYPE_LENGTH (type) > 16);
     }
 
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   if (tdep->arm_abi != ARM_ABI_APCS)
     {
       /* The AAPCS says all aggregates not larger than a word are returned
@@ -8792,7 +8792,7 @@ arm_store_return_value (struct type *type, struct regcache *regs,
   if (type->code () == TYPE_CODE_FLT)
     {
       gdb_byte buf[ARM_FP_REGISTER_SIZE];
-      arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
       switch (tdep->fp_model)
 	{
@@ -8881,7 +8881,7 @@ arm_return_value (struct gdbarch *gdbarch, struct value *function,
 		  struct type *valtype, struct regcache *regcache,
 		  gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   struct type *func_type = function ? value_type (function) : NULL;
   enum arm_vfp_cprc_base_type vfp_base_type;
   int vfp_base_count;
@@ -8973,7 +8973,7 @@ static int
 arm_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR jb_addr;
   gdb_byte buf[ARM_INT_REGISTER_SIZE];
@@ -9166,7 +9166,7 @@ show_fp_model (struct ui_file *file, int from_tty,
       && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm)
     {
       arm_gdbarch_tdep *tdep
-	= (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+	= gdbarch_tdep<arm_gdbarch_tdep> (target_gdbarch ());
 
       gdb_printf (file, _("\
 The current ARM floating point model is \"auto\" (currently \"%s\").\n"),
@@ -9206,7 +9206,7 @@ arm_show_abi (struct ui_file *file, int from_tty,
       && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm)
     {
       arm_gdbarch_tdep *tdep
-	= (arm_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+	= gdbarch_tdep<arm_gdbarch_tdep> (target_gdbarch ());
 
       gdb_printf (file, _("\
 The current ARM ABI is \"auto\" (currently \"%s\").\n"),
@@ -9285,7 +9285,7 @@ show_disassembly_style_sfunc (struct ui_file *file, int from_tty,
 static const char *
 arm_register_name (struct gdbarch *gdbarch, int i)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (is_s_pseudo (gdbarch, i))
     {
@@ -9456,7 +9456,7 @@ static enum register_status
 arm_mve_pseudo_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 		     int regnum, gdb_byte *buf)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* P0 is the first 16 bits of VPR.  */
   return regcache->raw_read_part (tdep->mve_vpr_regnum, 0, 2, buf);
@@ -9470,7 +9470,7 @@ arm_pseudo_read (struct gdbarch *gdbarch, readable_regcache *regcache,
   char name_buf[4];
   gdb_byte reg_buf[8];
   int offset, double_regnum;
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   gdb_assert (regnum >= num_regs);
 
@@ -9542,7 +9542,7 @@ static void
 arm_mve_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache,
 		      int regnum, const gdb_byte *buf)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   /* P0 is the first 16 bits of VPR.  */
   regcache->raw_write_part (tdep->mve_vpr_regnum, 0, 2, buf);
@@ -9556,7 +9556,7 @@ arm_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache,
   char name_buf[4];
   gdb_byte reg_buf[8];
   int offset, double_regnum;
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   gdb_assert (regnum >= num_regs);
 
@@ -9644,7 +9644,7 @@ arm_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 static void
 arm_register_g_packet_guesses (struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->is_m)
     {
@@ -9687,7 +9687,7 @@ arm_register_g_packet_guesses (struct gdbarch *gdbarch)
 static int
 arm_code_of_frame_writable (struct gdbarch *gdbarch, struct frame_info *frame)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->is_m && get_frame_type (frame) == SIGTRAMP_FRAME)
     {
@@ -10246,7 +10246,7 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
     {
       arm_gdbarch_tdep *tdep
-	= (arm_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
+	= gdbarch_tdep<arm_gdbarch_tdep> (best_arch->gdbarch);
 
       if (arm_abi != ARM_ABI_AUTO && arm_abi != tdep->arm_abi)
 	continue;
@@ -10566,7 +10566,7 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 arm_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep == NULL)
     return;
@@ -12775,7 +12775,7 @@ arm_record_coproc_data_proc (arm_insn_decode_record *arm_insn_r)
 {
   uint32_t op, op1_ebit, coproc, bits_24_25;
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep (arm_insn_r->gdbarch);
+    = gdbarch_tdep<arm_gdbarch_tdep> (arm_insn_r->gdbarch);
   struct regcache *reg_cache = arm_insn_r->regcache;
 
   arm_insn_r->opcode = bits (arm_insn_r->arm_insn, 24, 27);
@@ -13263,7 +13263,7 @@ static int
 thumb_record_ldm_stm_swi (arm_insn_decode_record *thumb_insn_r)
 {
   arm_gdbarch_tdep *tdep
-    = (arm_gdbarch_tdep *) gdbarch_tdep  (thumb_insn_r->gdbarch);
+    = gdbarch_tdep<arm_gdbarch_tdep>  (thumb_insn_r->gdbarch);
   struct regcache *reg_cache = thumb_insn_r->regcache;
 
   uint32_t ret = 0; /* function return value: -1:record failure ;  0:success  */
diff --git a/gdb/arm-wince-tdep.c b/gdb/arm-wince-tdep.c
index 354c6fbca7f..5063b308809 100644
--- a/gdb/arm-wince-tdep.c
+++ b/gdb/arm-wince-tdep.c
@@ -115,7 +115,7 @@ arm_wince_skip_main_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
 static void
 arm_wince_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
 
   windows_init_abi (info, gdbarch);
 
diff --git a/gdb/avr-tdep.c b/gdb/avr-tdep.c
index e103045cb23..4722f7ee748 100644
--- a/gdb/avr-tdep.c
+++ b/gdb/avr-tdep.c
@@ -232,7 +232,7 @@ avr_register_type (struct gdbarch *gdbarch, int reg_nr)
   if (reg_nr == AVR_PC_REGNUM)
     return builtin_type (gdbarch)->builtin_uint32;
 
-  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
   if (reg_nr == AVR_PSEUDO_PC_REGNUM)
     return tdep->pc_type;
 
@@ -750,7 +750,7 @@ avr_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR pc_beg, CORE_ADDR pc_end,
   gdb_assert (vpc < AVR_MAX_PROLOGUE_SIZE);
 
   /* Handle static small stack allocation using rcall or push.  */
-  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
   while (scan_stage == 1 && vpc < len)
     {
       insn = extract_unsigned_integer (&prologue[vpc], 2, byte_order);
@@ -1053,7 +1053,7 @@ avr_frame_unwind_cache (struct frame_info *this_frame,
 
   /* The previous frame's SP needed to be computed.  Save the computed
      value.  */
-  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
   info->saved_regs[AVR_SP_REGNUM].set_value (info->prev_sp
 					     - 1 + tdep->call_length);
 
@@ -1135,7 +1135,7 @@ avr_frame_prev_register (struct frame_info *this_frame,
 	  int i;
 	  gdb_byte buf[3];
 	  struct gdbarch *gdbarch = get_frame_arch (this_frame);
-	  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
 
 	  read_memory (info->saved_regs[AVR_PC_REGNUM].addr (),
 		       buf, tdep->call_length);
@@ -1277,7 +1277,7 @@ avr_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 {
   int i;
   gdb_byte buf[3];
-  avr_gdbarch_tdep *tdep = (avr_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
   int call_length = tdep->call_length;
   CORE_ADDR return_pc = avr_convert_iaddr_to_raw (bp_addr);
   int regnum = AVR_ARGN_REGNUM;
@@ -1461,7 +1461,7 @@ avr_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
     {
       avr_gdbarch_tdep *tdep
-	= (avr_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
+	= gdbarch_tdep<avr_gdbarch_tdep> (best_arch->gdbarch);
 
       if (tdep->call_length == call_length)
 	return best_arch->gdbarch;
diff --git a/gdb/bfin-tdep.c b/gdb/bfin-tdep.c
index 573eed94793..f232e22c37c 100644
--- a/gdb/bfin-tdep.c
+++ b/gdb/bfin-tdep.c
@@ -766,7 +766,7 @@ bfin_frame_align (struct gdbarch *gdbarch, CORE_ADDR address)
 enum bfin_abi
 bfin_abi (struct gdbarch *gdbarch)
 {
-  bfin_gdbarch_tdep *tdep = (bfin_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  bfin_gdbarch_tdep *tdep = gdbarch_tdep<bfin_gdbarch_tdep> (gdbarch);
   return tdep->bfin_abi;
 }
 
@@ -792,7 +792,7 @@ bfin_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       bfin_gdbarch_tdep *tdep
-	= (bfin_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<bfin_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->bfin_abi != abi)
 	continue;
diff --git a/gdb/cris-linux-tdep.c b/gdb/cris-linux-tdep.c
index f55f9b9083c..b3ed7450e99 100644
--- a/gdb/cris-linux-tdep.c
+++ b/gdb/cris-linux-tdep.c
@@ -33,7 +33,7 @@
 static void
 cris_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/cris-tdep.c b/gdb/cris-tdep.c
index efd728a5229..73110d97f2f 100644
--- a/gdb/cris-tdep.c
+++ b/gdb/cris-tdep.c
@@ -313,7 +313,7 @@ cris_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
 				  void **this_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct cris_unwind_cache *info;
   CORE_ADDR addr;
@@ -450,7 +450,7 @@ static int
 crisv32_single_step_through_delay (struct gdbarch *gdbarch,
 				   struct frame_info *this_frame)
 {
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   ULONGEST erp;
   int ret = 0;
 
@@ -696,7 +696,7 @@ cris_frame_unwind_cache (struct frame_info *this_frame,
 			 void **this_prologue_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   struct cris_unwind_cache *info;
 
   if ((*this_prologue_cache))
@@ -1334,7 +1334,7 @@ crisv32_scan_prologue (CORE_ADDR pc, struct frame_info *this_frame,
 static CORE_ADDR
 cris_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   CORE_ADDR func_addr, func_end;
   struct symtab_and_line sal;
   CORE_ADDR pc_after_prologue;
@@ -1369,7 +1369,7 @@ cris_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 static const gdb_byte *
 cris_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   static unsigned char break8_insn[] = {0x38, 0xe9};
   static unsigned char break15_insn[] = {0x3f, 0xe9};
 
@@ -1388,7 +1388,7 @@ static int
 cris_spec_reg_applicable (struct gdbarch *gdbarch,
 			  struct cris_spec_reg spec_reg)
 {
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   unsigned int version = tdep->cris_version;
   
   switch (spec_reg.applicable_version)
@@ -3767,7 +3767,7 @@ cris_supply_gregset (const struct regset *regset, struct regcache *regcache,
 		     int regnum, const void *gregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   int i;
   const cris_elf_greg_t *regp = static_cast<const cris_elf_greg_t *>(gregs);
 
@@ -3861,7 +3861,7 @@ Makes GDB use the NRP register instead of the ERP register in certain cases."),
 static void
 cris_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  cris_gdbarch_tdep *tdep = (cris_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
   if (tdep != NULL)
     {
       gdb_printf (file, "cris_dump_tdep: tdep->cris_version = %i\n",
@@ -3941,7 +3941,7 @@ cris_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       cris_gdbarch_tdep *tdep
-	= (cris_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<cris_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->cris_version == usr_cmd_cris_version
 	  && tdep->cris_mode == usr_cmd_cris_mode
diff --git a/gdb/csky-tdep.c b/gdb/csky-tdep.c
index b63ff7ccd44..4f563189fef 100644
--- a/gdb/csky-tdep.c
+++ b/gdb/csky-tdep.c
@@ -2655,7 +2655,7 @@ csky_pseudo_register_name (struct gdbarch *gdbarch, int regno)
 {
   int num_regs = gdbarch_num_regs (gdbarch);
   csky_gdbarch_tdep *tdep
-        = (csky_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+        = gdbarch_tdep<csky_gdbarch_tdep> (gdbarch);
 
   regno -= num_regs;
 
@@ -2703,7 +2703,7 @@ csky_pseudo_register_read (struct gdbarch *gdbarch,
 {
   int num_regs = gdbarch_num_regs (gdbarch);
   csky_gdbarch_tdep *tdep
-        = (csky_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+        = gdbarch_tdep<csky_gdbarch_tdep> (gdbarch);
 
   regnum -= num_regs;
 
@@ -2755,7 +2755,7 @@ csky_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
 {
   int num_regs = gdbarch_num_regs (gdbarch);
   csky_gdbarch_tdep *tdep
-        = (csky_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+        = gdbarch_tdep<csky_gdbarch_tdep> (gdbarch);
 
   regnum -= num_regs;
 
@@ -2883,7 +2883,7 @@ csky_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       csky_gdbarch_tdep *tdep
-        = (csky_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<csky_gdbarch_tdep> (arches->gdbarch);
       if (fpu_abi != tdep->fpu_abi)
         continue;
       if (vdsp_version != tdep->vdsp_version)
diff --git a/gdb/frv-tdep.c b/gdb/frv-tdep.c
index 2328791a540..34f437764a9 100644
--- a/gdb/frv-tdep.c
+++ b/gdb/frv-tdep.c
@@ -93,7 +93,7 @@ struct frv_gdbarch_tdep : gdbarch_tdep
 enum frv_abi
 frv_abi (struct gdbarch *gdbarch)
 {
-  frv_gdbarch_tdep *tdep = (frv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  frv_gdbarch_tdep *tdep = gdbarch_tdep<frv_gdbarch_tdep> (gdbarch);
   return tdep->frv_abi;
 }
 
@@ -275,7 +275,7 @@ frv_register_name (struct gdbarch *gdbarch, int reg)
   if (reg >= frv_num_regs + frv_num_pseudo_regs)
     return "?toolarge?";
 
-  frv_gdbarch_tdep *tdep = (frv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  frv_gdbarch_tdep *tdep = gdbarch_tdep<frv_gdbarch_tdep> (gdbarch);
   return tdep->register_names[reg];
 }
 
diff --git a/gdb/ft32-tdep.c b/gdb/ft32-tdep.c
index f77e313e0dd..024ca47ce4d 100644
--- a/gdb/ft32-tdep.c
+++ b/gdb/ft32-tdep.c
@@ -110,7 +110,7 @@ ft32_register_type (struct gdbarch *gdbarch, int reg_nr)
 {
   if (reg_nr == FT32_PC_REGNUM)
     {
-      ft32_gdbarch_tdep *tdep = (ft32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      ft32_gdbarch_tdep *tdep = gdbarch_tdep<ft32_gdbarch_tdep> (gdbarch);
       return tdep->pc_type;
     }
   else if (reg_nr == FT32_SP_REGNUM || reg_nr == FT32_FP_REGNUM)
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index 3a7b7f92ef7..b2c91db0c4f 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -142,8 +142,23 @@ using read_core_file_mappings_loop_ftype =
 
 #include "gdbarch-gen.h"
 
-extern struct gdbarch_tdep *gdbarch_tdep (struct gdbarch *gdbarch);
+/* An internal function that should _only_ be called from gdbarch_tdep.
+   Returns the gdbarch_tdep field held within GDBARCH.  */
 
+extern struct gdbarch_tdep *gdbarch_tdep_1 (struct gdbarch *gdbarch);
+
+/* Return the gdbarch_tdep object held within GDBARCH cast to the type
+   TDepType, which should be a sub-class of gdbarch_tdep.  There is no
+   checking done that the gdbarch_tdep within GDBARCH actually is of the
+   type TDepType, we just assume the caller knows what they are doing.  */
+
+template<typename TDepType>
+static inline TDepType *
+gdbarch_tdep (struct gdbarch *gdbarch)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep_1 (gdbarch);
+  return static_cast<TDepType *> (tdep);
+}
 
 /* Mechanism for co-ordinating the selection of a specific
    architecture.
diff --git a/gdb/hppa-bsd-tdep.c b/gdb/hppa-bsd-tdep.c
index 34f57d2512a..c405511529d 100644
--- a/gdb/hppa-bsd-tdep.c
+++ b/gdb/hppa-bsd-tdep.c
@@ -118,7 +118,7 @@ hppabsd_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
 void
 hppabsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
 
   /* OpenBSD and NetBSD have a 64-bit 'long double'.  */
   set_gdbarch_long_double_bit (gdbarch, 64);
diff --git a/gdb/hppa-linux-tdep.c b/gdb/hppa-linux-tdep.c
index 40e32c115d2..f17d2ae6b02 100644
--- a/gdb/hppa-linux-tdep.c
+++ b/gdb/hppa-linux-tdep.c
@@ -476,7 +476,7 @@ hppa_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					 void *cb_data,
 					 const struct regcache *regcache)
 {
-  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
 
   cb (".reg", 80 * tdep->bytes_per_address, 80 * tdep->bytes_per_address,
       &hppa_linux_regset, NULL, cb_data);
@@ -486,7 +486,7 @@ hppa_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 static void
 hppa_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/hppa-tdep.c b/gdb/hppa-tdep.c
index f9ececbb04f..9f93a945a6a 100644
--- a/gdb/hppa-tdep.c
+++ b/gdb/hppa-tdep.c
@@ -247,7 +247,7 @@ internalize_unwinds (struct objfile *objfile, struct unwind_table_entry *table,
   if (size > 0)
     {
       struct gdbarch *gdbarch = objfile->arch ();
-      hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
       unsigned long tmp;
       unsigned i;
       char *buf = (char *) alloca (size);
@@ -718,7 +718,7 @@ hppa32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   /* Global pointer (r19) of the function we are trying to call.  */
   CORE_ADDR gp;
 
-  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
 
   for (write_pass = 0; write_pass < 2; write_pass++)
     {
@@ -955,7 +955,7 @@ hppa64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 			function_call_return_method return_method,
 			CORE_ADDR struct_addr)
 {
-  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int i, offset = 0;
   CORE_ADDR gp;
@@ -2241,7 +2241,7 @@ hppa_frame_cache (struct frame_info *this_frame, void **this_cache)
   }
 
   {
-    hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+    hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
 
     if (tdep->unwind_adjust_stub)
       tdep->unwind_adjust_stub (this_frame, cache->base, cache->saved_regs);
@@ -2471,7 +2471,7 @@ hppa_stub_unwind_sniffer (const struct frame_unwind *self,
 {
   CORE_ADDR pc = get_frame_address_in_block (this_frame);
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
 
   if (pc == 0
       || (tdep->in_solib_call_trampoline != NULL
@@ -3147,7 +3147,7 @@ hppa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 hppa_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  hppa_gdbarch_tdep *tdep = (hppa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
 
   gdb_printf (file, "bytes_per_address = %d\n", 
 	      tdep->bytes_per_address);
diff --git a/gdb/i386-bsd-tdep.c b/gdb/i386-bsd-tdep.c
index b38f8d05887..dbbd3c786c3 100644
--- a/gdb/i386-bsd-tdep.c
+++ b/gdb/i386-bsd-tdep.c
@@ -74,7 +74,7 @@ int i386bsd_sc_reg_offset[] =
 void
 i386bsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   tdep->jb_pc_offset = 0;
 
diff --git a/gdb/i386-darwin-tdep.c b/gdb/i386-darwin-tdep.c
index dc780583766..2a9198aceb3 100644
--- a/gdb/i386-darwin-tdep.c
+++ b/gdb/i386-darwin-tdep.c
@@ -156,7 +156,7 @@ i386_darwin_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 			     function_call_return_method return_method,
 			     CORE_ADDR struct_addr)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   gdb_byte buf[4];
   int i;
@@ -248,7 +248,7 @@ i386_darwin_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 static void
 i386_darwin_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* We support the SSE registers.  */
   tdep->num_xmm_regs = I386_NUM_XREGS - 1;
diff --git a/gdb/i386-fbsd-tdep.c b/gdb/i386-fbsd-tdep.c
index d68498cd5e9..b7a524db68c 100644
--- a/gdb/i386-fbsd-tdep.c
+++ b/gdb/i386-fbsd-tdep.c
@@ -325,7 +325,7 @@ i386fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				       void *cb_data,
 				       const struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   cb (".reg", I386_FBSD_SIZEOF_GREGSET, I386_FBSD_SIZEOF_GREGSET,
       &i386_fbsd_gregset, NULL, cb_data);
@@ -365,7 +365,7 @@ i386fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 static void
 i386fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support. */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/i386-gnu-tdep.c b/gdb/i386-gnu-tdep.c
index 51c253d2dfe..3d97fe36a85 100644
--- a/gdb/i386-gnu-tdep.c
+++ b/gdb/i386-gnu-tdep.c
@@ -173,7 +173,7 @@ static int i386gnu_gregset_reg_offset[] =
 static void
 i386gnu_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* GNU uses ELF.  */
   i386_elf_init_abi (info, gdbarch);
diff --git a/gdb/i386-go32-tdep.c b/gdb/i386-go32-tdep.c
index 15ac38dc12f..0c0c08e3579 100644
--- a/gdb/i386-go32-tdep.c
+++ b/gdb/i386-go32-tdep.c
@@ -26,7 +26,7 @@
 static void
 i386_go32_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* DJGPP doesn't have any special frames for signal handlers.  */
   tdep->sigtramp_p = NULL;
diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c
index 5d7f54194af..6033104230f 100644
--- a/gdb/i386-linux-tdep.c
+++ b/gdb/i386-linux-tdep.c
@@ -763,7 +763,7 @@ i386_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					 void *cb_data,
 					 const struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   cb (".reg", 68, 68, &i386_gregset, NULL, cb_data);
 
@@ -825,7 +825,7 @@ i386_linux_displaced_step_copy_insn (struct gdbarch *gdbarch,
 static void
 i386_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   const struct target_desc *tdesc = info.target_desc;
   struct tdesc_arch_data *tdesc_data = info.tdesc_data;
   const struct tdesc_feature *feature;
diff --git a/gdb/i386-netbsd-tdep.c b/gdb/i386-netbsd-tdep.c
index 2cee1b94760..a9ebc3dd827 100644
--- a/gdb/i386-netbsd-tdep.c
+++ b/gdb/i386-netbsd-tdep.c
@@ -372,7 +372,7 @@ i386nbsd_sigtramp_cache_init (const struct tramp_frame *self,
 static void 
 i386nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* Obviously NetBSD is BSD-based.  */
   i386bsd_init_abi (info, gdbarch);
@@ -407,7 +407,7 @@ i386nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 static void
 i386nbsdelf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* It's still NetBSD.  */
   i386nbsd_init_abi (info, gdbarch);
diff --git a/gdb/i386-nto-tdep.c b/gdb/i386-nto-tdep.c
index 6716329149b..259867f262b 100644
--- a/gdb/i386-nto-tdep.c
+++ b/gdb/i386-nto-tdep.c
@@ -77,7 +77,7 @@ static void
 i386nto_supply_gregset (struct regcache *regcache, char *gpregs)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   gdb_assert (tdep->gregset_reg_offset == i386nto_gregset_reg_offset);
   i386_gregset.supply_regset (&i386_gregset, regcache, -1,
@@ -126,7 +126,7 @@ static int
 i386nto_register_area (struct gdbarch *gdbarch,
 		       int regno, int regset, unsigned *off)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   *off = 0;
   if (regset == NTO_REG_GENERAL)
@@ -315,7 +315,7 @@ init_i386nto_ops (void)
 static void
 i386nto_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   static struct target_so_ops nto_svr4_so_ops;
 
   /* Deal with our strange signals.  */
diff --git a/gdb/i386-obsd-tdep.c b/gdb/i386-obsd-tdep.c
index b1f4d6c5e8d..798094509c6 100644
--- a/gdb/i386-obsd-tdep.c
+++ b/gdb/i386-obsd-tdep.c
@@ -407,7 +407,7 @@ static const struct frame_unwind i386obsd_trapframe_unwind = {
 static void 
 i386obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* Obviously OpenBSD is BSD-based.  */
   i386bsd_init_abi (info, gdbarch);
diff --git a/gdb/i386-sol2-tdep.c b/gdb/i386-sol2-tdep.c
index e8a3ba20045..5ee108d3578 100644
--- a/gdb/i386-sol2-tdep.c
+++ b/gdb/i386-sol2-tdep.c
@@ -65,7 +65,7 @@ i386_sol2_mcontext_addr (struct frame_info *this_frame)
 static void
 i386_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* Solaris is SVR4-based.  */
   i386_svr4_init_abi (info, gdbarch);
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 8501e12e241..d500f6998c5 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -169,7 +169,7 @@ const int num_lower_zmm_regs = 16;
 static int
 i386_mmx_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int mm0_regnum = tdep->mm0_regnum;
 
   if (mm0_regnum < 0)
@@ -184,7 +184,7 @@ i386_mmx_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_byte_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   regnum -= tdep->al_regnum;
   return regnum >= 0 && regnum < tdep->num_byte_regs;
@@ -195,7 +195,7 @@ i386_byte_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_word_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   regnum -= tdep->ax_regnum;
   return regnum >= 0 && regnum < tdep->num_word_regs;
@@ -206,7 +206,7 @@ i386_word_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_dword_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int eax_regnum = tdep->eax_regnum;
 
   if (eax_regnum < 0)
@@ -221,7 +221,7 @@ i386_dword_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_zmmh_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int zmm0h_regnum = tdep->zmm0h_regnum;
 
   if (zmm0h_regnum < 0)
@@ -234,7 +234,7 @@ i386_zmmh_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_zmm_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int zmm0_regnum = tdep->zmm0_regnum;
 
   if (zmm0_regnum < 0)
@@ -247,7 +247,7 @@ i386_zmm_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_k_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int k0_regnum = tdep->k0_regnum;
 
   if (k0_regnum < 0)
@@ -260,7 +260,7 @@ i386_k_regnum_p (struct gdbarch *gdbarch, int regnum)
 static int
 i386_ymmh_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int ymm0h_regnum = tdep->ymm0h_regnum;
 
   if (ymm0h_regnum < 0)
@@ -275,7 +275,7 @@ i386_ymmh_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_ymm_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int ymm0_regnum = tdep->ymm0_regnum;
 
   if (ymm0_regnum < 0)
@@ -288,7 +288,7 @@ i386_ymm_regnum_p (struct gdbarch *gdbarch, int regnum)
 static int
 i386_ymmh_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int ymm16h_regnum = tdep->ymm16h_regnum;
 
   if (ymm16h_regnum < 0)
@@ -301,7 +301,7 @@ i386_ymmh_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_ymm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int ymm16_regnum = tdep->ymm16_regnum;
 
   if (ymm16_regnum < 0)
@@ -316,7 +316,7 @@ i386_ymm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_bnd_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int bnd0_regnum = tdep->bnd0_regnum;
 
   if (bnd0_regnum < 0)
@@ -331,7 +331,7 @@ i386_bnd_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_xmm_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int num_xmm_regs = I387_NUM_XMM_REGS (tdep);
 
   if (num_xmm_regs == 0)
@@ -346,7 +346,7 @@ i386_xmm_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_xmm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int num_xmm_avx512_regs = I387_NUM_XMM_AVX512_REGS (tdep);
 
   if (num_xmm_avx512_regs == 0)
@@ -359,7 +359,7 @@ i386_xmm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 static int
 i386_mxcsr_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (I387_NUM_XMM_REGS (tdep) == 0)
     return 0;
@@ -372,7 +372,7 @@ i386_mxcsr_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_fp_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (I387_ST0_REGNUM (tdep) < 0)
     return 0;
@@ -384,7 +384,7 @@ i386_fp_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_fpc_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (I387_ST0_REGNUM (tdep) < 0)
     return 0;
@@ -398,7 +398,7 @@ i386_fpc_regnum_p (struct gdbarch *gdbarch, int regnum)
 static int
 i386_bndr_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
    if (I387_BND0R_REGNUM (tdep) < 0)
      return 0;
@@ -412,7 +412,7 @@ i386_bndr_regnum_p (struct gdbarch *gdbarch, int regnum)
 static int
 i386_mpx_ctrl_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
    if (I387_BNDCFGU_REGNUM (tdep) < 0)
      return 0;
@@ -426,7 +426,7 @@ i386_mpx_ctrl_regnum_p (struct gdbarch *gdbarch, int regnum)
 bool
 i386_pkru_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int pkru_regnum = tdep->pkru_regnum;
 
   if (pkru_regnum < 0)
@@ -462,7 +462,7 @@ i386_register_name (struct gdbarch *gdbarch, int regnum)
 const char *
 i386_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   if (i386_bnd_regnum_p (gdbarch, regnum))
     return i386_bnd_names[regnum - tdep->bnd0_regnum];
   if (i386_mmx_regnum_p (gdbarch, regnum))
@@ -485,7 +485,7 @@ i386_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 static int
 i386_dbx_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* This implements what GCC calls the "default" register map
      (dbx_register_map[]).  */
@@ -532,7 +532,7 @@ i386_dbx_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 static int
 i386_svr4_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* This implements the GCC register map that tries to be compatible
      with the SVR4 C compiler for DWARF (svr4_dbx_register_map[]).  */
@@ -2434,7 +2434,7 @@ static struct i386_frame_cache *
 i386_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct i386_frame_cache *cache;
   CORE_ADDR addr;
@@ -2524,7 +2524,7 @@ i386_sigtramp_frame_sniffer (const struct frame_unwind *self,
 			     void **this_prologue_cache)
 {
   gdbarch *arch = get_frame_arch (this_frame);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
 
   /* We shouldn't even bother if we don't have a sigcontext_addr
      handler.  */
@@ -2611,7 +2611,7 @@ i386_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
   CORE_ADDR sp, jb_addr;
   struct gdbarch *gdbarch = get_frame_arch (frame);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int jb_pc_offset = tdep->jb_pc_offset;
 
   /* If JB_PC_OFFSET is -1, we have no way to find out where the
@@ -2860,7 +2860,7 @@ static void
 i386_extract_return_value (struct gdbarch *gdbarch, struct type *type,
 			   struct regcache *regcache, gdb_byte *valbuf)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int len = TYPE_LENGTH (type);
   gdb_byte buf[I386_MAX_REGISTER_SIZE];
 
@@ -2918,7 +2918,7 @@ static void
 i386_store_return_value (struct gdbarch *gdbarch, struct type *type,
 			 struct regcache *regcache, const gdb_byte *valbuf)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int len = TYPE_LENGTH (type);
 
   if (type->code () == TYPE_CODE_FLT)
@@ -2997,7 +2997,7 @@ static const char *struct_convention = default_struct_convention;
 static int
 i386_reg_struct_return_p (struct gdbarch *gdbarch, struct type *type)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   enum type_code code = type->code ();
   int len = TYPE_LENGTH (type);
 
@@ -3099,7 +3099,7 @@ i386_return_value (struct gdbarch *gdbarch, struct value *function,
 struct type *
 i387_ext_type (struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (!tdep->i387_ext_type)
     {
@@ -3117,7 +3117,7 @@ i387_ext_type (struct gdbarch *gdbarch)
 static struct type *
 i386_bnd_type (struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
 
   if (!tdep->i386_bnd_type)
@@ -3153,7 +3153,7 @@ i386_bnd_type (struct gdbarch *gdbarch)
 static struct type *
 i386_zmm_type (struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (!tdep->i386_zmm_type)
     {
@@ -3212,7 +3212,7 @@ i386_zmm_type (struct gdbarch *gdbarch)
 static struct type *
 i386_ymm_type (struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (!tdep->i386_ymm_type)
     {
@@ -3269,7 +3269,7 @@ i386_ymm_type (struct gdbarch *gdbarch)
 static struct type *
 i386_mmx_type (struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (!tdep->i386_mmx_type)
     {
@@ -3346,7 +3346,7 @@ static int
 i386_mmx_regnum_to_fp_regnum (readable_regcache *regcache, int regnum)
 {
   gdbarch *arch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
   int mmxreg, fpreg;
   ULONGEST fstat;
   int tos;
@@ -3387,7 +3387,7 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
     }
   else
     {
-      i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
       if (i386_bnd_regnum_p (gdbarch, regnum))
 	{
 	  regnum -= tdep->bnd0_regnum;
@@ -3577,7 +3577,7 @@ i386_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
     }
   else
     {
-      i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
       if (i386_bnd_regnum_p (gdbarch, regnum))
 	{
@@ -3685,7 +3685,7 @@ int
 i386_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				 struct agent_expr *ax, int regnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (i386_mmx_regnum_p (gdbarch, regnum))
     {
@@ -3902,7 +3902,7 @@ i386_supply_gregset (const struct regset *regset, struct regcache *regcache,
 		     int regnum, const void *gregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   const gdb_byte *regs = (const gdb_byte *) gregs;
   int i;
 
@@ -3927,7 +3927,7 @@ i386_collect_gregset (const struct regset *regset,
 		      int regnum, void *gregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   gdb_byte *regs = (gdb_byte *) gregs;
   int i;
 
@@ -3950,7 +3950,7 @@ i386_supply_fpregset (const struct regset *regset, struct regcache *regcache,
 		      int regnum, const void *fpregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (len == I387_SIZEOF_FXSAVE)
     {
@@ -3973,7 +3973,7 @@ i386_collect_fpregset (const struct regset *regset,
 		       int regnum, void *fpregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (len == I387_SIZEOF_FXSAVE)
     {
@@ -4005,7 +4005,7 @@ i386_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				   void *cb_data,
 				   const struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   cb (".reg", tdep->sizeof_gregset, tdep->sizeof_gregset, &i386_gregset, NULL,
       cb_data);
@@ -4510,7 +4510,7 @@ i386_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 void
 i386_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* System V Release 4 uses ELF.  */
   i386_elf_init_abi (info, gdbarch);
@@ -4552,7 +4552,7 @@ int
 i386_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 			  const struct reggroup *group)
 {
-  const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int fp_regnum_p, mmx_regnum_p, xmm_regnum_p, mxcsr_regnum_p,
       ymm_regnum_p, ymmh_regnum_p, ymm_avx512_regnum_p, ymmh_avx512_regnum_p,
       bndr_regnum_p, bnd_regnum_p, zmm_regnum_p, zmmh_regnum_p,
@@ -4997,7 +4997,7 @@ static int i386_record_floats (struct gdbarch *gdbarch,
 			       struct i386_record_s *ir,
 			       uint32_t iregnum)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   int i;
 
   /* Oza: Because of floating point insn push/pop of fpu stack is going to
@@ -5068,7 +5068,7 @@ i386_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
   ULONGEST addr;
   gdb_byte buf[I386_MAX_REGISTER_SIZE];
   struct i386_record_s ir;
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   uint8_t rex_w = -1;
   uint8_t rex_r = 0;
 
@@ -8839,7 +8839,7 @@ i386_mpx_bd_base (void)
 
   rcache = get_current_regcache ();
   gdbarch *arch = rcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
 
   regstatus = regcache_raw_read_unsigned (rcache, tdep->bndcfgu_regnum, &ret);
 
@@ -8853,7 +8853,7 @@ int
 i386_mpx_enabled (void)
 {
   gdbarch *arch = get_current_arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
   const struct target_desc *tdesc = tdep->tdesc;
 
   return (tdesc_find_feature (tdesc, "org.gnu.gdb.i386.mpx") != NULL);
diff --git a/gdb/i386-windows-tdep.c b/gdb/i386-windows-tdep.c
index 8e1cc17b91c..9eec6e28109 100644
--- a/gdb/i386-windows-tdep.c
+++ b/gdb/i386-windows-tdep.c
@@ -136,7 +136,7 @@ i386_windows_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 static void
 i386_windows_init_abi_common (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   set_gdbarch_skip_trampoline_code (gdbarch, i386_windows_skip_trampoline_code);
 
diff --git a/gdb/i387-tdep.c b/gdb/i387-tdep.c
index f056ea59347..42ed4eebc2c 100644
--- a/gdb/i387-tdep.c
+++ b/gdb/i387-tdep.c
@@ -204,7 +204,7 @@ void
 i387_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
 		       struct frame_info *frame, const char *args)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   ULONGEST fctrl;
   int fctrl_p;
   ULONGEST fstat;
@@ -440,7 +440,7 @@ void
 i387_supply_fsave (struct regcache *regcache, int regnum, const void *fsave)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   const gdb_byte *regs = (const gdb_byte *) fsave;
   int i;
@@ -495,7 +495,7 @@ void
 i387_collect_fsave (const struct regcache *regcache, int regnum, void *fsave)
 {
   gdbarch *arch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
   gdb_byte *regs = (gdb_byte *) fsave;
   int i;
 
@@ -589,7 +589,7 @@ void
 i387_supply_fxsave (struct regcache *regcache, int regnum, const void *fxsave)
 {
   gdbarch *arch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
   const gdb_byte *regs = (const gdb_byte *) fxsave;
   int i;
 
@@ -673,7 +673,7 @@ void
 i387_collect_fxsave (const struct regcache *regcache, int regnum, void *fxsave)
 {
   gdbarch *arch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
   gdb_byte *regs = (gdb_byte *) fxsave;
   int i;
 
@@ -906,7 +906,7 @@ i387_xsave_get_clear_bv (struct gdbarch *gdbarch, const void *xsave)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   const gdb_byte *regs = (const gdb_byte *) xsave;
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   /* Get `xstat_bv'.  The supported bits in `xstat_bv' are 8 bytes.  */
   ULONGEST xstate_bv = extract_unsigned_integer (XSAVE_XSTATE_BV_ADDR (regs),
@@ -926,7 +926,7 @@ i387_supply_xsave (struct regcache *regcache, int regnum,
 {
   struct gdbarch *gdbarch = regcache->arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   const gdb_byte *regs = (const gdb_byte *) xsave;
   int i;
   /* In 64-bit mode the split between "low" and "high" ZMM registers is at
@@ -1349,7 +1349,7 @@ i387_collect_xsave (const struct regcache *regcache, int regnum,
 {
   struct gdbarch *gdbarch = regcache->arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   gdb_byte *p, *regs = (gdb_byte *) xsave;
   gdb_byte raw[I386_MAX_REGISTER_SIZE];
   ULONGEST initial_xstate_bv, clear_bv, xstate_bv = 0;
@@ -1934,7 +1934,7 @@ i387_tag (const gdb_byte *raw)
 void
 i387_return_value (struct gdbarch *gdbarch, struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
   ULONGEST fstat;
 
   /* Set the top of the floating-point register stack to 7.  The
@@ -1957,7 +1957,7 @@ i387_return_value (struct gdbarch *gdbarch, struct regcache *regcache)
 void
 i387_reset_bnd_regs (struct gdbarch *gdbarch, struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   if (I387_BND0R_REGNUM (tdep) > 0)
     {
diff --git a/gdb/ia64-linux-tdep.c b/gdb/ia64-linux-tdep.c
index 64a57f5bf2f..508d4e6f7c6 100644
--- a/gdb/ia64-linux-tdep.c
+++ b/gdb/ia64-linux-tdep.c
@@ -216,7 +216,7 @@ ia64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 static void
 ia64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
   static const char *const stap_register_prefixes[] = { "r", NULL };
   static const char *const stap_register_indirection_prefixes[] = { "[",
 								    NULL };
diff --git a/gdb/ia64-tdep.c b/gdb/ia64-tdep.c
index 82456dc9c98..de343cfe17d 100644
--- a/gdb/ia64-tdep.c
+++ b/gdb/ia64-tdep.c
@@ -310,7 +310,7 @@ static const struct floatformat *floatformats_ia64_ext[2] =
 static struct type *
 ia64_ext_type (struct gdbarch *gdbarch)
 {
-  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
 
   if (!tdep->ia64_ext_type)
     tdep->ia64_ext_type
@@ -2177,7 +2177,7 @@ ia64_sigtramp_frame_init_saved_regs (struct frame_info *this_frame,
 				     struct ia64_frame_cache *cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
 
   if (tdep->sigcontext_register_address)
     {
@@ -2336,7 +2336,7 @@ ia64_sigtramp_frame_sniffer (const struct frame_unwind *self,
 			     void **this_cache)
 {
   gdbarch *arch = get_frame_arch (this_frame);
-  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (arch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (arch);
   if (tdep->pc_in_sigtramp)
     {
       CORE_ADDR pc = get_frame_pc (this_frame);
@@ -2485,7 +2485,7 @@ ia64_access_reg (unw_addr_space_t as, unw_regnum_t uw_regnum, unw_word_t *val,
   unw_word_t bsp, sof, cfm, psr, ip;
   struct frame_info *this_frame = (struct frame_info *) arg;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
   
   /* We never call any libunwind routines that need to write registers.  */
   gdb_assert (!write);
@@ -3484,7 +3484,7 @@ ia64_find_global_pointer_from_dynamic_section (struct gdbarch *gdbarch,
 static CORE_ADDR
 ia64_find_global_pointer (struct gdbarch *gdbarch, CORE_ADDR faddr)
 {
-  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
   CORE_ADDR addr = 0;
 
   if (tdep->find_global_pointer_from_solib)
@@ -3679,7 +3679,7 @@ ia64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 		      function_call_return_method return_method,
 		      CORE_ADDR struct_addr)
 {
-  ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int argno;
   struct value *arg;
diff --git a/gdb/loongarch-linux-tdep.c b/gdb/loongarch-linux-tdep.c
index 21fc67f9323..2fd70a06123 100644
--- a/gdb/loongarch-linux-tdep.c
+++ b/gdb/loongarch-linux-tdep.c
@@ -188,7 +188,7 @@ loongarch_linux_syscall_next_pc (struct frame_info *frame)
 static void
 loongarch_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  loongarch_gdbarch_tdep *tdep = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/loongarch-tdep.c b/gdb/loongarch-tdep.c
index f2f4e3be909..57c5fcabb99 100644
--- a/gdb/loongarch-tdep.c
+++ b/gdb/loongarch-tdep.c
@@ -225,7 +225,7 @@ static CORE_ADDR
 loongarch_next_pc (struct regcache *regcache, CORE_ADDR cur_pc)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  loongarch_gdbarch_tdep *tdep = (loongarch_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  loongarch_gdbarch_tdep *tdep = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
   insn_t insn = loongarch_fetch_instruction (cur_pc);
   size_t insn_len = loongarch_insn_length (insn);
   CORE_ADDR next_pc = cur_pc + insn_len;
@@ -605,7 +605,7 @@ loongarch_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 	 we are looking for.  If it doesn't then we can't reuse this
 	 gdbarch.  */
       loongarch_gdbarch_tdep *candidate_tdep
-	= (loongarch_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<loongarch_gdbarch_tdep> (arches->gdbarch);
 
       if (candidate_tdep->abi_features != abi_features)
 	continue;
diff --git a/gdb/m32c-tdep.c b/gdb/m32c-tdep.c
index 4971be796cd..37456d16cb3 100644
--- a/gdb/m32c-tdep.c
+++ b/gdb/m32c-tdep.c
@@ -142,7 +142,7 @@ struct m32c_gdbarch_tdep : gdbarch_tdep
 static void
 make_types (struct gdbarch *arch)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   unsigned long mach = gdbarch_bfd_arch_info (arch)->mach;
   int data_addr_reg_bits, code_addr_reg_bits;
   char type_name[50];
@@ -215,7 +215,7 @@ make_types (struct gdbarch *arch)
 static const char *
 m32c_register_name (struct gdbarch *gdbarch, int num)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   return tdep->regs[num].name;
 }
 
@@ -223,7 +223,7 @@ m32c_register_name (struct gdbarch *gdbarch, int num)
 static struct type *
 m32c_register_type (struct gdbarch *arch, int reg_nr)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   return tdep->regs[reg_nr].type;
 }
 
@@ -231,7 +231,7 @@ m32c_register_type (struct gdbarch *arch, int reg_nr)
 static int
 m32c_register_sim_regno (struct gdbarch *gdbarch, int reg_nr)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   return tdep->regs[reg_nr].sim_num;
 }
 
@@ -239,7 +239,7 @@ m32c_register_sim_regno (struct gdbarch *gdbarch, int reg_nr)
 static int
 m32c_debug_info_reg_to_regnum (struct gdbarch *gdbarch, int reg_nr)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   if (0 <= reg_nr && reg_nr <= M32C_MAX_DWARF_REGNUM
       && tdep->dwarf_regs[reg_nr])
     return tdep->dwarf_regs[reg_nr]->num;
@@ -254,7 +254,7 @@ static int
 m32c_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 			  const struct reggroup *group)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   struct m32c_reg *reg = &tdep->regs[regnum];
 
   /* The anonymous raw registers aren't in any groups.  */
@@ -330,7 +330,7 @@ static int
 m32c_read_flg (readable_regcache *cache)
 {
   gdbarch *arch = cache->arch ();
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   ULONGEST flg;
 
   cache->raw_read (tdep->flg->num, &flg);
@@ -530,7 +530,7 @@ static enum register_status
 m32c_r3r2r1r0_read (struct m32c_reg *reg, readable_regcache *cache, gdb_byte *buf)
 {
   gdbarch *arch = reg->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   int len = TYPE_LENGTH (tdep->r0->type);
   enum register_status status;
 
@@ -567,7 +567,7 @@ m32c_r3r2r1r0_write (struct m32c_reg *reg, struct regcache *cache,
 		     const gdb_byte *buf)
 {
   gdbarch *arch = reg->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   int len = TYPE_LENGTH (tdep->r0->type);
 
   if (gdbarch_byte_order (reg->arch) == BFD_ENDIAN_BIG)
@@ -595,7 +595,7 @@ m32c_pseudo_register_read (struct gdbarch *arch,
 			   int cookednum,
 			   gdb_byte *buf)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   struct m32c_reg *reg;
 
   gdb_assert (0 <= cookednum && cookednum < tdep->num_regs);
@@ -613,7 +613,7 @@ m32c_pseudo_register_write (struct gdbarch *arch,
 			    int cookednum,
 			    const gdb_byte *buf)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   struct m32c_reg *reg;
 
   gdb_assert (0 <= cookednum && cookednum < tdep->num_regs);
@@ -638,7 +638,7 @@ add_reg (struct gdbarch *arch,
 	 struct m32c_reg *ry,
 	 int n)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   struct m32c_reg *r = &tdep->regs[tdep->num_regs];
 
   gdb_assert (tdep->num_regs < M32C_MAX_NUM_REGS);
@@ -678,7 +678,7 @@ set_dwarf_regnum (struct m32c_reg *reg, int num)
 
   /* Update the DWARF->reg mapping.  */
   gdbarch *arch = reg->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   tdep->dwarf_regs[num] = reg;
 }
 
@@ -800,7 +800,7 @@ mark_save_restore (struct m32c_reg *reg)
 static void
 make_regs (struct gdbarch *arch)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   int mach = gdbarch_bfd_arch_info (arch)->mach;
   int num_raw_regs;
   int num_cooked_regs;
@@ -1349,7 +1349,7 @@ m32c_pv_enter (struct m32c_pv_state *state, int size)
     return 1;
 
   gdbarch *arch = state->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   if (m32c_pv_push (state, state->fb, tdep->push_addr_bytes))
     return 1;
 
@@ -1379,7 +1379,7 @@ static int
 m32c_pv_pushm (struct m32c_pv_state *state, int src)
 {
   gdbarch *arch = state->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   /* The bits in SRC indicating which registers to save are:
      r0 r1 r2 r3 a0 a1 sb fb */
@@ -1400,7 +1400,7 @@ static int
 m32c_is_1st_arg_reg (struct m32c_pv_state *state, pv_t value)
 {
   gdbarch *arch = state->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   return (value.kind == pvk_register
 	  && (gdbarch_bfd_arch_info (state->arch)->mach == bfd_mach_m16c
@@ -1415,7 +1415,7 @@ static int
 m32c_is_arg_reg (struct m32c_pv_state *state, pv_t value)
 {
   gdbarch *arch = state->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   return (value.kind == pvk_register
 	  && (gdbarch_bfd_arch_info (state->arch)->mach == bfd_mach_m16c
@@ -1440,7 +1440,7 @@ m32c_is_arg_spill (struct m32c_pv_state *st,
 		   pv_t value)
 {
   gdbarch *arch = st->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   return (m32c_is_arg_reg (st, value)
 	  && loc.kind == srcdest_mem
@@ -1464,7 +1464,7 @@ m32c_is_struct_return (struct m32c_pv_state *st,
 		       pv_t value)
 {
   gdbarch *arch = st->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   return (m32c_is_1st_arg_reg (st, value)
 	  && !st->stack->find_reg (st->arch, value.reg, 0)
@@ -1482,7 +1482,7 @@ static int
 m32c_pushm_is_reg_save (struct m32c_pv_state *st, int src)
 {
   gdbarch *arch = st->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   /* The bits in SRC indicating which registers to save are:
      r0 r1 r2 r3 a0 a1 sb fb */
@@ -1510,7 +1510,7 @@ check_for_saved (void *prologue_untyped, pv_t addr, CORE_ADDR size, pv_t value)
 {
   struct m32c_prologue *prologue = (struct m32c_prologue *) prologue_untyped;
   struct gdbarch *arch = prologue->arch;
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   /* Is this the unchanged value of some register being saved on the
      stack?  */
@@ -1550,7 +1550,7 @@ m32c_analyze_prologue (struct gdbarch *arch,
 		       CORE_ADDR start, CORE_ADDR limit,
 		       struct m32c_prologue *prologue)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   unsigned long mach = gdbarch_bfd_arch_info (arch)->mach;
   CORE_ADDR after_last_frame_related_insn;
   struct m32c_pv_state st;
@@ -1881,7 +1881,7 @@ m32c_frame_base (struct frame_info *this_frame,
   struct m32c_prologue *p
     = m32c_analyze_frame_prologue (this_frame, this_prologue_cache);
   gdbarch *arch = get_frame_arch (this_frame);
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
 
   /* In functions that use alloca, the distance between the stack
      pointer and the frame base varies dynamically, so we can't use
@@ -1932,7 +1932,7 @@ m32c_prev_register (struct frame_info *this_frame,
 		    void **this_prologue_cache, int regnum)
 {
   gdbarch *arch = get_frame_arch (this_frame);
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
   struct m32c_prologue *p
     = m32c_analyze_frame_prologue (this_frame, this_prologue_cache);
   CORE_ADDR frame_base = m32c_frame_base (this_frame, this_prologue_cache);
@@ -2015,7 +2015,7 @@ m32c_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 		      function_call_return_method return_method,
 		      CORE_ADDR struct_addr)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   unsigned long mach = gdbarch_bfd_arch_info (gdbarch)->mach;
   CORE_ADDR cfa;
@@ -2178,7 +2178,7 @@ m32c_return_value (struct gdbarch *gdbarch,
 		   gdb_byte *readbuf,
 		   const gdb_byte *writebuf)
 {
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   enum return_value_convention conv;
   ULONGEST valtype_len = TYPE_LENGTH (valtype);
@@ -2309,7 +2309,7 @@ static CORE_ADDR
 m32c_skip_trampoline_code (struct frame_info *frame, CORE_ADDR stop_pc)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   /* It would be nicer to simply look up the addresses of known
@@ -2555,7 +2555,7 @@ m32c_virtual_frame_pointer (struct gdbarch *gdbarch, CORE_ADDR pc,
   struct m32c_prologue p;
 
   struct regcache *regcache = get_current_regcache ();
-  m32c_gdbarch_tdep *tdep = (m32c_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
   
   if (!find_pc_partial_function (pc, &name, &func_addr, &func_end))
     internal_error (__FILE__, __LINE__,
diff --git a/gdb/m68hc11-tdep.c b/gdb/m68hc11-tdep.c
index 98f1367423e..9eb18b937be 100644
--- a/gdb/m68hc11-tdep.c
+++ b/gdb/m68hc11-tdep.c
@@ -146,14 +146,14 @@ struct m68gc11_gdbarch_tdep : gdbarch_tdep
 static int
 stack_correction (gdbarch *arch)
 {
-  m68gc11_gdbarch_tdep *tdep = (m68gc11_gdbarch_tdep *) gdbarch_tdep (arch);
+  m68gc11_gdbarch_tdep *tdep = gdbarch_tdep<m68gc11_gdbarch_tdep> (arch);
   return tdep->stack_correction;
 }
 
 static int
 use_page_register (gdbarch *arch)
 {
-  m68gc11_gdbarch_tdep *tdep = (m68gc11_gdbarch_tdep *) gdbarch_tdep (arch);
+  m68gc11_gdbarch_tdep *tdep = gdbarch_tdep<m68gc11_gdbarch_tdep> (arch);
   return tdep->stack_correction;
 }
 
@@ -642,7 +642,7 @@ m68hc11_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
       return pc;
     }
 
-  m68gc11_gdbarch_tdep *tdep = (m68gc11_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68gc11_gdbarch_tdep *tdep = gdbarch_tdep<m68gc11_gdbarch_tdep> (gdbarch);
   seq_table = tdep->prologue;
   
   /* The 68hc11 stack is as follows:
@@ -1020,7 +1020,7 @@ m68hc11_print_register (struct gdbarch *gdbarch, struct ui_file *file,
   else
     {
       m68gc11_gdbarch_tdep *tdep
-	= (m68gc11_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	= gdbarch_tdep<m68gc11_gdbarch_tdep> (gdbarch);
 
       if (regno == HARD_PC_REGNUM && tdep->use_page_register)
 	{
@@ -1125,7 +1125,7 @@ m68hc11_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file,
       gdb_printf (file, " Y=");
       m68hc11_print_register (gdbarch, file, frame, HARD_Y_REGNUM);
   
-      m68gc11_gdbarch_tdep *tdep = (m68gc11_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      m68gc11_gdbarch_tdep *tdep = gdbarch_tdep<m68gc11_gdbarch_tdep> (gdbarch);
 
       if (tdep->use_page_register)
 	{
@@ -1417,7 +1417,7 @@ m68hc11_gdbarch_init (struct gdbarch_info info,
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       m68gc11_gdbarch_tdep *tdep
-	= (m68gc11_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<m68gc11_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->elf_flags != elf_flags)
 	continue;
diff --git a/gdb/m68k-bsd-tdep.c b/gdb/m68k-bsd-tdep.c
index 9ef70f0dda4..2614c223f8e 100644
--- a/gdb/m68k-bsd-tdep.c
+++ b/gdb/m68k-bsd-tdep.c
@@ -133,7 +133,7 @@ m68kbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 static void
 m68kbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   tdep->jb_pc = 5;
   tdep->jb_elt_size = 4;
diff --git a/gdb/m68k-linux-tdep.c b/gdb/m68k-linux-tdep.c
index 85ad4741b1f..28401d3ecc6 100644
--- a/gdb/m68k-linux-tdep.c
+++ b/gdb/m68k-linux-tdep.c
@@ -384,7 +384,7 @@ m68k_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 static void
 m68k_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/m68k-tdep.c b/gdb/m68k-tdep.c
index 568bde66f93..9e59f5904c3 100644
--- a/gdb/m68k-tdep.c
+++ b/gdb/m68k-tdep.c
@@ -70,7 +70,7 @@ typedef BP_MANIPULATION (m68k_break_insn) m68k_breakpoint;
 static struct type *
 m68k_ps_type (struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (!tdep->m68k_ps_type)
     {
@@ -99,7 +99,7 @@ m68k_ps_type (struct gdbarch *gdbarch)
 static struct type *
 m68881_ext_type (struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (!tdep->m68881_ext_type)
     tdep->m68881_ext_type
@@ -120,7 +120,7 @@ m68881_ext_type (struct gdbarch *gdbarch)
 static struct type *
 m68k_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (tdep->fpregs_present)
     {
@@ -171,7 +171,7 @@ static const char * const m68k_register_names[] = {
 static const char *
 m68k_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (regnum < 0 || regnum >= ARRAY_SIZE (m68k_register_names))
     internal_error (__FILE__, __LINE__,
@@ -191,7 +191,7 @@ static int
 m68k_convert_register_p (struct gdbarch *gdbarch,
 			 int regnum, struct type *type)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (!tdep->fpregs_present)
     return 0;
@@ -300,7 +300,7 @@ m68k_extract_return_value (struct type *type, struct regcache *regcache,
   if (type->code () == TYPE_CODE_PTR && len == 4)
     {
       struct gdbarch *gdbarch = regcache->arch ();
-      m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
       regcache->raw_read (tdep->pointer_result_regnum, valbuf);
     }
   else if (len <= 4)
@@ -325,7 +325,7 @@ m68k_svr4_extract_return_value (struct type *type, struct regcache *regcache,
 {
   gdb_byte buf[M68K_MAX_REGISTER_SIZE];
   struct gdbarch *gdbarch = regcache->arch ();
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (tdep->float_return && type->code () == TYPE_CODE_FLT)
     {
@@ -348,7 +348,7 @@ m68k_store_return_value (struct type *type, struct regcache *regcache,
   if (type->code () == TYPE_CODE_PTR && len == 4)
     {
       struct gdbarch *gdbarch = regcache->arch ();
-      m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
       regcache->raw_write (tdep->pointer_result_regnum, valbuf);
       /* gdb historically also set D0 in the SVR4 case.  */
       if (tdep->pointer_result_regnum != M68K_D0_REGNUM)
@@ -371,7 +371,7 @@ m68k_svr4_store_return_value (struct type *type, struct regcache *regcache,
 			      const gdb_byte *valbuf)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (tdep->float_return && type->code () == TYPE_CODE_FLT)
     {
@@ -391,7 +391,7 @@ m68k_svr4_store_return_value (struct type *type, struct regcache *regcache,
 static int
 m68k_reg_struct_return_p (struct gdbarch *gdbarch, struct type *type)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
   enum type_code code = type->code ();
   int len = TYPE_LENGTH (type);
 
@@ -469,7 +469,7 @@ m68k_svr4_return_value (struct gdbarch *gdbarch, struct value *function,
 			gdb_byte *readbuf, const gdb_byte *writebuf)
 {
   enum type_code code = type->code ();
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   /* Aggregates with a single member are always returned like their
      sole element.  */
@@ -541,7 +541,7 @@ m68k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 		      function_call_return_method return_method,
 		      CORE_ADDR struct_addr)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   gdb_byte buf[4];
   int i;
@@ -596,7 +596,7 @@ m68k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 static int
 m68k_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int num)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (num < 8)
     /* d0..7 */
@@ -766,7 +766,7 @@ m68k_analyze_register_saves (struct gdbarch *gdbarch, CORE_ADDR pc,
 			     struct m68k_frame_cache *cache)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (cache->locals >= 0)
     {
@@ -1058,7 +1058,7 @@ m68k_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
   gdb_byte *buf;
   CORE_ADDR sp, jb_addr;
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   if (tdep->jb_pc < 0)
@@ -1104,7 +1104,7 @@ m68k_return_in_first_hidden_param_p (struct gdbarch *gdbarch,
 void
 m68k_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   /* SVR4 uses a different calling convention.  */
   set_gdbarch_return_value (gdbarch, m68k_svr4_return_value);
@@ -1122,7 +1122,7 @@ m68k_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 static void
 m68k_embedded_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   m68k_svr4_init_abi (info, gdbarch);
   tdep->pointer_result_regnum = M68K_D0_REGNUM;
@@ -1237,7 +1237,7 @@ m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
     {
       m68k_gdbarch_tdep *tdep
-	= (m68k_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
+	= gdbarch_tdep<m68k_gdbarch_tdep> (best_arch->gdbarch);
 
       if (flavour != tdep->flavour)
 	continue;
@@ -1339,7 +1339,7 @@ m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 m68k_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  m68k_gdbarch_tdep *tdep = (m68k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
 
   if (tdep == NULL)
     return;
diff --git a/gdb/mep-tdep.c b/gdb/mep-tdep.c
index 6b3a62391c0..d5ba78c6df9 100644
--- a/gdb/mep-tdep.c
+++ b/gdb/mep-tdep.c
@@ -260,7 +260,7 @@ me_module_register_set (CONFIG_ATTR me_module,
        specifically excluding the generic coprocessor register sets.  */
 
   mep_gdbarch_tdep *tdep
-    = (mep_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+    = gdbarch_tdep<mep_gdbarch_tdep> (target_gdbarch ());
   CGEN_CPU_DESC desc = tdep->cpu_desc;
   const CGEN_HW_ENTRY *hw;
 
@@ -856,7 +856,7 @@ current_me_module (void)
   else
     {
       mep_gdbarch_tdep *tdep
-	= (mep_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+	= gdbarch_tdep<mep_gdbarch_tdep> (target_gdbarch ());
       return tdep->me_module;
     }
 }
@@ -2391,7 +2391,7 @@ mep_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       mep_gdbarch_tdep *tdep
-	= (mep_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<mep_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->me_module == me_module)
 	return arches->gdbarch;
diff --git a/gdb/mips-linux-tdep.c b/gdb/mips-linux-tdep.c
index d8f90ccf881..ca313a28279 100644
--- a/gdb/mips-linux-tdep.c
+++ b/gdb/mips-linux-tdep.c
@@ -1317,7 +1317,7 @@ mips_linux_get_syscall_number (struct gdbarch *gdbarch,
 			       thread_info *thread)
 {
   struct regcache *regcache = get_thread_regcache (thread);
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int regsize = register_size (gdbarch, MIPS_V0_REGNUM);
   /* The content of a register */
@@ -1527,7 +1527,7 @@ static void
 mips_linux_init_abi (struct gdbarch_info info,
 		     struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   enum mips_abi abi = mips_abi (gdbarch);
   struct tdesc_arch_data *tdesc_data = info.tdesc_data;
 
diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index 071319ccc73..ed4c23a07ff 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -227,7 +227,7 @@ static const char mips_disassembler_options_n64[] = "gpr-names=64";
 const struct mips_regnum *
 mips_regnum (struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   return tdep->regnum;
 }
 
@@ -252,7 +252,7 @@ mips_float_register_p (struct gdbarch *gdbarch, int regnum)
 static bool
 mips_eabi (gdbarch *arch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (arch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (arch);
   return (tdep->mips_abi == MIPS_ABI_EABI32 \
 	  || tdep->mips_abi == MIPS_ABI_EABI64);
 }
@@ -260,21 +260,21 @@ mips_eabi (gdbarch *arch)
 static int
 mips_last_fp_arg_regnum (gdbarch *arch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (arch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (arch);
   return tdep->mips_last_fp_arg_regnum;
 }
 
 static int
 mips_last_arg_regnum (gdbarch *arch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (arch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (arch);
   return tdep->mips_last_arg_regnum;
 }
 
 static enum mips_fpu_type
 mips_get_fpu_type (gdbarch *arch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (arch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (arch);
   return tdep->mips_fpu_type;
 }
 
@@ -282,14 +282,14 @@ mips_get_fpu_type (gdbarch *arch)
 enum mips_abi
 mips_abi (struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   return tdep->mips_abi;
 }
 
 int
 mips_isa_regsize (struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
   /* If we know how big the registers are, use that size.  */
   if (tdep->register_size_valid_p)
@@ -335,7 +335,7 @@ mips_abi_regsize (struct gdbarch *gdbarch)
 static int
 is_mips16_isa (struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   return tdep->mips_isa == ISA_MIPS16;
 }
 
@@ -344,7 +344,7 @@ is_mips16_isa (struct gdbarch *gdbarch)
 static int
 is_micromips_isa (struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   return tdep->mips_isa == ISA_MICROMIPS;
 }
 
@@ -636,7 +636,7 @@ static const char * const mips_linux_reg_names[NUM_MIPS_PROCESSOR_REGS] = {
 static const char *
 mips_register_name (struct gdbarch *gdbarch, int regno)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   /* GPR names for all ABIs other than n32/n64.  */
   static const char *mips_gpr_names[] = {
     "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
@@ -777,7 +777,7 @@ mips_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
   else if (register_size (gdbarch, rawnum) >
 	   register_size (gdbarch, cookednum))
     {
-      mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
       if (tdep->mips64_transfers_32bit_regs_p)
 	return regcache->raw_read_part (rawnum, 0, 4, buf);
@@ -810,7 +810,7 @@ mips_pseudo_register_write (struct gdbarch *gdbarch,
   else if (register_size (gdbarch, rawnum) >
 	   register_size (gdbarch, cookednum))
     {
-      mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
       if (tdep->mips64_transfers_32bit_regs_p)
 	regcache->raw_write_part (rawnum, 0, 4, buf);
@@ -855,7 +855,7 @@ mips_ax_pseudo_register_push_stack (struct gdbarch *gdbarch,
       if (register_size (gdbarch, rawnum) > register_size (gdbarch, reg))
 	{
 	  mips_gdbarch_tdep *tdep
-	    = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	    = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
 	  if (!tdep->mips64_transfers_32bit_regs_p
 	      || gdbarch_byte_order (gdbarch) != BFD_ENDIAN_BIG)
@@ -1059,7 +1059,7 @@ mips_register_type (struct gdbarch *gdbarch, int regnum)
   else
     {
       int rawnum = regnum - gdbarch_num_regs (gdbarch);
-      mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
       /* The cooked or ABI registers.  These are sized according to
 	 the ABI (with a few complications).  */
@@ -1191,7 +1191,7 @@ show_mask_address (struct ui_file *file, int from_tty,
       else
 	{
 	  mips_gdbarch_tdep *tdep
-	    = (mips_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
+	    = gdbarch_tdep<mips_gdbarch_tdep> (target_gdbarch ());
 
 	  if (mips_mask_address_p (tdep))
 	    additional_text = _(" (currently \"on\")");
@@ -1727,7 +1727,7 @@ mips32_next_pc (struct regcache *regcache, CORE_ADDR pc)
 	    case 12:            /* SYSCALL */
 	      {
 		mips_gdbarch_tdep *tdep
-		  = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+		  = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
 		if (tdep->syscall_next_pc != NULL)
 		  pc = tdep->syscall_next_pc (get_current_frame ());
@@ -1938,7 +1938,7 @@ micromips_next_pc (struct regcache *regcache, CORE_ADDR pc)
 		case 0x22d: /* SYSCALL:  000000 1000101101 111100 */
 		  {
 		    mips_gdbarch_tdep *tdep
-		      = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+		      = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
 		    if (tdep->syscall_next_pc != NULL)
 		      pc = tdep->syscall_next_pc (get_current_frame ());
@@ -3901,7 +3901,7 @@ mips_stub_frame_base_sniffer (struct frame_info *this_frame)
 static CORE_ADDR
 mips_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
   if (mips_mask_address_p (tdep) && (((ULONGEST) addr) >> 32 == 0xffffffffUL))
     /* This hack is a work-around for existing boards using PMON, the
@@ -4804,7 +4804,7 @@ mips_eabi_return_value (struct gdbarch *gdbarch, struct value *function,
 			struct type *type, struct regcache *regcache,
 			gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   int fp_return_type = 0;
   int offset, regnum, xfer;
 
@@ -5195,7 +5195,7 @@ mips_n32n64_return_value (struct gdbarch *gdbarch, struct value *function,
 			  struct type *type, struct regcache *regcache,
 			  gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
 
   /* From MIPSpro N32 ABI Handbook, Document Number: 007-2816-004
 
@@ -5704,7 +5704,7 @@ mips_o32_return_value (struct gdbarch *gdbarch, struct value *function,
 {
   CORE_ADDR func_addr = function ? find_function_addr (function, NULL) : 0;
   int mips16 = mips_pc_is_mips16 (gdbarch, func_addr);
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   enum mips_fval_reg fval_reg;
 
   fval_reg = readbuf ? mips16 ? mips_fval_gpr : mips_fval_fpr : mips_fval_both;
@@ -8101,7 +8101,7 @@ mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   else if (arches != NULL)
     {
       mips_gdbarch_tdep *tdep
-	= (mips_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<mips_gdbarch_tdep> (arches->gdbarch);
       elf_flags = tdep->elf_flags;
     }
   else
@@ -8142,7 +8142,7 @@ mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   if (found_abi == MIPS_ABI_UNKNOWN && info.abfd == NULL && arches != NULL)
     {
       mips_gdbarch_tdep *tdep
-	= (mips_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<mips_gdbarch_tdep> (arches->gdbarch);
       found_abi = tdep->found_abi;
     }
 
@@ -8459,7 +8459,7 @@ mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       mips_gdbarch_tdep *tdep
-        = (mips_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+        = gdbarch_tdep<mips_gdbarch_tdep> (arches->gdbarch);
 
       /* MIPS needs to be pedantic about which ABI and the compressed
 	 ISA variation the object is using.  */
@@ -8917,7 +8917,7 @@ mips_fpu_type_str (enum mips_fpu_type fpu_type)
 static void
 mips_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
   if (tdep != NULL)
     {
       int ef_mips_arch;
diff --git a/gdb/mn10300-tdep.c b/gdb/mn10300-tdep.c
index 7a41070bb30..22511d894d4 100644
--- a/gdb/mn10300-tdep.c
+++ b/gdb/mn10300-tdep.c
@@ -1412,7 +1412,7 @@ mn10300_gdbarch_init (struct gdbarch_info info,
 static void
 mn10300_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  mn10300_gdbarch_tdep *tdep = (mn10300_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  mn10300_gdbarch_tdep *tdep = gdbarch_tdep<mn10300_gdbarch_tdep> (gdbarch);
   gdb_printf (file, "mn10300_dump_tdep: am33_mode = %d\n",
 	      tdep->am33_mode);
 }
diff --git a/gdb/mn10300-tdep.h b/gdb/mn10300-tdep.h
index 10fef99c5d7..87b861ead90 100644
--- a/gdb/mn10300-tdep.h
+++ b/gdb/mn10300-tdep.h
@@ -84,7 +84,7 @@ struct mn10300_gdbarch_tdep : gdbarch_tdep
 static inline int
 get_am33_mode (gdbarch *arch)
 {
-  mn10300_gdbarch_tdep *tdep = (mn10300_gdbarch_tdep *) gdbarch_tdep (arch);
+  mn10300_gdbarch_tdep *tdep = gdbarch_tdep<mn10300_gdbarch_tdep> (arch);
   return tdep->am33_mode;
 }
 
diff --git a/gdb/msp430-tdep.c b/gdb/msp430-tdep.c
index 28268a95139..4ae8b3d5626 100644
--- a/gdb/msp430-tdep.c
+++ b/gdb/msp430-tdep.c
@@ -341,7 +341,7 @@ msp430_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc,
   int rn;
   pv_t reg[MSP430_NUM_TOTAL_REGS];
   CORE_ADDR after_last_frame_setup_insn = start_pc;
-  msp430_gdbarch_tdep *tdep = (msp430_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  msp430_gdbarch_tdep *tdep = gdbarch_tdep<msp430_gdbarch_tdep> (gdbarch);
   int code_model = tdep->code_model;
   int sz;
 
@@ -570,7 +570,7 @@ msp430_return_value (struct gdbarch *gdbarch,
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   LONGEST valtype_len = TYPE_LENGTH (valtype);
-  msp430_gdbarch_tdep *tdep = (msp430_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  msp430_gdbarch_tdep *tdep = gdbarch_tdep<msp430_gdbarch_tdep> (gdbarch);
   int code_model = tdep->code_model;
 
   if (TYPE_LENGTH (valtype) > 8
@@ -651,7 +651,7 @@ msp430_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   int write_pass;
   int sp_off = 0;
   CORE_ADDR cfa;
-  msp430_gdbarch_tdep *tdep = (msp430_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  msp430_gdbarch_tdep *tdep = gdbarch_tdep<msp430_gdbarch_tdep> (gdbarch);
   int code_model = tdep->code_model;
 
   struct type *func_type = value_type (function);
@@ -814,7 +814,7 @@ msp430_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
 
   stub_name = bms.minsym->linkage_name ();
 
-  msp430_gdbarch_tdep *tdep = (msp430_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  msp430_gdbarch_tdep *tdep = gdbarch_tdep<msp430_gdbarch_tdep> (gdbarch);
   if (tdep->code_model == MSP_SMALL_CODE_MODEL
       && msp430_in_return_stub (gdbarch, pc, stub_name))
     {
@@ -877,7 +877,7 @@ msp430_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 	  if (ca && gdbarch_bfd_arch_info (ca)->arch == bfd_arch_msp430)
 	    {
 	      msp430_gdbarch_tdep *ca_tdep
-		= (msp430_gdbarch_tdep *) gdbarch_tdep (ca);
+		= gdbarch_tdep<msp430_gdbarch_tdep> (ca);
 
 	      elf_flags = ca_tdep->elf_flags;
 	      isa = ca_tdep->isa;
@@ -904,7 +904,7 @@ msp430_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       msp430_gdbarch_tdep *candidate_tdep
-	= (msp430_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<msp430_gdbarch_tdep> (arches->gdbarch);
 
       if (candidate_tdep->elf_flags != elf_flags
 	  || candidate_tdep->isa != isa
diff --git a/gdb/nds32-tdep.c b/gdb/nds32-tdep.c
index e95ad7cc662..11bfd2d1f54 100644
--- a/gdb/nds32-tdep.c
+++ b/gdb/nds32-tdep.c
@@ -289,7 +289,7 @@ typedef BP_MANIPULATION (nds32_break_insn) nds32_breakpoint;
 static int
 nds32_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int num)
 {
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   const int FSR = 38;
   const int FDR = FSR + 32;
 
@@ -432,7 +432,7 @@ nds32_pseudo_register_read (struct gdbarch *gdbarch,
 			    readable_regcache *regcache, int regnum,
 			    gdb_byte *buf)
 {
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   gdb_byte reg_buf[8];
   int offset, fdr_regnum;
   enum register_status status;
@@ -471,7 +471,7 @@ nds32_pseudo_register_write (struct gdbarch *gdbarch,
 			     struct regcache *regcache, int regnum,
 			     const gdb_byte *buf)
 {
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   gdb_byte reg_buf[8];
   int offset, fdr_regnum;
 
@@ -608,7 +608,7 @@ static CORE_ADDR
 nds32_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
 			CORE_ADDR limit_pc, struct nds32_frame_cache *cache)
 {
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   /* Current scanning status.  */
   int in_prologue_bb = 0;
@@ -1169,7 +1169,7 @@ static int
 nds32_analyze_epilogue (struct gdbarch *gdbarch, CORE_ADDR pc,
 			struct nds32_frame_cache *cache)
 {
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   CORE_ADDR limit_pc;
   uint32_t insn, insn_len;
@@ -1220,7 +1220,7 @@ nds32_analyze_epilogue (struct gdbarch *gdbarch, CORE_ADDR pc,
 static int
 nds32_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   int insn_type = INSN_NORMAL;
   int ret_found = 0;
@@ -1424,7 +1424,7 @@ nds32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   int i;
   ULONGEST regval;
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   struct type *func_type = value_type (function);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   int abi_split = nds32_abi_split (tdep->elf_abi);
@@ -1652,7 +1652,7 @@ nds32_extract_return_value (struct gdbarch *gdbarch, struct type *type,
 			    struct regcache *regcache, gdb_byte *valbuf)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   int calling_use_fpr;
   int len;
@@ -1742,7 +1742,7 @@ nds32_store_return_value (struct gdbarch *gdbarch, struct type *type,
 			  struct regcache *regcache, const gdb_byte *valbuf)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  nds32_gdbarch_tdep *tdep = (nds32_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   int calling_use_fpr;
   int len;
@@ -1965,7 +1965,7 @@ nds32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
     {
       nds32_gdbarch_tdep *idep
-	= (nds32_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
+	= gdbarch_tdep<nds32_gdbarch_tdep> (best_arch->gdbarch);
 
       if (idep->elf_abi != elf_abi)
 	continue;
diff --git a/gdb/nios2-linux-tdep.c b/gdb/nios2-linux-tdep.c
index a32f79aa28a..da69638b20b 100644
--- a/gdb/nios2-linux-tdep.c
+++ b/gdb/nios2-linux-tdep.c
@@ -217,7 +217,7 @@ nios2_linux_is_kernel_helper (CORE_ADDR pc)
 static void
 nios2_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  nios2_gdbarch_tdep *tdep = (nios2_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nios2_gdbarch_tdep *tdep = gdbarch_tdep<nios2_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/nios2-tdep.c b/gdb/nios2-tdep.c
index 159d31b2d0f..0bad229b44a 100644
--- a/gdb/nios2-tdep.c
+++ b/gdb/nios2-tdep.c
@@ -2098,7 +2098,7 @@ static CORE_ADDR
 nios2_get_next_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  nios2_gdbarch_tdep *tdep = (nios2_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nios2_gdbarch_tdep *tdep = gdbarch_tdep<nios2_gdbarch_tdep> (gdbarch);
   unsigned long mach = gdbarch_bfd_arch_info (gdbarch)->mach;
   unsigned int insn;
   const struct nios2_opcode *op = nios2_fetch_insn (gdbarch, pc, &insn);
@@ -2221,7 +2221,7 @@ static int
 nios2_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  nios2_gdbarch_tdep *tdep = (nios2_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  nios2_gdbarch_tdep *tdep = gdbarch_tdep<nios2_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR jb_addr = get_frame_register_unsigned (frame, NIOS2_R4_REGNUM);
   gdb_byte buf[4];
diff --git a/gdb/or1k-tdep.c b/gdb/or1k-tdep.c
index 2b906fa69d3..4699b755d42 100644
--- a/gdb/or1k-tdep.c
+++ b/gdb/or1k-tdep.c
@@ -248,7 +248,7 @@ or1k_return_value (struct gdbarch *gdbarch, struct value *functype,
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   enum type_code rv_type = valtype->code ();
   unsigned int rv_size = TYPE_LENGTH (valtype);
-  or1k_gdbarch_tdep *tdep = (or1k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  or1k_gdbarch_tdep *tdep = gdbarch_tdep<or1k_gdbarch_tdep> (gdbarch);
   int bpw = tdep->bytes_per_word;
 
   /* Deal with struct/union as addresses.  If an array won't fit in a
@@ -353,7 +353,7 @@ or1k_delay_slot_p (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
   const CGEN_INSN *insn;
   CGEN_FIELDS tmp_fields;
-  or1k_gdbarch_tdep *tdep = (or1k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  or1k_gdbarch_tdep *tdep = gdbarch_tdep<or1k_gdbarch_tdep> (gdbarch);
 
   insn = cgen_lookup_insn (tdep->gdb_cgen_cpu_desc,
 			   NULL,
@@ -635,7 +635,7 @@ or1k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   int heap_offset = 0;
   CORE_ADDR heap_sp = sp - 128;
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  or1k_gdbarch_tdep *tdep = (or1k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  or1k_gdbarch_tdep *tdep = gdbarch_tdep<or1k_gdbarch_tdep> (gdbarch);
   int bpa = tdep->bytes_per_address;
   int bpw = tdep->bytes_per_word;
   struct type *func_type = value_type (function);
@@ -1273,7 +1273,7 @@ or1k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 or1k_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  or1k_gdbarch_tdep *tdep = (or1k_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  or1k_gdbarch_tdep *tdep = gdbarch_tdep<or1k_gdbarch_tdep> (gdbarch);
 
   if (NULL == tdep)
     return; /* Nothing to report */
diff --git a/gdb/ppc-fbsd-nat.c b/gdb/ppc-fbsd-nat.c
index ce045ac55ab..d0a5778e2d3 100644
--- a/gdb/ppc-fbsd-nat.c
+++ b/gdb/ppc-fbsd-nat.c
@@ -100,7 +100,7 @@ fill_fpregset (const struct regcache *regcache,
 static int
 getfpregs_supplies (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
 	 point registers.  Traditionally, GDB's register set has still
@@ -185,7 +185,7 @@ static int
 ppcfbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i, regnum;
 
   /* The stack pointer shouldn't be zero.  */
diff --git a/gdb/ppc-fbsd-tdep.c b/gdb/ppc-fbsd-tdep.c
index 4afcc3019a4..f5b482921a7 100644
--- a/gdb/ppc-fbsd-tdep.c
+++ b/gdb/ppc-fbsd-tdep.c
@@ -126,7 +126,7 @@ ppcfbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				      void *cb_data,
 				      const struct regcache *regcache)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (tdep->wordsize == 4)
     cb (".reg", 148, 148, &ppc32_fbsd_gregset, NULL, cb_data);
@@ -200,7 +200,7 @@ static struct trad_frame_cache *
 ppcfbsd_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   struct trad_frame_cache *cache;
   CORE_ADDR addr, base, func;
   gdb_byte buf[PPC_INSN_SIZE];
@@ -287,7 +287,7 @@ static CORE_ADDR
 ppcfbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 				  CORE_ADDR lm_addr, CORE_ADDR offset)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   struct regcache *regcache;
   int tp_offset, tp_regnum;
 
@@ -319,7 +319,7 @@ ppcfbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 static void
 ppcfbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support. */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c
index f959bb0c1ad..de4158c411a 100644
--- a/gdb/ppc-linux-nat.c
+++ b/gdb/ppc-linux-nat.c
@@ -649,7 +649,7 @@ static int
 ppc_register_u_addr (struct gdbarch *gdbarch, int regno)
 {
   int u_addr = -1;
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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 +802,7 @@ static void
 fetch_spe_register (struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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 +911,7 @@ static void
 fetch_register (struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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;
@@ -1156,7 +1156,7 @@ static void
 fetch_gp_regs (struct regcache *regcache, int tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   if (have_ptrace_getsetregs)
@@ -1208,7 +1208,7 @@ static void
 fetch_fp_regs (struct regcache *regcache, int tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   if (have_ptrace_getsetfpregs)
@@ -1226,7 +1226,7 @@ static void
 fetch_ppc_registers (struct regcache *regcache, int tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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 +1425,7 @@ static void
 store_spe_register (const struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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 +1477,7 @@ static void
 store_register (const struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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;
@@ -1718,7 +1718,7 @@ static void
 store_gp_regs (const struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   if (have_ptrace_getsetregs)
@@ -1780,7 +1780,7 @@ static void
 store_fp_regs (const struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   if (have_ptrace_getsetfpregs)
@@ -1798,7 +1798,7 @@ static void
 store_ppc_registers (const struct regcache *regcache, int tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_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)
diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c
index bf95f395515..cd1c176badf 100644
--- a/gdb/ppc-linux-tdep.c
+++ b/gdb/ppc-linux-tdep.c
@@ -332,7 +332,7 @@ ppc_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
 {
   unsigned int insnbuf[POWERPC32_PLT_CHECK_LEN];
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR target = 0;
   int scan_limit, i;
@@ -898,7 +898,7 @@ ppc_linux_vsxregset (void)
 const struct regset *
 ppc_linux_cgprregset (struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (tdep->wordsize == 4)
     {
@@ -938,7 +938,7 @@ ppc_linux_collect_core_cpgrregset (const struct regset *regset,
 				   int regnum, void *buf, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   const struct regset *cgprregset = ppc_linux_cgprregset (gdbarch);
 
@@ -985,7 +985,7 @@ ppc_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					void *cb_data,
 					const struct regcache *regcache)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int have_altivec = tdep->ppc_vr0_regnum != -1;
   int have_vsx = tdep->ppc_vsr0_upper_regnum != -1;
   int have_ppr = tdep->ppc_ppr_regnum != -1;
@@ -1170,7 +1170,7 @@ ppc_linux_sigtramp_cache (struct frame_info *this_frame,
   CORE_ADDR fpregs;
   int i;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   base = get_frame_register_unsigned (this_frame,
@@ -1341,7 +1341,7 @@ ppc_linux_get_syscall_number (struct gdbarch *gdbarch,
 			      thread_info *thread)
 {
   struct regcache *regcache = get_thread_regcache (thread);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   /* Make sure we're in a 32- or 64-bit machine */
@@ -1417,7 +1417,7 @@ static int
 ppc_linux_syscall_record (struct regcache *regcache)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   ULONGEST scnum;
   enum gdb_syscall syscall_gdb;
   int ret;
@@ -1507,7 +1507,7 @@ ppc_linux_record_signal (struct gdbarch *gdbarch, struct regcache *regcache,
   const int SIGNAL_FRAMESIZE = 128;
   const int sizeof_rt_sigframe = 1440 * 2 + 8 * 2 + 4 * 6 + 8 + 8 + 128 + 512;
   ULONGEST sp;
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   for (i = 3; i <= 12; i++)
@@ -2042,7 +2042,7 @@ static void
 ppc_linux_init_abi (struct gdbarch_info info,
 		    struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   struct tdesc_arch_data *tdesc_data = info.tdesc_data;
   static const char *const stap_integer_prefixes[] = { "i", NULL };
   static const char *const stap_register_indirection_prefixes[] = { "(",
diff --git a/gdb/ppc-netbsd-nat.c b/gdb/ppc-netbsd-nat.c
index fb2dce501a4..91f18fbb83f 100644
--- a/gdb/ppc-netbsd-nat.c
+++ b/gdb/ppc-netbsd-nat.c
@@ -52,7 +52,7 @@ static ppc_nbsd_nat_target the_ppc_nbsd_nat_target;
 static int
 getregs_supplies (struct gdbarch *gdbarch, int regnum)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   return ((regnum >= tdep->ppc_gp0_regnum
 	   && regnum < tdep->ppc_gp0_regnum + ppc_num_gprs)
@@ -68,7 +68,7 @@ getregs_supplies (struct gdbarch *gdbarch, int regnum)
 static int
 getfpregs_supplies (struct gdbarch *gdbarch, int regnum)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
      point registers.  Traditionally, GDB's register set has still
@@ -159,7 +159,7 @@ ppcnbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
   struct switchframe sf;
   struct callframe cf;
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   /* The stack pointer shouldn't be zero.  */
diff --git a/gdb/ppc-netbsd-tdep.c b/gdb/ppc-netbsd-tdep.c
index cb3d8d5e5df..d8dc494979a 100644
--- a/gdb/ppc-netbsd-tdep.c
+++ b/gdb/ppc-netbsd-tdep.c
@@ -102,7 +102,7 @@ ppcnbsd_sigtramp_cache_init (const struct tramp_frame *self,
 			     CORE_ADDR func)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   CORE_ADDR addr, base;
   int i;
 
diff --git a/gdb/ppc-obsd-nat.c b/gdb/ppc-obsd-nat.c
index 93e1024b589..e480f19dc73 100644
--- a/gdb/ppc-obsd-nat.c
+++ b/gdb/ppc-obsd-nat.c
@@ -54,7 +54,7 @@ static ppc_obsd_nat_target the_ppc_obsd_nat_target;
 static int
 getfpregs_supplies (struct gdbarch *gdbarch, int regnum)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
      point registers.  Traditionally, GDB's register set has still
@@ -154,7 +154,7 @@ static int
 ppcobsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   struct switchframe sf;
   struct callframe cf;
   int i, regnum;
diff --git a/gdb/ppc-obsd-tdep.c b/gdb/ppc-obsd-tdep.c
index a2924e35bbc..90fb5e3a399 100644
--- a/gdb/ppc-obsd-tdep.c
+++ b/gdb/ppc-obsd-tdep.c
@@ -161,7 +161,7 @@ static struct trad_frame_cache *
 ppcobsd_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct trad_frame_cache *cache;
   CORE_ADDR addr, base, func;
diff --git a/gdb/ppc-sysv-tdep.c b/gdb/ppc-sysv-tdep.c
index 6c2fd1bfc99..ed6c2d4449d 100644
--- a/gdb/ppc-sysv-tdep.c
+++ b/gdb/ppc-sysv-tdep.c
@@ -65,7 +65,7 @@ ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 			      function_call_return_method return_method,
 			      CORE_ADDR struct_addr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int opencl_abi = ppc_sysv_use_opencl_abi (value_type (function));
   ULONGEST saved_sp;
@@ -597,7 +597,7 @@ get_decimal_float_return_value (struct gdbarch *gdbarch, struct type *valtype,
 				struct regcache *regcache, gdb_byte *readbuf,
 				const gdb_byte *writebuf)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   gdb_assert (valtype->code () == TYPE_CODE_DECFLOAT);
 
@@ -675,7 +675,7 @@ do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *func_type,
 			  gdb_byte *readbuf, const gdb_byte *writebuf,
 			  int broken_gcc)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int opencl_abi = func_type? ppc_sysv_use_opencl_abi (func_type) : 0;
 
@@ -1250,7 +1250,7 @@ ppc64_sysv_abi_push_val (struct gdbarch *gdbarch,
 			 const bfd_byte *val, int len, int align,
 			 struct ppc64_sysv_argpos *argpos)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int offset = 0;
 
   /* Enforce alignment of stack location, if requested.  */
@@ -1300,7 +1300,7 @@ static void
 ppc64_sysv_abi_push_integer (struct gdbarch *gdbarch, ULONGEST val,
 			     struct ppc64_sysv_argpos *argpos)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   gdb_byte buf[PPC_MAX_REGISTER_SIZE];
 
@@ -1318,7 +1318,7 @@ ppc64_sysv_abi_push_freg (struct gdbarch *gdbarch,
 			  struct type *type, const bfd_byte *val,
 			  struct ppc64_sysv_argpos *argpos)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   if (tdep->soft_float)
     return;
 
@@ -1403,7 +1403,7 @@ static void
 ppc64_sysv_abi_push_vreg (struct gdbarch *gdbarch, const bfd_byte *val,
 			  struct ppc64_sysv_argpos *argpos)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (argpos->regcache && argpos->vreg <= 13)
     argpos->regcache->cooked_write (tdep->ppc_vr0_regnum + argpos->vreg, val);
@@ -1419,7 +1419,7 @@ ppc64_sysv_abi_push_param (struct gdbarch *gdbarch,
 			   struct type *type, const bfd_byte *val,
 			   struct ppc64_sysv_argpos *argpos)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (type->code () == TYPE_CODE_FLT
       || type->code () == TYPE_CODE_DECFLOAT)
@@ -1545,7 +1545,7 @@ ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch,
 				CORE_ADDR struct_addr)
 {
   CORE_ADDR func_addr = find_function_addr (function, NULL);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int opencl_abi = ppc_sysv_use_opencl_abi (value_type (function));
   ULONGEST back_chain;
@@ -1739,7 +1739,7 @@ ppc64_sysv_abi_return_value_base (struct gdbarch *gdbarch, struct type *valtype,
 				  struct regcache *regcache, gdb_byte *readbuf,
 				  const gdb_byte *writebuf, int index)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* Integers live in GPRs starting at r3.  */
   if ((valtype->code () == TYPE_CODE_INT
@@ -1922,7 +1922,7 @@ ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct value *function,
 			     struct type *valtype, struct regcache *regcache,
 			     gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   struct type *func_type = function ? value_type (function) : NULL;
   int opencl_abi = func_type? ppc_sysv_use_opencl_abi (func_type) : 0;
   struct type *eltype;
diff --git a/gdb/ppc64-tdep.c b/gdb/ppc64-tdep.c
index 32931f72691..0437ca7e3f3 100644
--- a/gdb/ppc64-tdep.c
+++ b/gdb/ppc64-tdep.c
@@ -89,7 +89,7 @@ ppc64_plt_entry_point (struct frame_info *frame, CORE_ADDR plt_off)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   CORE_ADDR tocp;
 
   if (execution_direction == EXEC_REVERSE)
diff --git a/gdb/riscv-linux-tdep.c b/gdb/riscv-linux-tdep.c
index 387b8bdbc2f..5bda2e5c824 100644
--- a/gdb/riscv-linux-tdep.c
+++ b/gdb/riscv-linux-tdep.c
@@ -179,7 +179,7 @@ riscv_linux_syscall_next_pc (struct frame_info *frame)
 static void
 riscv_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
index 69f2123dcdb..2d41be96b20 100644
--- a/gdb/riscv-tdep.c
+++ b/gdb/riscv-tdep.c
@@ -733,7 +733,7 @@ show_riscv_debug_variable (struct ui_file *file, int from_tty,
 int
 riscv_isa_xlen (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   return tdep->isa_features.xlen;
 }
 
@@ -742,7 +742,7 @@ riscv_isa_xlen (struct gdbarch *gdbarch)
 int
 riscv_abi_xlen (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   return tdep->abi_features.xlen;
 }
 
@@ -751,7 +751,7 @@ riscv_abi_xlen (struct gdbarch *gdbarch)
 int
 riscv_isa_flen (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   return tdep->isa_features.flen;
 }
 
@@ -760,7 +760,7 @@ riscv_isa_flen (struct gdbarch *gdbarch)
 int
 riscv_abi_flen (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   return tdep->abi_features.flen;
 }
 
@@ -769,7 +769,7 @@ riscv_abi_flen (struct gdbarch *gdbarch)
 bool
 riscv_abi_embedded (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   return tdep->abi_features.embedded;
 }
 
@@ -786,7 +786,7 @@ riscv_has_fp_regs (struct gdbarch *gdbarch)
 static bool
 riscv_has_fp_abi (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   return tdep->abi_features.flen > 0;
 }
 
@@ -910,7 +910,7 @@ riscv_register_name (struct gdbarch *gdbarch, int regnum)
      will show up in 'info register all'.  Unless, we identify the
      duplicate copies of these registers (in riscv_tdesc_unknown_reg) and
      then hide the registers here by giving them no name.  */
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   if (tdep->duplicate_fflags_regnum == regnum)
     return NULL;
   if (tdep->duplicate_frm_regnum == regnum)
@@ -938,7 +938,7 @@ riscv_register_name (struct gdbarch *gdbarch, int regnum)
 static struct type *
 riscv_fpreg_d_type (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
 
   if (tdep->riscv_fpreg_d_type == nullptr)
     {
@@ -1260,7 +1260,7 @@ riscv_is_regnum_a_named_csr (int regnum)
 static bool
 riscv_is_unknown_csr (struct gdbarch *gdbarch, int regnum)
 {
-  riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   return (regnum >= tdep->unknown_csrs_first_regnum
 	  && regnum < (tdep->unknown_csrs_first_regnum
 		       + tdep->unknown_csrs_count));
@@ -3600,7 +3600,7 @@ riscv_tdesc_unknown_reg (struct gdbarch *gdbarch, tdesc_feature *feature,
      record their register numbers here.  */
   if (strcmp (tdesc_feature_name (feature), riscv_freg_feature.name ()) == 0)
     {
-      riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
       int *regnum_ptr = nullptr;
 
       if (strcmp (reg_name, "fflags") == 0)
@@ -3631,7 +3631,7 @@ riscv_tdesc_unknown_reg (struct gdbarch *gdbarch, tdesc_feature *feature,
      about register groups in riscv_register_reggroup_p.  */
   if (strcmp (tdesc_feature_name (feature), riscv_csr_feature.name ()) == 0)
     {
-      riscv_gdbarch_tdep *tdep = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
       if (tdep->unknown_csrs_first_regnum == -1)
 	tdep->unknown_csrs_first_regnum = possible_regnum;
       gdb_assert (tdep->unknown_csrs_first_regnum
@@ -3733,7 +3733,7 @@ riscv_gdbarch_init (struct gdbarch_info info,
 	 we are looking for.  If it doesn't then we can't reuse this
 	 gdbarch.  */
       riscv_gdbarch_tdep *other_tdep
-	= (riscv_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<riscv_gdbarch_tdep> (arches->gdbarch);
 
       if (other_tdep->isa_features != features
 	  || other_tdep->abi_features != abi_features)
@@ -3858,7 +3858,7 @@ riscv_next_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   struct gdbarch *gdbarch = regcache->arch ();
   const riscv_gdbarch_tdep *tdep
-    = (riscv_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+    = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
   struct riscv_insn insn;
   CORE_ADDR next_pc;
 
diff --git a/gdb/rl78-tdep.c b/gdb/rl78-tdep.c
index 6ea0473081d..2462e7a191d 100644
--- a/gdb/rl78-tdep.c
+++ b/gdb/rl78-tdep.c
@@ -267,7 +267,7 @@ struct rl78_prologue
 static struct type *
 rl78_psw_type (struct gdbarch *gdbarch)
 {
-  rl78_gdbarch_tdep *tdep = (rl78_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  rl78_gdbarch_tdep *tdep = gdbarch_tdep<rl78_gdbarch_tdep> (gdbarch);
 
   if (tdep->rl78_psw_type == NULL)
     {
@@ -291,7 +291,7 @@ rl78_psw_type (struct gdbarch *gdbarch)
 static struct type *
 rl78_register_type (struct gdbarch *gdbarch, int reg_nr)
 {
-  rl78_gdbarch_tdep *tdep = (rl78_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  rl78_gdbarch_tdep *tdep = gdbarch_tdep<rl78_gdbarch_tdep> (gdbarch);
 
   if (reg_nr == RL78_PC_REGNUM)
     return tdep->rl78_code_pointer;
@@ -1248,7 +1248,7 @@ rl78_return_value (struct gdbarch *gdbarch,
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   ULONGEST valtype_len = TYPE_LENGTH (valtype);
-  rl78_gdbarch_tdep *tdep = (rl78_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  rl78_gdbarch_tdep *tdep = gdbarch_tdep<rl78_gdbarch_tdep> (gdbarch);
   int is_g10 = tdep->elf_flags & E_FLAG_RL78_G10;
 
   if (valtype_len > 8)
@@ -1394,7 +1394,7 @@ rl78_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       rl78_gdbarch_tdep *tdep
-	= (rl78_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<rl78_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->elf_flags != elf_flags)
 	continue;
diff --git a/gdb/rs6000-aix-nat.c b/gdb/rs6000-aix-nat.c
index 8563aea313a..8697d27b4ed 100644
--- a/gdb/rs6000-aix-nat.c
+++ b/gdb/rs6000-aix-nat.c
@@ -115,7 +115,7 @@ static rs6000_nat_target the_rs6000_nat_target;
 static int
 regmap (struct gdbarch *gdbarch, int regno, int *isfloat)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   *isfloat = 0;
   if (tdep->ppc_gp0_regnum <= regno
@@ -317,7 +317,7 @@ rs6000_nat_target::fetch_registers (struct regcache *regcache, int regno)
 
   else
     {
-      ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
       /* Read 32 general purpose registers.  */
       for (regno = tdep->ppc_gp0_regnum;
@@ -359,7 +359,7 @@ rs6000_nat_target::store_registers (struct regcache *regcache, int regno)
 
   else
     {
-      ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
       /* Write general purpose registers first.  */
       for (regno = tdep->ppc_gp0_regnum;
diff --git a/gdb/rs6000-aix-tdep.c b/gdb/rs6000-aix-tdep.c
index 867f21dc634..41384993c26 100644
--- a/gdb/rs6000-aix-tdep.c
+++ b/gdb/rs6000-aix-tdep.c
@@ -75,7 +75,7 @@ aix_sighandle_frame_cache (struct frame_info *this_frame,
   LONGEST backchain;
   CORE_ADDR base, base_orig, func;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct trad_frame_cache *this_trad_cache;
 
@@ -261,7 +261,7 @@ rs6000_aix_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					 void *cb_data,
 					 const struct regcache *regcache)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   if (tdep->wordsize == 4)
     cb (".reg", 592, 592, &rs6000_aix32_regset, NULL, cb_data);
   else
@@ -292,7 +292,7 @@ rs6000_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 			function_call_return_method return_method,
 			CORE_ADDR struct_addr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int ii;
   int len = 0;
@@ -522,7 +522,7 @@ rs6000_return_value (struct gdbarch *gdbarch, struct value *function,
 		     struct type *valtype, struct regcache *regcache,
 		     gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   /* The calling convention this function implements assumes the
@@ -660,7 +660,7 @@ rs6000_convert_from_func_ptr_addr (struct gdbarch *gdbarch,
 				   CORE_ADDR addr,
 				   struct target_ops *targ)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct obj_section *s;
 
@@ -704,7 +704,7 @@ branch_dest (struct regcache *regcache, int opcode, int instr,
 	     CORE_ADDR pc, CORE_ADDR safety)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR dest;
   int immediate;
@@ -972,7 +972,7 @@ static struct ld_info
 rs6000_aix_extract_ld_info (struct gdbarch *gdbarch,
 			    const gdb_byte *ldi_buf)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
   const struct ld_info_desc desc
@@ -1131,7 +1131,7 @@ rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch,
 static void
 rs6000_aix_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* RS6000/AIX does not support PT_STEP.  Has to be simulated.  */
   set_gdbarch_software_single_step (gdbarch, rs6000_software_single_step);
diff --git a/gdb/rs6000-lynx178-tdep.c b/gdb/rs6000-lynx178-tdep.c
index 844d0a4ede2..dc13dd3fa73 100644
--- a/gdb/rs6000-lynx178-tdep.c
+++ b/gdb/rs6000-lynx178-tdep.c
@@ -36,7 +36,7 @@ rs6000_lynx178_push_dummy_call (struct gdbarch *gdbarch,
 				function_call_return_method return_method,
 				CORE_ADDR struct_addr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int ii;
   int len = 0;
@@ -265,7 +265,7 @@ rs6000_lynx178_return_value (struct gdbarch *gdbarch, struct value *function,
 			     struct type *valtype, struct regcache *regcache,
 			     gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   /* The calling convention this function implements assumes the
diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
index 6815dfaa820..640459f1c28 100644
--- a/gdb/rs6000-tdep.c
+++ b/gdb/rs6000-tdep.c
@@ -201,7 +201,7 @@ struct rs6000_framedata
 int
 vsx_register_p (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   if (tdep->ppc_vsr0_regnum < 0)
     return 0;
   else
@@ -213,7 +213,7 @@ vsx_register_p (struct gdbarch *gdbarch, int regno)
 int
 altivec_register_p (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   if (tdep->ppc_vr0_regnum < 0 || tdep->ppc_vrsave_regnum < 0)
     return 0;
   else
@@ -225,7 +225,7 @@ altivec_register_p (struct gdbarch *gdbarch, int regno)
 int
 spe_register_p (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   
   /* Is it a reference to EV0 -- EV31, and do we have those?  */
   if (IS_SPE_PSEUDOREG (tdep, regno))
@@ -257,7 +257,7 @@ spe_register_p (struct gdbarch *gdbarch, int regno)
 int
 ppc_floating_point_unit_p (struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   return (tdep->ppc_fp0_regnum >= 0
 	  && tdep->ppc_fpscr_regnum >= 0);
@@ -268,7 +268,7 @@ ppc_floating_point_unit_p (struct gdbarch *gdbarch)
 int
 ppc_altivec_support_p (struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   return (tdep->ppc_vr0_regnum >= 0
 	  && tdep->ppc_vrsave_regnum >= 0);
@@ -297,7 +297,7 @@ set_sim_regno (int *table, int gdb_regno, int sim_regno)
 static void
 init_sim_regno_table (struct gdbarch *arch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (arch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (arch);
   int total_regs = gdbarch_num_regs (arch);
   int *sim_regno = GDBARCH_OBSTACK_CALLOC (arch, total_regs, int);
   int i;
@@ -391,7 +391,7 @@ init_sim_regno_table (struct gdbarch *arch)
 static int
 rs6000_register_sim_regno (struct gdbarch *gdbarch, int reg)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int sim_regno;
 
   if (tdep->sim_regno == NULL)
@@ -522,7 +522,7 @@ ppc_supply_gregset (const struct regset *regset, struct regcache *regcache,
 		    int regnum, const void *gregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   const struct ppc_reg_offsets *offsets
     = (const struct ppc_reg_offsets *) regset->regmap;
   size_t offset;
@@ -578,7 +578,7 @@ ppc_supply_fpregset (const struct regset *regset, struct regcache *regcache,
   if (!ppc_floating_point_unit_p (gdbarch))
     return;
 
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   offsets = (const struct ppc_reg_offsets *) regset->regmap;
   if (regnum == -1)
     {
@@ -611,7 +611,7 @@ ppc_collect_gregset (const struct regset *regset,
 		     int regnum, void *gregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   const struct ppc_reg_offsets *offsets
     = (const struct ppc_reg_offsets *) regset->regmap;
   size_t offset;
@@ -668,7 +668,7 @@ ppc_collect_fpregset (const struct regset *regset,
   if (!ppc_floating_point_unit_p (gdbarch))
     return;
 
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   offsets = (const struct ppc_reg_offsets *) regset->regmap;
   if (regnum == -1)
     {
@@ -746,7 +746,7 @@ static int
 rs6000_in_function_epilogue_frame_p (struct frame_info *curfrm,
 				     struct gdbarch *gdbarch, CORE_ADDR pc)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   bfd_byte insn_buf[PPC_INSN_SIZE];
   CORE_ADDR scan_pc, func_start, func_end, epilogue_start, epilogue_end;
@@ -1042,7 +1042,7 @@ ppc_displaced_step_fixup (struct gdbarch *gdbarch,
       if (insn & 0x1)
 	{
 	  /* Link register needs to be set to the next instruction's PC.  */
-	  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 	  regcache_cooked_write_unsigned (regs,
 					  tdep->ppc_lr_regnum,
 					  from + PPC_INSN_SIZE);
@@ -1590,7 +1590,7 @@ skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc, CORE_ADDR lim_pc,
   int num_skip_non_prologue_insns = 0;
   int r0_contains_arg = 0;
   const struct bfd_arch_info *arch_info = gdbarch_bfd_arch_info (gdbarch);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   memset (fdata, 0, sizeof (struct rs6000_framedata));
@@ -2310,7 +2310,7 @@ static CORE_ADDR
 rs6000_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   unsigned int ii, op;
   int rel;
@@ -2368,7 +2368,7 @@ rs6000_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
 static struct type *
 rs6000_builtin_type_vec64 (struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->ppc_builtin_type_vec64)
     {
@@ -2413,7 +2413,7 @@ rs6000_builtin_type_vec64 (struct gdbarch *gdbarch)
 static struct type *
 rs6000_builtin_type_vec128 (struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->ppc_builtin_type_vec128)
     {
@@ -2467,7 +2467,7 @@ rs6000_builtin_type_vec128 (struct gdbarch *gdbarch)
 static const char *
 rs6000_register_name (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* The upper half "registers" have names in the XML description,
      but we present only the low GPRs and the full 64-bit registers
@@ -2605,7 +2605,7 @@ rs6000_register_name (struct gdbarch *gdbarch, int regno)
 static struct type *
 rs6000_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* These are the e500 pseudo-registers.  */
   if (IS_SPE_PSEUDOREG (tdep, regnum))
@@ -2644,7 +2644,7 @@ static int
 rs6000_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 				   const struct reggroup *group)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (IS_V_ALIAS_PSEUDOREG (tdep, regnum))
     return 0;
@@ -2659,7 +2659,7 @@ static int
 rs6000_convert_register_p (struct gdbarch *gdbarch, int regnum,
 			   struct type *type)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   return (tdep->ppc_fp0_regnum >= 0
 	  && regnum >= tdep->ppc_fp0_regnum
@@ -2744,7 +2744,7 @@ e500_move_ev_register (move_ev_register_func move,
 		       struct regcache *regcache, int ev_reg, void *buffer)
 {
   struct gdbarch *arch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (arch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (arch);
   int reg_index;
   gdb_byte *byte_buffer = (gdb_byte *) buffer;
   enum register_status status;
@@ -2785,7 +2785,7 @@ e500_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int ev_reg, gdb_byte *buffer)
 {
   struct gdbarch *arch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index;
   enum register_status status;
 
@@ -2826,7 +2826,7 @@ static enum register_status
 dfp_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int reg_nr, gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, fp0;
   enum register_status status;
 
@@ -2866,7 +2866,7 @@ static void
 dfp_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
 			    int reg_nr, const gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, fp0;
 
   if (IS_DFP_PSEUDOREG (tdep, reg_nr))
@@ -2903,7 +2903,7 @@ v_alias_pseudo_register_read (struct gdbarch *gdbarch,
 			      readable_regcache *regcache, int reg_nr,
 			      gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   gdb_assert (IS_V_ALIAS_PSEUDOREG (tdep, reg_nr));
 
   return regcache->raw_read (tdep->ppc_vr0_regnum
@@ -2918,7 +2918,7 @@ v_alias_pseudo_register_write (struct gdbarch *gdbarch,
 			       struct regcache *regcache,
 			       int reg_nr, const gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   gdb_assert (IS_V_ALIAS_PSEUDOREG (tdep, reg_nr));
 
   regcache->raw_write (tdep->ppc_vr0_regnum
@@ -2930,7 +2930,7 @@ static enum register_status
 vsx_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int reg_nr, gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0, fp0, vsr0_upper;
   enum register_status status;
 
@@ -2978,7 +2978,7 @@ static void
 vsx_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
 			    int reg_nr, const gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0, fp0, vsr0_upper;
 
   if (IS_VSX_PSEUDOREG (tdep, reg_nr))
@@ -3020,7 +3020,7 @@ static enum register_status
 efp_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int reg_nr, gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0;
 
   if (IS_EFP_PSEUDOREG (tdep, reg_nr))
@@ -3049,7 +3049,7 @@ static void
 efp_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
 			    int reg_nr, const gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0;
   int offset = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG ? 0 : 8;
 
@@ -3085,7 +3085,7 @@ rs6000_pseudo_register_read (struct gdbarch *gdbarch,
 			     int reg_nr, gdb_byte *buffer)
 {
   struct gdbarch *regcache_arch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   gdb_assert (regcache_arch == gdbarch);
 
@@ -3116,7 +3116,7 @@ rs6000_pseudo_register_write (struct gdbarch *gdbarch,
 			      int reg_nr, const gdb_byte *buffer)
 {
   struct gdbarch *regcache_arch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   gdb_assert (regcache_arch == gdbarch);
 
@@ -3147,7 +3147,7 @@ static void
 dfp_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				struct agent_expr *ax, int reg_nr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, fp0;
 
   if (IS_DFP_PSEUDOREG (tdep, reg_nr))
@@ -3174,7 +3174,7 @@ static void
 v_alias_pseudo_register_collect (struct gdbarch *gdbarch,
 				 struct agent_expr *ax, int reg_nr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   gdb_assert (IS_V_ALIAS_PSEUDOREG (tdep, reg_nr));
 
   ax_reg_mask (ax, tdep->ppc_vr0_regnum
@@ -3188,7 +3188,7 @@ static void
 vsx_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				struct agent_expr *ax, int reg_nr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0, fp0, vsr0_upper;
 
   if (IS_VSX_PSEUDOREG (tdep, reg_nr))
@@ -3226,7 +3226,7 @@ static void
 efp_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				struct agent_expr *ax, int reg_nr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0;
 
   if (IS_EFP_PSEUDOREG (tdep, reg_nr))
@@ -3249,7 +3249,7 @@ static int
 rs6000_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				   struct agent_expr *ax, int reg_nr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   if (IS_SPE_PSEUDOREG (tdep, reg_nr))
     {
       int reg_index = reg_nr - tdep->ppc_ev0_regnum;
@@ -3289,7 +3289,7 @@ rs6000_gen_return_address (struct gdbarch *gdbarch,
 			   struct agent_expr *ax, struct axs_value *value,
 			   CORE_ADDR scope)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   value->type = register_type (gdbarch, tdep->ppc_lr_regnum);
   value->kind = axs_lvalue_register;
   value->u.reg = tdep->ppc_lr_regnum;
@@ -3300,7 +3300,7 @@ rs6000_gen_return_address (struct gdbarch *gdbarch,
 static int
 rs6000_stab_reg_to_regnum (struct gdbarch *gdbarch, int num)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (0 <= num && num <= 31)
     return tdep->ppc_gp0_regnum + num;
@@ -3342,7 +3342,7 @@ rs6000_stab_reg_to_regnum (struct gdbarch *gdbarch, int num)
 static int
 rs6000_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int num)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (0 <= num && num <= 31)
     return tdep->ppc_gp0_regnum + num;
@@ -3561,7 +3561,7 @@ rs6000_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct rs6000_frame_cache *cache;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct rs6000_framedata fdata;
   int wordsize = tdep->wordsize;
@@ -3797,7 +3797,7 @@ rs6000_epilogue_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct rs6000_frame_cache *cache;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (*this_cache)
     return (struct rs6000_frame_cache *) *this_cache;
@@ -3918,7 +3918,7 @@ ppc_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
 			    struct dwarf2_frame_state_reg *reg,
 			    struct frame_info *this_frame)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   /* PPC32 and PPC64 ABI's are the same regarding volatile and
      non-volatile registers.  We will use the same code for both.  */
@@ -4229,7 +4229,7 @@ static int
 ppc_process_record_op4 (struct gdbarch *gdbarch, struct regcache *regcache,
 			CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_FIELD (insn, 21, 11);
   int vra = PPC_FIELD (insn, 11, 5);
 
@@ -4771,7 +4771,7 @@ static int
 ppc_process_record_op6 (struct gdbarch *gdbarch, struct regcache *regcache,
 			CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int subtype = PPC_FIELD (insn, 28, 4);
   CORE_ADDR ea = 0;
 
@@ -4799,7 +4799,7 @@ static int
 ppc_process_record_op19 (struct gdbarch *gdbarch, struct regcache *regcache,
 			   CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_EXTOP (insn);
 
   switch (ext & 0x01f)
@@ -4855,7 +4855,7 @@ ppc_process_record_op31_177 (struct gdbarch *gdbarch,
 {
   int RA_opcode = PPC_RA(insn);
   int as = PPC_FIELD (insn, 6, 3);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   switch (RA_opcode)
     {
@@ -4875,7 +4875,7 @@ static int
 ppc_process_record_op31 (struct gdbarch *gdbarch, struct regcache *regcache,
 			   CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_EXTOP (insn);
   int tmp, nr, nb = 0, i;
   CORE_ADDR at_dcsz, ea = 0;
@@ -5536,7 +5536,7 @@ static int
 ppc_process_record_op59 (struct gdbarch *gdbarch, struct regcache *regcache,
 			 CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_EXTOP (insn);
   int at = PPC_FIELD (insn, 6, 3);
 
@@ -5701,7 +5701,7 @@ ppc_process_record_op60_XX2 (struct gdbarch *gdbarch,
 			     struct regcache *regcache,
 			     CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int RA_opcode = PPC_RA(insn);
 
   switch (RA_opcode)
@@ -5742,7 +5742,7 @@ static int
 ppc_process_record_op60 (struct gdbarch *gdbarch, struct regcache *regcache,
 			   CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_EXTOP (insn);
 
   switch (ext >> 2)
@@ -6097,7 +6097,7 @@ static int
 ppc_process_record_op61 (struct gdbarch *gdbarch, struct regcache *regcache,
 			   CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   ULONGEST ea = 0;
   int size;
 
@@ -6156,7 +6156,7 @@ static int
 ppc_process_record_op63 (struct gdbarch *gdbarch, struct regcache *regcache,
 			   CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_EXTOP (insn);
   int tmp;
 
@@ -6453,7 +6453,7 @@ ppc_process_record_prefix_op42 (struct gdbarch *gdbarch,
 				struct regcache *regcache,
 				uint32_t insn_prefix, uint32_t insn_suffix)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST1 = PPC_FIELD (insn_prefix, 8, 1);
 
@@ -6489,7 +6489,7 @@ ppc_process_record_prefix_op59_XX3 (struct gdbarch *gdbarch,
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST4 = PPC_FIELD (insn_prefix, 8, 4);
   int at = PPC_FIELD (insn_suffix, 6, 3);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (type == 3)
     {
@@ -6603,7 +6603,7 @@ ppc_process_record_prefix_store (struct gdbarch *gdbarch,
 				 CORE_ADDR addr, uint32_t insn_prefix,
 				 uint32_t insn_suffix)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   ULONGEST iaddr = 0;
   int size;
   int R = PPC_BIT (insn_prefix, 11);
@@ -6659,7 +6659,7 @@ ppc_process_record_prefix_op32 (struct gdbarch *gdbarch,
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST1 = PPC_FIELD (insn_prefix, 8, 1);
   int ST4 = PPC_FIELD (insn_prefix, 8, 4);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (type == 1)
     {
@@ -6713,7 +6713,7 @@ ppc_process_record_prefix_op33 (struct gdbarch *gdbarch,
 {
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST4 = PPC_FIELD (insn_prefix, 8, 4);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (type == 1)
     {
@@ -6751,7 +6751,7 @@ ppc_process_record_prefix_op34 (struct gdbarch *gdbarch,
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST1 = PPC_FIELD (insn_prefix, 8, 1);
   int ST4 = PPC_FIELD (insn_prefix, 8, 4);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (type == 1)
     {
@@ -6797,7 +6797,7 @@ ppc_process_record_prefix_store_vsx_ds_form (struct gdbarch *gdbarch,
 					     uint32_t insn_prefix,
 					     uint32_t insn_suffix)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   ULONGEST ea = 0;
   int size;
   int R = PPC_BIT (insn_prefix, 11);
@@ -6850,7 +6850,7 @@ ppc_process_record_prefix_vsx_d_form (struct gdbarch *gdbarch,
 				      uint32_t insn_prefix,
 				      uint32_t insn_suffix)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   ULONGEST ea = 0;
   int size;
   int R = PPC_BIT (insn_prefix, 11);
@@ -6907,7 +6907,7 @@ ppc_process_prefix_instruction (int insn_prefix, int insn_suffix,
 {
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST1 = PPC_FIELD (insn_prefix, 8, 1);
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   int op6;
 
   /* D-form has uses a 5-bit opcode in the instruction suffix */
@@ -7086,7 +7086,7 @@ int
 ppc_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
 		      CORE_ADDR addr)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   uint32_t insn, insn_suffix;
   int op6, tmp, i;
@@ -8150,7 +8150,7 @@ rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 	 meaningful, because 64-bit CPUs can run in 32-bit mode.  So, perform
 	 separate word size check.  */
       ppc_gdbarch_tdep *tdep
-	= (ppc_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<ppc_gdbarch_tdep> (arches->gdbarch);
       if (tdep && tdep->elf_abi != elf_abi)
 	continue;
       if (tdep && tdep->soft_float != soft_float)
@@ -8452,7 +8452,7 @@ rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 rs6000_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
 
   if (tdep == NULL)
     return;
diff --git a/gdb/rx-tdep.c b/gdb/rx-tdep.c
index 2a24ebba2b6..c67d4057195 100644
--- a/gdb/rx-tdep.c
+++ b/gdb/rx-tdep.c
@@ -964,7 +964,7 @@ rx_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       rx_gdbarch_tdep *tdep
-	= (rx_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<rx_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->elf_flags != elf_flags)
 	continue;
diff --git a/gdb/s390-linux-tdep.c b/gdb/s390-linux-tdep.c
index 9d4e2d09f2a..03611fe1d23 100644
--- a/gdb/s390-linux-tdep.c
+++ b/gdb/s390-linux-tdep.c
@@ -79,7 +79,7 @@ static void
 s390_write_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
 
@@ -269,7 +269,7 @@ s390_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				   void *cb_data,
 				   const struct regcache *regcache)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   const int gregset_size = (tdep->abi == ABI_LINUX_S390 ?
 			    s390_sizeof_gregset : s390x_sizeof_gregset);
 
@@ -390,7 +390,7 @@ s390_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
 				  void **this_prologue_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   int word_size = gdbarch_ptr_bit (gdbarch) / 8;
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct s390_sigtramp_unwind_cache *info;
@@ -561,7 +561,7 @@ s390_linux_get_syscall_number (struct gdbarch *gdbarch,
 			       thread_info *thread)
 {
   struct regcache *regs = get_thread_regcache (thread);
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   ULONGEST pc;
   ULONGEST svc_number = -1;
@@ -594,7 +594,7 @@ static int
 s390_all_but_pc_registers_record (struct regcache *regcache)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   int i;
 
   for (i = 0; i < 16; i++)
@@ -802,7 +802,7 @@ static int
 s390_linux_syscall_record (struct regcache *regcache, LONGEST syscall_native)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   int ret;
   enum gdb_syscall syscall_gdb;
 
@@ -853,7 +853,7 @@ static int
 s390_linux_record_signal (struct gdbarch *gdbarch, struct regcache *regcache,
 			  enum gdb_signal signal)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   /* There are two kinds of signal frames on s390. rt_sigframe is always
      the larger one, so don't even bother with sigframe.  */
   const int sizeof_rt_sigframe = (tdep->abi == ABI_LINUX_ZSERIES ?
@@ -1117,7 +1117,7 @@ s390_init_linux_record_tdep (struct linux_record_tdep *record_tdep,
 static void
 s390_linux_init_abi_any (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   tdep->s390_syscall_record = s390_linux_syscall_record;
 
@@ -1152,7 +1152,7 @@ s390_linux_init_abi_any (struct gdbarch_info info, struct gdbarch *gdbarch)
 static void
 s390_linux_init_abi_31 (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   tdep->abi = ABI_LINUX_S390;
 
@@ -1168,7 +1168,7 @@ s390_linux_init_abi_31 (struct gdbarch_info info, struct gdbarch *gdbarch)
 static void
 s390_linux_init_abi_64 (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   tdep->abi = ABI_LINUX_ZSERIES;
 
diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c
index 14b03a167d7..2aeb3a14637 100644
--- a/gdb/s390-tdep.c
+++ b/gdb/s390-tdep.c
@@ -1045,7 +1045,7 @@ s390_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
 static int
 s390_register_call_saved (struct gdbarch *gdbarch, int regnum)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   switch (tdep->abi)
     {
@@ -1076,7 +1076,7 @@ s390_guess_tracepoint_registers (struct gdbarch *gdbarch,
 				 struct regcache *regcache,
 				 CORE_ADDR addr)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   int sz = register_size (gdbarch, S390_PSWA_REGNUM);
   gdb_byte *reg = (gdb_byte *) alloca (sz);
   ULONGEST pswm, pswa;
@@ -1172,7 +1172,7 @@ enum { s390_dwarf_reg_r0l = ARRAY_SIZE (s390_dwarf_regmap) - 16 };
 static int
 s390_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   int gdb_reg = -1;
 
   /* In a 32-on-64 debug scenario, debug info refers to the full
@@ -1231,7 +1231,7 @@ static struct value *
 s390_value_from_register (struct gdbarch *gdbarch, struct type *type,
 			  int regnum, struct frame_id frame_id)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   struct value *value = default_value_from_register (gdbarch, type,
 						     regnum, frame_id);
   check_typedef (type);
@@ -1250,7 +1250,7 @@ s390_value_from_register (struct gdbarch *gdbarch, struct type *type,
 static const char *
 s390_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   if (regnum == tdep->pc_regnum)
     return "pc";
@@ -1284,7 +1284,7 @@ s390_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 static struct type *
 s390_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   if (regnum == tdep->pc_regnum)
     return builtin_type (gdbarch)->builtin_func_ptr;
@@ -1308,7 +1308,7 @@ static enum register_status
 s390_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int regnum, gdb_byte *buf)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int regsize = register_size (gdbarch, regnum);
   ULONGEST val;
@@ -1383,7 +1383,7 @@ static void
 s390_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
 			    int regnum, const gdb_byte *buf)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int regsize = register_size (gdbarch, regnum);
   ULONGEST val, psw;
@@ -1442,7 +1442,7 @@ static int
 s390_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 				 const struct reggroup *group)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 
   /* We usually save/restore the whole PSW, which includes PC and CC.
      However, some older gdbservers may not support saving/restoring
@@ -1470,7 +1470,7 @@ static int
 s390_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				 struct agent_expr *ax, int regnum)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   if (regnum == tdep->pc_regnum)
     {
       ax_reg_mask (ax, S390_PSWA_REGNUM);
@@ -1504,7 +1504,7 @@ static int
 s390_ax_pseudo_register_push_stack (struct gdbarch *gdbarch,
 				    struct agent_expr *ax, int regnum)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   if (regnum == tdep->pc_regnum)
     {
       ax_reg (ax, S390_PSWA_REGNUM);
@@ -1905,7 +1905,7 @@ s390_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 		      function_call_return_method return_method,
 		      CORE_ADDR struct_addr)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   int word_size = gdbarch_ptr_bit (gdbarch) / 8;
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int i;
@@ -2084,7 +2084,7 @@ s390_return_value (struct gdbarch *gdbarch, struct value *function,
       break;
     case TYPE_CODE_ARRAY:
       {
-	s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
 	rvc = (tdep->vector_abi == S390_VECTOR_ABI_128
 	       && TYPE_LENGTH (type) <= 16 && type->is_vector ())
 	  ? RETURN_VALUE_REGISTER_CONVENTION
@@ -2168,7 +2168,7 @@ s390_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
 static CORE_ADDR
 s390_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   ULONGEST pc;
   pc = frame_unwind_register_unsigned (next_frame, tdep->pc_regnum);
   return gdbarch_addr_bits_remove (gdbarch, pc);
@@ -2190,7 +2190,7 @@ static struct value *
 s390_unwind_pseudo_register (struct frame_info *this_frame, int regnum)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   struct type *type = register_type (gdbarch, regnum);
 
   /* Unwind PC via PSW address.  */
@@ -2775,7 +2775,7 @@ static CORE_ADDR
 s390_record_address_mask (struct gdbarch *gdbarch, struct regcache *regcache,
 			  CORE_ADDR val)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   ULONGEST pswm, pswa;
   int am;
   if (tdep->abi == ABI_LINUX_S390)
@@ -2842,7 +2842,7 @@ s390_record_calc_disp_vsce (struct gdbarch *gdbarch, struct regcache *regcache,
 			    uint8_t vx, uint8_t el, uint8_t es, uint16_t bd,
 			    int8_t dh, CORE_ADDR *res)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   ULONGEST x;
   gdb_byte buf[16];
@@ -2885,7 +2885,7 @@ static int s390_popcnt (unsigned int x) {
 static int
 s390_record_gpr_g (struct gdbarch *gdbarch, struct regcache *regcache, int i)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + i))
     return -1;
   if (tdep->abi == ABI_LINUX_S390)
@@ -2899,7 +2899,7 @@ s390_record_gpr_g (struct gdbarch *gdbarch, struct regcache *regcache, int i)
 static int
 s390_record_gpr_h (struct gdbarch *gdbarch, struct regcache *regcache, int i)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   if (tdep->abi == ABI_LINUX_S390)
     {
       if (record_full_arch_list_add_reg (regcache, S390_R0_UPPER_REGNUM + i))
@@ -2939,7 +2939,7 @@ static int
 s390_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
 		     CORE_ADDR addr)
 {
-  s390_gdbarch_tdep *tdep = (s390_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
   uint16_t insn[3] = {0};
   /* Instruction as bytes.  */
   uint8_t ibyte[6];
@@ -7178,7 +7178,7 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       s390_gdbarch_tdep *tmp
-	= (s390_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<s390_gdbarch_tdep> (arches->gdbarch);
 
       if (!tmp)
 	continue;
diff --git a/gdb/sh-linux-tdep.c b/gdb/sh-linux-tdep.c
index 2975a8f5d3d..f146f023add 100644
--- a/gdb/sh-linux-tdep.c
+++ b/gdb/sh-linux-tdep.c
@@ -195,7 +195,7 @@ sh_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   set_gdbarch_fetch_tls_load_module_address (gdbarch,
 					     svr4_fetch_objfile_link_map);
 
-  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
 
   /* Remember regset characteristics.  The sizes should match
      elf_gregset_t and elf_fpregset_t from Linux.  */
diff --git a/gdb/sh-netbsd-tdep.c b/gdb/sh-netbsd-tdep.c
index 4fbb53b49ff..49760337c4b 100644
--- a/gdb/sh-netbsd-tdep.c
+++ b/gdb/sh-netbsd-tdep.c
@@ -63,7 +63,7 @@ static void
 shnbsd_init_abi (struct gdbarch_info info,
 		  struct gdbarch *gdbarch)
 {
-  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
   nbsd_init_abi (info, gdbarch);
 
   tdep->core_gregmap = (struct sh_corefile_regmap *)regmap;
diff --git a/gdb/sh-tdep.c b/gdb/sh-tdep.c
index 2341a9beef6..062df860c81 100644
--- a/gdb/sh-tdep.c
+++ b/gdb/sh-tdep.c
@@ -1554,7 +1554,7 @@ sh_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 static struct type *
 sh_littlebyte_bigword_type (struct gdbarch *gdbarch)
 {
-  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
 
   if (tdep->sh_littlebyte_bigword_type == NULL)
     tdep->sh_littlebyte_bigword_type
@@ -2146,7 +2146,7 @@ sh_corefile_supply_regset (const struct regset *regset,
 			   int regnum, const void *regs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
   const struct sh_corefile_regmap *regmap = (regset == &sh_corefile_gregset
 					     ? tdep->core_gregmap
 					     : tdep->core_fpregmap);
@@ -2172,7 +2172,7 @@ sh_corefile_collect_regset (const struct regset *regset,
 			    int regnum, void *regs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
   const struct sh_corefile_regmap *regmap = (regset == &sh_corefile_gregset
 					     ? tdep->core_gregmap
 					     : tdep->core_fpregmap);
@@ -2210,7 +2210,7 @@ sh_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				 void *cb_data,
 				 const struct regcache *regcache)
 {
-  sh_gdbarch_tdep *tdep = (sh_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
 
   if (tdep->core_gregmap != NULL)
     cb (".reg", tdep->sizeof_gregset, tdep->sizeof_gregset,
diff --git a/gdb/sparc-linux-tdep.c b/gdb/sparc-linux-tdep.c
index 18196b2f075..66481ea7b8a 100644
--- a/gdb/sparc-linux-tdep.c
+++ b/gdb/sparc-linux-tdep.c
@@ -254,7 +254,7 @@ static void
 sparc_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   gdbarch *arch = regcache->arch ();
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
   ULONGEST psr;
 
   regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
@@ -421,7 +421,7 @@ static const struct regset sparc32_linux_fpregset =
 static void
 sparc32_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/sparc-netbsd-tdep.c b/gdb/sparc-netbsd-tdep.c
index a97a772dba2..57c178511fa 100644
--- a/gdb/sparc-netbsd-tdep.c
+++ b/gdb/sparc-netbsd-tdep.c
@@ -295,7 +295,7 @@ static const struct regset sparc32nbsd_fpregset =
 void
 sparc32nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   nbsd_init_abi (info, gdbarch);
 
diff --git a/gdb/sparc-sol2-tdep.c b/gdb/sparc-sol2-tdep.c
index 28eb6f67601..a92e95ce71b 100644
--- a/gdb/sparc-sol2-tdep.c
+++ b/gdb/sparc-sol2-tdep.c
@@ -196,7 +196,7 @@ static const struct frame_unwind sparc32_sol2_sigtramp_frame_unwind =
 static void
 sparc32_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   tdep->gregset = &sparc32_sol2_gregset;
   tdep->sizeof_gregset = 152;
diff --git a/gdb/sparc-tdep.c b/gdb/sparc-tdep.c
index e540263a2fe..397f5489550 100644
--- a/gdb/sparc-tdep.c
+++ b/gdb/sparc-tdep.c
@@ -425,7 +425,7 @@ sparc32_register_name (struct gdbarch *gdbarch, int regnum)
 static struct type *
 sparc_psr_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->sparc_psr_type)
     {
@@ -447,7 +447,7 @@ sparc_psr_type (struct gdbarch *gdbarch)
 static struct type *
 sparc_fsr_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->sparc_fsr_type)
     {
@@ -988,7 +988,7 @@ CORE_ADDR
 sparc_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
 			CORE_ADDR current_pc, struct sparc_frame_cache *cache)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
   unsigned long insn;
   int offset = 0;
   int dest = -1;
@@ -1680,7 +1680,7 @@ sparc_analyze_control_transfer (struct regcache *regcache,
 
       /* Trap instruction (TRAP).  */
       gdbarch *arch = regcache->arch ();
-      sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
+      sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
       return tdep->step_trap (frame, insn);
     }
 
@@ -1731,7 +1731,7 @@ static std::vector<CORE_ADDR>
 sparc_software_single_step (struct regcache *regcache)
 {
   struct gdbarch *arch = regcache->arch ();
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
   CORE_ADDR npc, nnpc;
 
   CORE_ADDR pc, orig_npc;
@@ -1761,7 +1761,7 @@ static void
 sparc_write_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   gdbarch *arch = regcache->arch ();
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
 
   regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
   regcache_cooked_write_unsigned (regcache, tdep->npc_regnum, pc + 4);
@@ -1776,7 +1776,7 @@ sparc_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				    void *cb_data,
 				    const struct regcache *regcache)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   cb (".reg", tdep->sizeof_gregset, tdep->sizeof_gregset, tdep->gregset, NULL,
       cb_data);
diff --git a/gdb/sparc64-fbsd-tdep.c b/gdb/sparc64-fbsd-tdep.c
index 8a288282772..76c682fd521 100644
--- a/gdb/sparc64-fbsd-tdep.c
+++ b/gdb/sparc64-fbsd-tdep.c
@@ -222,7 +222,7 @@ static const struct regset sparc64fbsd_fpregset =
 static void
 sparc64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support. */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/sparc64-linux-tdep.c b/gdb/sparc64-linux-tdep.c
index 9ea72331e93..f5940cfcdee 100644
--- a/gdb/sparc64-linux-tdep.c
+++ b/gdb/sparc64-linux-tdep.c
@@ -262,7 +262,7 @@ static void
 sparc64_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   gdbarch *arch = regcache->arch ();
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (arch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
   ULONGEST state;
 
   regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
@@ -364,7 +364,7 @@ static const struct regset sparc64_linux_fpregset =
 static void
 sparc64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/sparc64-netbsd-tdep.c b/gdb/sparc64-netbsd-tdep.c
index 29cd3b6f3ba..db368118f23 100644
--- a/gdb/sparc64-netbsd-tdep.c
+++ b/gdb/sparc64-netbsd-tdep.c
@@ -248,7 +248,7 @@ static const struct regset sparc64nbsd_fpregset =
 static void
 sparc64nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   nbsd_init_abi (info, gdbarch);
 
diff --git a/gdb/sparc64-obsd-tdep.c b/gdb/sparc64-obsd-tdep.c
index 05ebbd2e84a..d6470a51b65 100644
--- a/gdb/sparc64-obsd-tdep.c
+++ b/gdb/sparc64-obsd-tdep.c
@@ -423,7 +423,7 @@ static const struct regset sparc64obsd_fpregset =
 static void
 sparc64obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   tdep->gregset = &sparc64obsd_gregset;
   tdep->sizeof_gregset = 288;
diff --git a/gdb/sparc64-sol2-tdep.c b/gdb/sparc64-sol2-tdep.c
index 458f0320582..e656c359efa 100644
--- a/gdb/sparc64-sol2-tdep.c
+++ b/gdb/sparc64-sol2-tdep.c
@@ -199,7 +199,7 @@ static const struct frame_unwind sparc64_sol2_sigtramp_frame_unwind =
 static void
 sparc64_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   tdep->gregset = &sparc64_sol2_gregset;
   tdep->sizeof_gregset = 304;
diff --git a/gdb/sparc64-tdep.c b/gdb/sparc64-tdep.c
index 95496d33ad4..5ca5f2dca8c 100644
--- a/gdb/sparc64-tdep.c
+++ b/gdb/sparc64-tdep.c
@@ -648,7 +648,7 @@ sparc64_structure_or_union_p (const struct type *type)
 static struct type *
 sparc64_pstate_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->sparc64_pstate_type)
     {
@@ -675,7 +675,7 @@ sparc64_pstate_type (struct gdbarch *gdbarch)
 static struct type *
 sparc64_ccr_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   if (tdep->sparc64_ccr_type == NULL)
     {
@@ -700,7 +700,7 @@ sparc64_ccr_type (struct gdbarch *gdbarch)
 static struct type *
 sparc64_fsr_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->sparc64_fsr_type)
     {
@@ -733,7 +733,7 @@ sparc64_fsr_type (struct gdbarch *gdbarch)
 static struct type *
 sparc64_fprs_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->sparc64_fprs_type)
     {
@@ -1806,7 +1806,7 @@ sparc64_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr)
 void
 sparc64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = (sparc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
 
   tdep->pc_regnum = SPARC64_PC_REGNUM;
   tdep->npc_regnum = SPARC64_NPC_REGNUM;
diff --git a/gdb/tic6x-linux-tdep.c b/gdb/tic6x-linux-tdep.c
index 5a93294361a..b2422d1ccc0 100644
--- a/gdb/tic6x-linux-tdep.c
+++ b/gdb/tic6x-linux-tdep.c
@@ -45,7 +45,7 @@ static const gdb_byte tic6x_bkpt_bnop_le[] = { 0x22, 0xa1, 0x00, 0x00 };
 static unsigned int
 tic6x_register_sigcontext_offset (unsigned int regnum, struct gdbarch *gdbarch)
 {
-  tic6x_gdbarch_tdep *tdep = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  tic6x_gdbarch_tdep *tdep = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
 
   if (regnum == TIC6X_A4_REGNUM || regnum == TIC6X_A4_REGNUM + 2
       || regnum == TIC6X_A4_REGNUM + 4)
@@ -92,7 +92,7 @@ tic6x_linux_rt_sigreturn_init (const struct tramp_frame *self,
 		    + TIC6X_SIGINFO_SIZE
 		    + 4 + 4 /* uc_flags and *uc_link in struct ucontext.  */
 		    + TIC6X_STACK_T_SIZE);
-  tic6x_gdbarch_tdep *tdep = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  tic6x_gdbarch_tdep *tdep = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
   unsigned int reg_offset;
   unsigned int i;
 
@@ -165,7 +165,7 @@ extern struct target_so_ops dsbt_so_ops;
 static void
 tic6x_uclinux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  tic6x_gdbarch_tdep *tdep = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  tic6x_gdbarch_tdep *tdep = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/tic6x-tdep.c b/gdb/tic6x-tdep.c
index 3e49030ab14..b7efcf18576 100644
--- a/gdb/tic6x-tdep.c
+++ b/gdb/tic6x-tdep.c
@@ -325,7 +325,7 @@ tic6x_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 static const gdb_byte *
 tic6x_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
-  tic6x_gdbarch_tdep *tdep = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  tic6x_gdbarch_tdep *tdep = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
 
   *size = kind;
 
@@ -599,7 +599,7 @@ tic6x_get_next_pc (struct regcache *regcache, CORE_ADDR pc)
       if (inst == TIC6X_INST_SWE)
 	{
 	  tic6x_gdbarch_tdep *tdep
-	    = (tic6x_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	    = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
 
 	  if (tdep->syscall_next_pc != NULL)
 	    return tdep->syscall_next_pc (get_current_frame ());
@@ -1217,7 +1217,7 @@ tic6x_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       tic6x_gdbarch_tdep *tdep
-	= (tic6x_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<tic6x_gdbarch_tdep> (arches->gdbarch);
 
       if (has_gp != tdep->has_gp)
 	continue;
diff --git a/gdb/v850-tdep.c b/gdb/v850-tdep.c
index a67310a2440..4de5faa6a47 100644
--- a/gdb/v850-tdep.c
+++ b/gdb/v850-tdep.c
@@ -511,7 +511,7 @@ v850_use_struct_convention (struct gdbarch *gdbarch, struct type *type)
 {
   int i;
   struct type *fld_type, *tgt_type;
-  v850_gdbarch_tdep *tdep = (v850_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  v850_gdbarch_tdep *tdep = gdbarch_tdep<v850_gdbarch_tdep> (gdbarch);
 
   if (tdep->abi == V850_ABI_RH850)
     {
@@ -1023,7 +1023,7 @@ v850_push_dummy_call (struct gdbarch *gdbarch,
   int argnum;
   int arg_space = 0;
   int stack_offset;
-  v850_gdbarch_tdep *tdep = (v850_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  v850_gdbarch_tdep *tdep = gdbarch_tdep<v850_gdbarch_tdep> (gdbarch);
 
   if (tdep->abi == V850_ABI_RH850)
     stack_offset = 0;
@@ -1374,7 +1374,7 @@ v850_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       v850_gdbarch_tdep *tdep
-	= (v850_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
+	= gdbarch_tdep<v850_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->e_flags != e_flags || tdep->e_machine != e_machine)
 	continue;
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 9705fa33cc2..b62d216a7d3 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -486,7 +486,7 @@ windows_fetch_one_register (struct regcache *regcache,
 
   char *context_offset = context_ptr + windows_process.mappings[r];
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
 
   gdb_assert (!gdbarch_read_pc_p (gdbarch));
   gdb_assert (gdbarch_pc_regnum (gdbarch) >= 0);
diff --git a/gdb/xtensa-linux-nat.c b/gdb/xtensa-linux-nat.c
index 5a08824a680..d005c9d8f78 100644
--- a/gdb/xtensa-linux-nat.c
+++ b/gdb/xtensa-linux-nat.c
@@ -62,7 +62,7 @@ fill_gregset (const struct regcache *regcache,
   int i;
   xtensa_elf_gregset_t *regs = (xtensa_elf_gregset_t *) gregsetp;
   struct gdbarch *gdbarch = regcache->arch ();
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   if (regnum == gdbarch_pc_regnum (gdbarch) || regnum == -1)
     regcache->raw_collect (gdbarch_pc_regnum (gdbarch), &regs->pc);
@@ -124,7 +124,7 @@ supply_gregset_reg (struct regcache *regcache,
   xtensa_elf_gregset_t *regs = (xtensa_elf_gregset_t *) gregsetp;
 
   struct gdbarch *gdbarch = regcache->arch ();
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   if (regnum == gdbarch_pc_regnum (gdbarch) || regnum == -1)
     regcache->raw_supply (gdbarch_pc_regnum (gdbarch), &regs->pc);
diff --git a/gdb/xtensa-linux-tdep.c b/gdb/xtensa-linux-tdep.c
index ef55319fd09..600b59b8894 100644
--- a/gdb/xtensa-linux-tdep.c
+++ b/gdb/xtensa-linux-tdep.c
@@ -99,7 +99,7 @@ xtensa_linux_gdb_signal_to_target (struct gdbarch *gdbarch,
 static void
 xtensa_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   if (tdep->num_nopriv_regs < tdep->num_regs)
     {
diff --git a/gdb/xtensa-tdep.c b/gdb/xtensa-tdep.c
index b6558838e44..f881870e244 100644
--- a/gdb/xtensa-tdep.c
+++ b/gdb/xtensa-tdep.c
@@ -116,7 +116,7 @@ static unsigned int xtensa_debug_level = 0;
 static int
 windowing_enabled (struct gdbarch *gdbarch, unsigned int ps)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   /* If we know CALL0 ABI is set explicitly,  say it is Call0.  */
   if (tdep->call_abi == CallAbiCall0Only)
@@ -130,7 +130,7 @@ windowing_enabled (struct gdbarch *gdbarch, unsigned int ps)
 static int
 arreg_number (struct gdbarch *gdbarch, int a_regnum, ULONGEST wb)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   int arreg;
 
   arreg = a_regnum - tdep->a0_base;
@@ -145,7 +145,7 @@ arreg_number (struct gdbarch *gdbarch, int a_regnum, ULONGEST wb)
 static int
 areg_number (struct gdbarch *gdbarch, int ar_regnum, unsigned int wb)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   int areg;
 
   areg = ar_regnum - tdep->ar_base;
@@ -226,7 +226,7 @@ static int
 xtensa_find_register_by_name (struct gdbarch *gdbarch, const char *name)
 {
   int i;
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   for (i = 0; i < gdbarch_num_cooked_regs (gdbarch); i++)
     if (strcasecmp (tdep->regmap[i].name, name) == 0)
@@ -239,7 +239,7 @@ xtensa_find_register_by_name (struct gdbarch *gdbarch, const char *name)
 static const char *
 xtensa_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   /* Return the name stored in the register map.  */
   if (regnum >= 0 && regnum < gdbarch_num_cooked_regs (gdbarch))
@@ -254,7 +254,7 @@ xtensa_register_name (struct gdbarch *gdbarch, int regnum)
 static struct type *
 xtensa_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   /* Return signed integer for ARx and Ax registers.  */
   if ((regnum >= tdep->ar_base
@@ -339,7 +339,7 @@ static int
 xtensa_reg_to_regnum (struct gdbarch *gdbarch, int regnum)
 {
   int i;
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   if (regnum >= 0 && regnum < 16)
     return tdep->a0_base + regnum;
@@ -542,7 +542,7 @@ xtensa_pseudo_register_read (struct gdbarch *gdbarch,
 {
   DEBUGTRACE ("xtensa_pseudo_register_read (... regnum = %d (%s) ...)\n",
 	      regnum, xtensa_register_name (gdbarch, regnum));
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   /* Read aliases a0..a15, if this is a Windowed ABI.  */
   if (tdep->isa_use_windowed_registers
@@ -634,7 +634,7 @@ xtensa_pseudo_register_write (struct gdbarch *gdbarch,
 {
   DEBUGTRACE ("xtensa_pseudo_register_write (... regnum = %d (%s) ...)\n",
 	      regnum, xtensa_register_name (gdbarch, regnum));
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   /* Renumber register, if aliases a0..a15 on Windowed ABI.  */
   if (tdep->isa_use_windowed_registers
@@ -767,7 +767,7 @@ xtensa_register_reggroup_p (struct gdbarch *gdbarch,
 			    int regnum,
 			    const struct reggroup *group)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   xtensa_register_t* reg = &tdep->regmap[regnum];
   xtensa_register_type_t type = reg->type;
   xtensa_register_group_t rg = reg->group;
@@ -821,7 +821,7 @@ xtensa_supply_gregset (const struct regset *regset,
 {
   const xtensa_elf_gregset_t *regs = (const xtensa_elf_gregset_t *) gregs;
   struct gdbarch *gdbarch = rc->arch ();
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   int i;
 
   DEBUGTRACE ("xtensa_supply_gregset (..., regnum==%d, ...)\n", regnum);
@@ -1050,7 +1050,7 @@ static struct frame_id
 xtensa_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
 {
   CORE_ADDR pc, fp;
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   /* THIS-FRAME is a dummy frame.  Return a frame ID of that frame.  */
 
@@ -1105,7 +1105,7 @@ xtensa_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR current_pc)
 {
 #define RETURN_FP goto done
 
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   unsigned int fp_regnum = tdep->a0_base + 1;
   CORE_ADDR start_addr;
   xtensa_isa isa;
@@ -1255,7 +1255,7 @@ xtensa_frame_cache (struct frame_info *this_frame, void **this_cache)
   if (windowed)
     {
       LONGEST op1;
-      xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
       /* Get WINDOWBASE, WINDOWSTART, and PS registers.  */
       wb = get_frame_register_unsigned (this_frame, 
@@ -1417,7 +1417,7 @@ xtensa_frame_prev_register (struct frame_info *this_frame,
   struct xtensa_frame_cache *cache;
   ULONGEST saved_reg = 0;
   int done = 1;
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   if (*this_cache == NULL)
     *this_cache = xtensa_frame_cache (this_frame, this_cache);
@@ -1546,7 +1546,7 @@ xtensa_extract_return_value (struct type *type,
 
   gdb_assert(len > 0);
 
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   if (tdep->call_abi != CallAbiCall0Only)
     {
       /* First, we have to find the caller window in the register file.  */
@@ -1602,7 +1602,7 @@ xtensa_store_return_value (struct type *type,
 
   DEBUGTRACE ("xtensa_store_return_value (...)\n");
 
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   if (tdep->call_abi != CallAbiCall0Only)
     {
       regcache_raw_read_unsigned 
@@ -1686,7 +1686,7 @@ xtensa_push_dummy_call (struct gdbarch *gdbarch,
 			CORE_ADDR struct_addr)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   int size, onstack_size;
   gdb_byte *buf = (gdb_byte *) alloca (16);
   CORE_ADDR ra, ps;
@@ -1935,7 +1935,7 @@ xtensa_push_dummy_call (struct gdbarch *gdbarch,
 static int
 xtensa_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   if (tdep->isa_use_density_instructions)
     return 2;
@@ -2182,7 +2182,7 @@ call0_track_op (struct gdbarch *gdbarch, xtensa_c0reg_t dst[], xtensa_c0reg_t sr
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   unsigned litbase, litaddr, litval;
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   switch (opclass)
     {
@@ -2557,7 +2557,7 @@ call0_frame_cache (struct frame_info *this_frame,
   CORE_ADDR body_pc=UINT_MAX;	/* PC, where prologue analysis stopped.  */
   CORE_ADDR sp, fp, ra;
   int fp_regnum = C0_SP, c0_hasfp = 0, c0_frmsz = 0, prev_sp = 0, to_stk;
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
  
   sp = get_frame_register_unsigned
     (this_frame, tdep->a0_base + 1);
@@ -2710,7 +2710,7 @@ static int a11_was_saved;
 static void
 execute_l32e (struct gdbarch *gdbarch, int at, int as, int offset, CORE_ADDR wb)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   int atreg = arreg_number (gdbarch, tdep->a0_base + at, wb);
   int asreg = arreg_number (gdbarch, tdep->a0_base + as, wb);
   CORE_ADDR addr = xtensa_read_register (asreg) + offset;
@@ -2740,7 +2740,7 @@ execute_l32e (struct gdbarch *gdbarch, int at, int as, int offset, CORE_ADDR wb)
 static void
 execute_s32e (struct gdbarch *gdbarch, int at, int as, int offset, CORE_ADDR wb)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   int atreg = arreg_number (gdbarch, tdep->a0_base + at, wb);
   int asreg = arreg_number (gdbarch, tdep->a0_base + as, wb);
   CORE_ADDR addr = xtensa_read_register (asreg) + offset;
@@ -2774,7 +2774,7 @@ execute_code (struct gdbarch *gdbarch, CORE_ADDR current_pc, CORE_ADDR wb)
   xtensa_opcode opc;
   int insn_num = 0;
   void (*func) (struct gdbarch *, int, int, int, CORE_ADDR);
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   uint32_t at, as, offset;
 
@@ -2905,7 +2905,7 @@ xtensa_window_interrupt_frame_cache (struct frame_info *this_frame,
   CORE_ADDR ps, wb, ws, ra;
   int epc1_regnum, i, regnum;
   xtensa_exception_handler_t eh_type;
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
 
   /* Read PS, WB, and WS from the hardware. Note that PS register
      must be present, if Windowed ABI is supported.  */
@@ -3019,7 +3019,7 @@ xtensa_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
 
       CORE_ADDR end_func;
 
-      xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
       if ((tdep->call_abi == CallAbiCall0Only)
 	  && call0_ret (start_pc, prologue_sal.end))
 	return start_pc;
@@ -3041,7 +3041,7 @@ xtensa_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
 static void
 xtensa_verify_config (struct gdbarch *gdbarch)
 {
-  xtensa_gdbarch_tdep *tdep = (xtensa_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
   string_file log;
 
   /* Verify that we got a reasonable number of AREGS.  */
diff --git a/gdb/z80-tdep.c b/gdb/z80-tdep.c
index d27e567c358..6a11883e7b4 100644
--- a/gdb/z80-tdep.c
+++ b/gdb/z80-tdep.c
@@ -308,7 +308,7 @@ z80_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR pc_beg, CORE_ADDR pc_end,
 		   struct z80_unwind_cache *info)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  z80_gdbarch_tdep *tdep = (z80_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  z80_gdbarch_tdep *tdep = gdbarch_tdep<z80_gdbarch_tdep> (gdbarch);
   int addr_len = tdep->addr_length;
   gdb_byte prologue[32]; /* max prologue is 24 bytes: __interrupt with local array */
   int pos = 0;
@@ -564,7 +564,7 @@ z80_frame_unwind_cache (struct frame_info *this_frame,
   gdb_byte buf[sizeof(void*)];
   struct z80_unwind_cache *info;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  z80_gdbarch_tdep *tdep = (z80_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  z80_gdbarch_tdep *tdep = gdbarch_tdep<z80_gdbarch_tdep> (gdbarch);
   int addr_len = tdep->addr_length;
 
   if (*this_prologue_cache)
@@ -697,7 +697,7 @@ z80_frame_prev_register (struct frame_info *this_frame,
 	  ULONGEST pc;
 	  gdb_byte buf[3];
 	  struct gdbarch *gdbarch = get_frame_arch (this_frame);
-	  z80_gdbarch_tdep *tdep = (z80_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+	  z80_gdbarch_tdep *tdep = gdbarch_tdep<z80_gdbarch_tdep> (gdbarch);
 	  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
 	  read_memory (info->saved_regs[Z80_PC_REGNUM].addr (),
@@ -750,7 +750,7 @@ z80_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
     }
   else /* kind is non-RST address, use CALL instead, but it is dungerous */
     {
-      z80_gdbarch_tdep *tdep = (z80_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+      z80_gdbarch_tdep *tdep = gdbarch_tdep<z80_gdbarch_tdep> (gdbarch);
       gdb_byte *p = break_insn;
       *p++ = 0xcd;
       *p++ = (kind >> 0) & 0xff;
-- 
2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCHv4 5/6] gdbsupport: add checked_static_cast
  2022-06-28 14:28     ` [PATCHv4 0/6] Detect invalid casts of gdbarch_tdep structures Andrew Burgess
                         ` (3 preceding siblings ...)
  2022-06-28 14:28       ` [PATCHv4 4/6] gdb: move the type cast into gdbarch_tdep Andrew Burgess
@ 2022-06-28 14:28       ` Andrew Burgess
  2022-06-28 14:28       ` [PATCHv4 6/6] gdb: ensure the cast in gdbarch_tdep is valid Andrew Burgess
  2022-07-11 10:46       ` [PATCHv4 0/6] Detect invalid casts of gdbarch_tdep structures Andrew Burgess
  6 siblings, 0 replies; 83+ messages in thread
From: Andrew Burgess @ 2022-06-28 14:28 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess, Pedro Alves, Tom Tromey

Pedro,

This patch is based on the idea you put forward in your feedback.  In
terms of naming I went with gdb::checked_static_cast in the end as I
feel the new function is really replacing static_cast.  The use of
dynamic_cast is really an implementation detail.

Let me know what you think.

Thanks,
Andrew

---

This commit was inspired by these mailing list posts:

  https://sourceware.org/pipermail/gdb-patches/2022-June/190323.html
  https://sourceware.org/pipermail/gdb-patches/2022-April/188098.html

The idea is to add a new function gdb::checked_static_cast, which can,
in some cases, be used as a drop-in replacement for static_cast.  And
so, if I previously wrote this:

  BaseClass *base = get_base_class_pointer ();
  DerivedClass *derived = static_cast<DerivedClass *> (base);

I can now write:

  BaseClass *base = get_base_class_pointer ();
  DerivedClass *derived = gdb::checked_static_cast<DerivedClass *> (base);

The requirement is that BaseClass and DerivedClass must be
polymorphic.

The benefit of making this change is that, when GDB is built in
developer mode, a run-time check will be made to ensure that `base`
really is of type DerivedClass before the cast is performed.  If
`base` is not of type DerivedClass then GDB will assert.

In a non-developer build gdb::checked_static_cast is equivalent to a
static_cast, and there should be no performance difference.

This commit adds the support function, but does not make use of this
function, a use will be added in the next commit.

Co-Authored-By: Pedro Alves <pedro@palves.net>
Co-Authored-By: Tom Tromey <tom@tromey.com>
---
 gdbsupport/gdb-checked-static-cast.h | 68 ++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)
 create mode 100644 gdbsupport/gdb-checked-static-cast.h

diff --git a/gdbsupport/gdb-checked-static-cast.h b/gdbsupport/gdb-checked-static-cast.h
new file mode 100644
index 00000000000..62378e458f8
--- /dev/null
+++ b/gdbsupport/gdb-checked-static-cast.h
@@ -0,0 +1,68 @@
+/* Copyright (C) 2022 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef COMMON_GDB_CHECKED_DYNAMIC_CAST_H
+#define COMMON_GDB_CHECKED_DYNAMIC_CAST_H
+
+#include "gdbsupport/traits.h"
+
+namespace gdb
+{
+
+/* This function can be used in place of static_cast when casting between
+   pointers of polymorphic types.  The benefit of using this call is that,
+   when compiling in developer mode, dynamic_cast will be used to validate
+   the cast.  This use of dynamic_cast is why this function will only
+   work for polymorphic types.
+
+   In non-developer (i.e. production) builds, the dynamic_cast is replaced
+   with a static_cast which is usually significantly faster.  */
+
+template<typename T, typename V>
+T
+checked_static_cast (V *v)
+{
+  /* We only support casting to pointer types.  */
+  static_assert (std::is_pointer<T>::value, "target must be a pointer type");
+
+  /* Check for polymorphic types explicitly in case we're in release mode.  */
+  static_assert (std::is_polymorphic<V>::value, "types must be polymorphic");
+
+  /* Figure out the type that T points to.  */
+  using T_no_P = typename std::remove_pointer<T>::type;
+
+  /* In developer mode this cast uses dynamic_cast to confirm at run-time
+     that the cast from V* to T is valid.  However, we can catch some
+     mistakes at compile time, this assert prevents anything other than
+     downcasts, or casts to same type.  */
+  static_assert (std::is_base_of<V, T_no_P>::value
+                 || std::is_base_of<T_no_P, V>::value,
+                 "types must be related");
+
+#ifdef DEVELOPMENT
+  T result = dynamic_cast<T> (v);
+  gdb_assert (result != nullptr);
+#else
+  T result = static_cast<T> (v);
+#endif
+
+  return result;
+}
+
+}
+
+#endif /* COMMON_GDB_CHECKED_DYNAMIC_CAST_H */
-- 
2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCHv4 6/6] gdb: ensure the cast in gdbarch_tdep is valid
  2022-06-28 14:28     ` [PATCHv4 0/6] Detect invalid casts of gdbarch_tdep structures Andrew Burgess
                         ` (4 preceding siblings ...)
  2022-06-28 14:28       ` [PATCHv4 5/6] gdbsupport: add checked_static_cast Andrew Burgess
@ 2022-06-28 14:28       ` Andrew Burgess
  2022-07-11 10:46       ` [PATCHv4 0/6] Detect invalid casts of gdbarch_tdep structures Andrew Burgess
  6 siblings, 0 replies; 83+ messages in thread
From: Andrew Burgess @ 2022-06-28 14:28 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

This commit makes use of gdb::checked_static_cast when casting the
generic gdbarch_tdep pointer to a specific sub-class type.  This means
that, when compiled in developer mode, GDB will validate that the cast
is correct.

In order to use gdb::checked_static_cast the types involved must have
RTTI, which is why the gdbarch_tdep base class now has a virtual
destructor.

Assuming there are no bugs in GDB where we cast a gdbarch_tdep pointer
to the wrong type, then there should be no changes after this commit.

If any bugs do exist, then GDB will now assert (in a developer build).
---
 gdb/gdbarch.h | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index b2c91db0c4f..16c73915c64 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -28,6 +28,7 @@
 #include "infrun.h"
 #include "osabi.h"
 #include "displaced-stepping.h"
+#include "gdbsupport/gdb-checked-static-cast.h"
 
 struct floatformat;
 struct ui_file;
@@ -58,7 +59,14 @@ struct inferior;
 
 #include "regcache.h"
 
-struct gdbarch_tdep {};
+/* The base class for every architecture's tdep sub-class.  The virtual
+   destructor ensures the class has RTTI information, which allows
+   gdb::checked_static_cast to be used, the gdbarch_tdep the function.  */
+
+struct gdbarch_tdep
+{
+  virtual ~gdbarch_tdep() = default;
+};
 
 /* The architecture associated with the inferior through the
    connection to the target.
@@ -157,7 +165,7 @@ static inline TDepType *
 gdbarch_tdep (struct gdbarch *gdbarch)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep_1 (gdbarch);
-  return static_cast<TDepType *> (tdep);
+  return gdb::checked_static_cast<TDepType *> (tdep);
 }
 
 /* Mechanism for co-ordinating the selection of a specific
-- 
2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v2] gdb+gdbserver/Linux: avoid reading registers while going through shell (was: Re: [PATCHv3 6/6] gdb: native target invalid architecture detection)
  2022-06-28 12:42               ` [PATCH v2] gdb+gdbserver/Linux: avoid reading registers while going through shell (was: Re: [PATCHv3 6/6] gdb: native target invalid architecture detection) Pedro Alves
  2022-06-28 14:21                 ` Andrew Burgess
@ 2022-06-29 15:17                 ` Simon Marchi
  2022-06-29 16:22                   ` [PATCH] Fix GDBserver regression due to change to avoid reading shell registers Pedro Alves
  1 sibling, 1 reply; 83+ messages in thread
From: Simon Marchi @ 2022-06-29 15:17 UTC (permalink / raw)
  To: Pedro Alves, Andrew Burgess, gdb-patches

On 6/28/22 08:42, Pedro Alves wrote:
> On 2022-06-28 11:37, Andrew Burgess wrote:
>> Pedro Alves <pedro@palves.net> writes:
>>
>>> On 2022-06-27 17:27, Andrew Burgess wrote:
>>>> Pedro Alves <pedro@palves.net> writes:
>>> So I gave the patch below a try, and it seems to works well -- readcache_read_pc
>>> is no longer called before target_find_description, and I saw no testsuite
>>> regressions (this is without your series, just pristine master).
>>>
>>> Now, this patch as is makes sense for linux-nat.c, but then I went to do the
>>> same thing for gdbserver, which has an equivalent save_stop_reason in linux-low.cc,
>>> and there this approach won't work as is for the simple fact that lwp->stop_pc
>>> is used in a lot more places.
>>>
>>> So to avoid gdb vs gdbserver divergence, it may be better to not take this patch
>>> as is, but instead tweak save_stop_reason to avoid reading the stop pc while
>>> the inferior is going through the shell, based on some per-inferior flag or some
>>> such.  Maybe we can repurpose progspace->executing_startup for this?  That
>>> flag used to be used by Cell (which is gone), but seems unused nowadays.  There's
>>> also other similar flags in inferior itself, like needs_setup, and
>>> in_initial_library_scan.  So we'd add a flag like one of those, set it while the
>>> inferior is going through the startup_inferior dance, and make save_stop_reason avoid
>>> reading the PC while that flag is set.
> 
> ...
> 
>>
>> Thanks, this looks good.  Maybe you should go ahead and merge this, and
>> the attach problem can be solved separately.
> 
> There's the gdb vs gdbserver divergence issue I pointed out above, though.
> 
> I was thinking we'd instead fix it with the alternative patch below, which
> works for both gdb and gdbserver.
> 
> Tested with no regressions on x86-64 Ubuntu 20.04, native and gdbserver.
> 
> WDYT?
> 
> From 1b7b50e7c8359553af8b8858a82f09d5389d4a1b Mon Sep 17 00:00:00 2001
> From: Pedro Alves <pedro@palves.net>
> Date: Mon, 27 Jun 2022 20:41:50 +0100
> Subject: [PATCH] gdb+gdbserver/Linux: avoid reading registers while going
>  through shell
> 
> For every stop, linux-nat.c saves the stopped thread's PC, in
> lwp->stop_pc.  This is done in save_stop_reason, in both
> gdb/linux-nat.c and gdbserver/linux-low.cc.  However, while we're
> going through the shell after "run", in startup_inferior, we shouldn't
> be reading registers, as we haven't yet determined the target's
> architecture -- the shell's architecture may not even be the same as
> the final inferior's.
> 
> In linux-nat.c, lwp->stop_pc is only needed when the thread has
> stopped for a breakpoint, and since when going through the shell, no
> breakpoint is going to hit, we could simply teach save_stop_reason to
> only record the stop pc when the thread stopped for a breakpoint.
> 
> However, in gdbserver/linux-low.cc, lwp->stop_pc is used in more cases
> than breakpoint hits (e.g., it's used in tracepoints & the
> "while-stepping" feature).
> 
> So to avoid GDB vs GDBserver divergence, we apply the same approach to
> both implementations.
> 
> We set a flag in the inferior (process in gdbserver) whenever it is
> being nursed through the shell, and when that flag is set,
> save_stop_reason bails out early.  While going through the shell,
> we'll only ever get process exits (normal or signalled), and exec
> events, so nothing is lost.
> 
> Change-Id: If0f01831514d3a74d17efd102875de7d2c6401ad

Hi,

This introduces the following ASan crash for me:

$ /home/smarchi/build/binutils-gdb/gdb/testsuite/../../gdb/../gdbserver/gdbserver stdio non-existing-program
=================================================================
==127719==ERROR: AddressSanitizer: heap-use-after-free on address 0x60f0000000e9 at pc 0x55bcbfa301f4 bp 0x7ffd238a7320 sp 0x7ffd238a7310
WRITE of size 1 at 0x60f0000000e9 thread T0
    #0 0x55bcbfa301f3 in scoped_restore_tmpl<bool>::~scoped_restore_tmpl() /home/smarchi/src/binutils-gdb/gdbserver/../gdbsupport/scoped_restore.h:86
    #1 0x55bcbfa2ffe9 in post_fork_inferior(int, char const*) /home/smarchi/src/binutils-gdb/gdbserver/fork-child.cc:120
    #2 0x55bcbf9c9199 in linux_process_target::create_inferior(char const*, std::__debug::vector<char*, std::allocator<char*> > const&) /home/smarchi/src/binutils-gdb/gdbserver/linux-low.cc:991
    #3 0x55bcbf954549 in captured_main /home/smarchi/src/binutils-gdb/gdbserver/server.cc:3941
    #4 0x55bcbf9552f0 in main /home/smarchi/src/binutils-gdb/gdbserver/server.cc:4084
    #5 0x7ff9d663b0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x240b2)
    #6 0x55bcbf8ef2bd in _start (/home/smarchi/build/binutils-gdb/gdbserver/gdbserver+0x1352bd)

0x60f0000000e9 is located 169 bytes inside of 176-byte region [0x60f000000040,0x60f0000000f0)
freed by thread T0 here:
    #0 0x7ff9d6c6f0c7 in operator delete(void*) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:160
    #1 0x55bcbf910d00 in remove_process(process_info*) /home/smarchi/src/binutils-gdb/gdbserver/inferiors.cc:164
    #2 0x55bcbf9c4ac7 in linux_process_target::remove_linux_process(process_info*) /home/smarchi/src/binutils-gdb/gdbserver/linux-low.cc:454
    #3 0x55bcbf9cdaa6 in linux_process_target::mourn(process_info*) /home/smarchi/src/binutils-gdb/gdbserver/linux-low.cc:1599
    #4 0x55bcbf988dc4 in target_mourn_inferior(ptid_t) /home/smarchi/src/binutils-gdb/gdbserver/target.cc:205
    #5 0x55bcbfa32020 in startup_inferior(process_stratum_target*, int, int, target_waitstatus*, ptid_t*) /home/smarchi/src/binutils-gdb/gdbserver/../gdb/nat/fork-inferior.c:515
    #6 0x55bcbfa2fdeb in post_fork_inferior(int, char const*) /home/smarchi/src/binutils-gdb/gdbserver/fork-child.cc:111
    #7 0x55bcbf9c9199 in linux_process_target::create_inferior(char const*, std::__debug::vector<char*, std::allocator<char*> > const&) /home/smarchi/src/binutils-gdb/gdbserver/linux-low.cc:991
    #8 0x55bcbf954549 in captured_main /home/smarchi/src/binutils-gdb/gdbserver/server.cc:3941
    #9 0x55bcbf9552f0 in main /home/smarchi/src/binutils-gdb/gdbserver/server.cc:4084
    #10 0x7ff9d663b0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x240b2)

previously allocated by thread T0 here:
    #0 0x7ff9d6c6e5a7 in operator new(unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:99
    #1 0x55bcbf910ad0 in add_process(int, int) /home/smarchi/src/binutils-gdb/gdbserver/inferiors.cc:144
    #2 0x55bcbf9c477d in linux_process_target::add_linux_process_no_mem_file(int, int) /home/smarchi/src/binutils-gdb/gdbserver/linux-low.cc:425
    #3 0x55bcbf9c8f4c in linux_process_target::create_inferior(char const*, std::__debug::vector<char*, std::allocator<char*> > const&) /home/smarchi/src/binutils-gdb/gdbserver/linux-low.cc:985
    #4 0x55bcbf954549 in captured_main /home/smarchi/src/binutils-gdb/gdbserver/server.cc:3941
    #5 0x55bcbf9552f0 in main /home/smarchi/src/binutils-gdb/gdbserver/server.cc:4084
    #6 0x7ff9d663b0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x240b2)

It looks like in that non-existing-program case, the process gets deleted before
the starting_up flag gets restored to false.

Simon

^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCH] Fix GDBserver regression due to change to avoid reading shell registers
  2022-06-29 15:17                 ` Simon Marchi
@ 2022-06-29 16:22                   ` Pedro Alves
  2022-06-29 16:38                     ` Simon Marchi
  0 siblings, 1 reply; 83+ messages in thread
From: Pedro Alves @ 2022-06-29 16:22 UTC (permalink / raw)
  To: Simon Marchi, Andrew Burgess, gdb-patches

On 2022-06-29 16:17, Simon Marchi wrote:

> This introduces the following ASan crash for me:

...

> It looks like in that non-existing-program case, the process gets deleted before
> the starting_up flag gets restored to false.

Thanks.  The patch below fixes it.  I've also run the whole testsuite with 
--target_board=native-extended-gdbserver, on x86-64 Ubuntu 20.04, with Asan,
and saw no regressions.

From 5ceb44cdf51b764193bea229c80e55ebb0d9c55c Mon Sep 17 00:00:00 2001
From: Pedro Alves <pedro@palves.net>
Date: Wed, 29 Jun 2022 16:38:43 +0100
Subject: [PATCH] Fix GDBserver regression due to change to avoid reading shell
 registers

Simon reported that the recent change to make GDB and GDBserver avoid
reading shell registers caused a GDBserver regression, caught with
ASan while running gdb.server/non-existing-program.exp:

 $ /home/smarchi/build/binutils-gdb/gdb/testsuite/../../gdb/../gdbserver/gdbserver stdio non-existing-program
 =================================================================
 ==127719==ERROR: AddressSanitizer: heap-use-after-free on address 0x60f0000000e9 at pc 0x55bcbfa301f4 bp 0x7ffd238a7320 sp 0x7ffd238a7310
 WRITE of size 1 at 0x60f0000000e9 thread T0
     #0 0x55bcbfa301f3 in scoped_restore_tmpl<bool>::~scoped_restore_tmpl() /home/smarchi/src/binutils-gdb/gdbserver/../gdbsupport/scoped_restore.h:86
     #1 0x55bcbfa2ffe9 in post_fork_inferior(int, char const*) /home/smarchi/src/binutils-gdb/gdbserver/fork-child.cc:120
     #2 0x55bcbf9c9199 in linux_process_target::create_inferior(char const*, std::__debug::vector<char*, std::allocator<char*> > const&) /home/smarchi/src/binutils-gdb/gdbserver/linux-low.cc:991
     #3 0x55bcbf954549 in captured_main /home/smarchi/src/binutils-gdb/gdbserver/server.cc:3941
     #4 0x55bcbf9552f0 in main /home/smarchi/src/binutils-gdb/gdbserver/server.cc:4084
     #5 0x7ff9d663b0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x240b2)
     #6 0x55bcbf8ef2bd in _start (/home/smarchi/build/binutils-gdb/gdbserver/gdbserver+0x1352bd)

 0x60f0000000e9 is located 169 bytes inside of 176-byte region [0x60f000000040,0x60f0000000f0)
 freed by thread T0 here:
     #0 0x7ff9d6c6f0c7 in operator delete(void*) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:160
     #1 0x55bcbf910d00 in remove_process(process_info*) /home/smarchi/src/binutils-gdb/gdbserver/inferiors.cc:164
     #2 0x55bcbf9c4ac7 in linux_process_target::remove_linux_process(process_info*) /home/smarchi/src/binutils-gdb/gdbserver/linux-low.cc:454
     #3 0x55bcbf9cdaa6 in linux_process_target::mourn(process_info*) /home/smarchi/src/binutils-gdb/gdbserver/linux-low.cc:1599
     #4 0x55bcbf988dc4 in target_mourn_inferior(ptid_t) /home/smarchi/src/binutils-gdb/gdbserver/target.cc:205
     #5 0x55bcbfa32020 in startup_inferior(process_stratum_target*, int, int, target_waitstatus*, ptid_t*) /home/smarchi/src/binutils-gdb/gdbserver/../gdb/nat/fork-inferior.c:515
     #6 0x55bcbfa2fdeb in post_fork_inferior(int, char const*) /home/smarchi/src/binutils-gdb/gdbserver/fork-child.cc:111
     #7 0x55bcbf9c9199 in linux_process_target::create_inferior(char const*, std::__debug::vector<char*, std::allocator<char*> > const&) /home/smarchi/src/binutils-gdb/gdbserver/linux-low.cc:991
     #8 0x55bcbf954549 in captured_main /home/smarchi/src/binutils-gdb/gdbserver/server.cc:3941
     #9 0x55bcbf9552f0 in main /home/smarchi/src/binutils-gdb/gdbserver/server.cc:4084
     #10 0x7ff9d663b0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x240b2)

 previously allocated by thread T0 here:
     #0 0x7ff9d6c6e5a7 in operator new(unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:99
     #1 0x55bcbf910ad0 in add_process(int, int) /home/smarchi/src/binutils-gdb/gdbserver/inferiors.cc:144
     #2 0x55bcbf9c477d in linux_process_target::add_linux_process_no_mem_file(int, int) /home/smarchi/src/binutils-gdb/gdbserver/linux-low.cc:425
     #3 0x55bcbf9c8f4c in linux_process_target::create_inferior(char const*, std::__debug::vector<char*, std::allocator<char*> > const&) /home/smarchi/src/binutils-gdb/gdbserver/linux-low.cc:985
     #4 0x55bcbf954549 in captured_main /home/smarchi/src/binutils-gdb/gdbserver/server.cc:3941
     #5 0x55bcbf9552f0 in main /home/smarchi/src/binutils-gdb/gdbserver/server.cc:4084
     #6 0x7ff9d663b0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x240b2)

Above we see that in the non-existing-program case, the process gets
deleted before the starting_up flag gets restored to false.

This happens because startup_inferior call target_mourn_inferior
before throwing an error, and in GDBserver, unlike in GDB, mourning
deletes the process.

Fix this by not using a scoped_restore to manage the starting_up flag,
since we should only clear it when startup_inferior doesn't throw.

Change-Id: I67325d6f81c64de4e89e20e4ec4556f57eac7f6c
---
 gdbserver/fork-child.cc | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/gdbserver/fork-child.cc b/gdbserver/fork-child.cc
index 7ea66f2a435..078612f7091 100644
--- a/gdbserver/fork-child.cc
+++ b/gdbserver/fork-child.cc
@@ -105,12 +105,21 @@ post_fork_inferior (int pid, const char *program)
 #endif
 
   process_info *proc = find_process_pid (pid);
-  scoped_restore save_starting_up
-    = make_scoped_restore (&proc->starting_up, true);
+
+  /* If the inferior fails to start, startup_inferior mourns the
+     process (which deletes it), and then throws an error.  This means
+     that on exception return, we don't need or want to clear this
+     flag back, as PROC won't exist anymore.  Thus, we don't use a
+     scoped_restore.  */
+  proc->starting_up = true;
 
   startup_inferior (the_target, pid,
 		    START_INFERIOR_TRAPS_EXPECTED,
 		    &cs.last_status, &cs.last_ptid);
+
+  /* If we get here, the process was successfully started.  */
+  proc->starting_up = false;
+
   current_thread->last_resume_kind = resume_stop;
   current_thread->last_status = cs.last_status;
   signal_pid = pid;

base-commit: b955c336f93a1b8ab433b713739c145c56f5c027
-- 
2.36.0


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH] Fix GDBserver regression due to change to avoid reading shell registers
  2022-06-29 16:22                   ` [PATCH] Fix GDBserver regression due to change to avoid reading shell registers Pedro Alves
@ 2022-06-29 16:38                     ` Simon Marchi
  0 siblings, 0 replies; 83+ messages in thread
From: Simon Marchi @ 2022-06-29 16:38 UTC (permalink / raw)
  To: Pedro Alves, Andrew Burgess, gdb-patches

On 6/29/22 12:22, Pedro Alves wrote:
> On 2022-06-29 16:17, Simon Marchi wrote:
> 
>> This introduces the following ASan crash for me:
> 
> ...
> 
>> It looks like in that non-existing-program case, the process gets deleted before
>> the starting_up flag gets restored to false.
> 
> Thanks.  The patch below fixes it.  I've also run the whole testsuite with 
> --target_board=native-extended-gdbserver, on x86-64 Ubuntu 20.04, with Asan,
> and saw no regressions.
> 
> From 5ceb44cdf51b764193bea229c80e55ebb0d9c55c Mon Sep 17 00:00:00 2001
> From: Pedro Alves <pedro@palves.net>
> Date: Wed, 29 Jun 2022 16:38:43 +0100
> Subject: [PATCH] Fix GDBserver regression due to change to avoid reading shell
>  registers
> 
> Simon reported that the recent change to make GDB and GDBserver avoid
> reading shell registers caused a GDBserver regression, caught with
> ASan while running gdb.server/non-existing-program.exp:
> 
>  $ /home/smarchi/build/binutils-gdb/gdb/testsuite/../../gdb/../gdbserver/gdbserver stdio non-existing-program
>  =================================================================
>  ==127719==ERROR: AddressSanitizer: heap-use-after-free on address 0x60f0000000e9 at pc 0x55bcbfa301f4 bp 0x7ffd238a7320 sp 0x7ffd238a7310
>  WRITE of size 1 at 0x60f0000000e9 thread T0
>      #0 0x55bcbfa301f3 in scoped_restore_tmpl<bool>::~scoped_restore_tmpl() /home/smarchi/src/binutils-gdb/gdbserver/../gdbsupport/scoped_restore.h:86
>      #1 0x55bcbfa2ffe9 in post_fork_inferior(int, char const*) /home/smarchi/src/binutils-gdb/gdbserver/fork-child.cc:120
>      #2 0x55bcbf9c9199 in linux_process_target::create_inferior(char const*, std::__debug::vector<char*, std::allocator<char*> > const&) /home/smarchi/src/binutils-gdb/gdbserver/linux-low.cc:991
>      #3 0x55bcbf954549 in captured_main /home/smarchi/src/binutils-gdb/gdbserver/server.cc:3941
>      #4 0x55bcbf9552f0 in main /home/smarchi/src/binutils-gdb/gdbserver/server.cc:4084
>      #5 0x7ff9d663b0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x240b2)
>      #6 0x55bcbf8ef2bd in _start (/home/smarchi/build/binutils-gdb/gdbserver/gdbserver+0x1352bd)
> 
>  0x60f0000000e9 is located 169 bytes inside of 176-byte region [0x60f000000040,0x60f0000000f0)
>  freed by thread T0 here:
>      #0 0x7ff9d6c6f0c7 in operator delete(void*) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:160
>      #1 0x55bcbf910d00 in remove_process(process_info*) /home/smarchi/src/binutils-gdb/gdbserver/inferiors.cc:164
>      #2 0x55bcbf9c4ac7 in linux_process_target::remove_linux_process(process_info*) /home/smarchi/src/binutils-gdb/gdbserver/linux-low.cc:454
>      #3 0x55bcbf9cdaa6 in linux_process_target::mourn(process_info*) /home/smarchi/src/binutils-gdb/gdbserver/linux-low.cc:1599
>      #4 0x55bcbf988dc4 in target_mourn_inferior(ptid_t) /home/smarchi/src/binutils-gdb/gdbserver/target.cc:205
>      #5 0x55bcbfa32020 in startup_inferior(process_stratum_target*, int, int, target_waitstatus*, ptid_t*) /home/smarchi/src/binutils-gdb/gdbserver/../gdb/nat/fork-inferior.c:515
>      #6 0x55bcbfa2fdeb in post_fork_inferior(int, char const*) /home/smarchi/src/binutils-gdb/gdbserver/fork-child.cc:111
>      #7 0x55bcbf9c9199 in linux_process_target::create_inferior(char const*, std::__debug::vector<char*, std::allocator<char*> > const&) /home/smarchi/src/binutils-gdb/gdbserver/linux-low.cc:991
>      #8 0x55bcbf954549 in captured_main /home/smarchi/src/binutils-gdb/gdbserver/server.cc:3941
>      #9 0x55bcbf9552f0 in main /home/smarchi/src/binutils-gdb/gdbserver/server.cc:4084
>      #10 0x7ff9d663b0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x240b2)
> 
>  previously allocated by thread T0 here:
>      #0 0x7ff9d6c6e5a7 in operator new(unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:99
>      #1 0x55bcbf910ad0 in add_process(int, int) /home/smarchi/src/binutils-gdb/gdbserver/inferiors.cc:144
>      #2 0x55bcbf9c477d in linux_process_target::add_linux_process_no_mem_file(int, int) /home/smarchi/src/binutils-gdb/gdbserver/linux-low.cc:425
>      #3 0x55bcbf9c8f4c in linux_process_target::create_inferior(char const*, std::__debug::vector<char*, std::allocator<char*> > const&) /home/smarchi/src/binutils-gdb/gdbserver/linux-low.cc:985
>      #4 0x55bcbf954549 in captured_main /home/smarchi/src/binutils-gdb/gdbserver/server.cc:3941
>      #5 0x55bcbf9552f0 in main /home/smarchi/src/binutils-gdb/gdbserver/server.cc:4084
>      #6 0x7ff9d663b0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x240b2)
> 
> Above we see that in the non-existing-program case, the process gets
> deleted before the starting_up flag gets restored to false.
> 
> This happens because startup_inferior call target_mourn_inferior
> before throwing an error, and in GDBserver, unlike in GDB, mourning
> deletes the process.
> 
> Fix this by not using a scoped_restore to manage the starting_up flag,
> since we should only clear it when startup_inferior doesn't throw.
> 
> Change-Id: I67325d6f81c64de4e89e20e4ec4556f57eac7f6c
> ---
>  gdbserver/fork-child.cc | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/gdbserver/fork-child.cc b/gdbserver/fork-child.cc
> index 7ea66f2a435..078612f7091 100644
> --- a/gdbserver/fork-child.cc
> +++ b/gdbserver/fork-child.cc
> @@ -105,12 +105,21 @@ post_fork_inferior (int pid, const char *program)
>  #endif
>  
>    process_info *proc = find_process_pid (pid);
> -  scoped_restore save_starting_up
> -    = make_scoped_restore (&proc->starting_up, true);
> +
> +  /* If the inferior fails to start, startup_inferior mourns the
> +     process (which deletes it), and then throws an error.  This means
> +     that on exception return, we don't need or want to clear this
> +     flag back, as PROC won't exist anymore.  Thus, we don't use a
> +     scoped_restore.  */
> +  proc->starting_up = true;
>  
>    startup_inferior (the_target, pid,
>  		    START_INFERIOR_TRAPS_EXPECTED,
>  		    &cs.last_status, &cs.last_ptid);
> +
> +  /* If we get here, the process was successfully started.  */
> +  proc->starting_up = false;
> +
>    current_thread->last_resume_kind = resume_stop;
>    current_thread->last_status = cs.last_status;
>    signal_pid = pid;
> 
> base-commit: b955c336f93a1b8ab433b713739c145c56f5c027
> -- 
> 2.36.0
> 

Thanks, LGTM.  This is the same fix I had imagined.

Simon

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCHv3 6/6] gdb: native target invalid architecture detection
  2022-06-27 21:38           ` Pedro Alves
  2022-06-28 10:37             ` Andrew Burgess
@ 2022-06-30  9:33             ` Andrew Burgess
  2022-06-30 11:44               ` Pedro Alves
  1 sibling, 1 reply; 83+ messages in thread
From: Andrew Burgess @ 2022-06-30  9:33 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches

Pedro Alves <pedro@palves.net> writes:

> On 2022-06-27 17:27, Andrew Burgess wrote:
>> Pedro Alves <pedro@palves.net> writes:
>>> On 2022-06-13 17:15, Andrew Burgess via Gdb-patches wrote:
>>> I have another question.  I'm confused on how if e.g., on x86-64, you
>>> load a RISC-V binary into GDB, and the try to run it, we don't end up
>>> with architecture of the target description instead.
>> 
>> The problem is that we end up trying to read the registers before we
>> read the target description.  Which I suspect you will say sounds wrong,
>> and I agree.
>> 
>> I removed the error() calls from this patch, and reran GDB, here's the
>> stack at the point of failure:
>> 
>
> ...
>
>>   #11 0x0000000000bf43c4 in regcache_read_pc (regcache=0x30f5f10) at ../../src/gdb/regcache.c:1325
>>   #12 0x00000000009c2e19 in save_stop_reason (lp=0x3a8ff80) at ../../src/gdb/linux-nat.c:2545
>>   #13 0x00000000009c40f0 in linux_nat_filter_event (lwpid=3990223, status=1407) at ../../src/gdb/linux-nat.c:3003
>>   #14 0x00000000009c471a in linux_nat_wait_1 (ptid=..., ourstatus=0x7fffffffa4f0, target_options=...)
>>       at ../../src/gdb/linux-nat.c:3178
>>   #15 0x00000000009c535a in linux_nat_target::wait (this=0x2d27140 <the_amd64_linux_nat_target>, ptid=..., 
>>       ourstatus=0x7fffffffa4f0, target_options=...) at ../../src/gdb/linux-nat.c:3416
>>   #16 0x0000000000dc5f3b in target_wait (ptid=..., status=0x7fffffffa4f0, options=...)
>>       at ../../src/gdb/target.c:2601
>>   #17 0x0000000000abd3c4 in startup_inferior (proc_target=0x2d27140 <the_amd64_linux_nat_target>, pid=3990223, 
>>       ntraps=1, last_waitstatus=0x0, last_ptid=0x0) at ../../src/gdb/nat/fork-inferior.c:482
>
> Alright, we're inside startup_inferior.
>
>> 
>> The initial architecture is riscv:rv32, and it is this architecture that
>> is used for handling the initial stop.
>> 
>> So my first thought was, pretty much as you suggest, that we should
>> fetch the target description earlier, then we'll not run into this
>> problem at all.
>> 
>
> I don't think we should fetch the tdesc earlier, I think that would be incorrect.  Instead,
> we should avoid reading registers while going through the shell.  The shell's registers have
> nothing to do with the final program's registers.  The shell may even be of a different
> architecture from the final inferior's architecture.  Like, if your shell is a 64-bit
> bash, and then the inferior you're going to debug, which the shell execs, is a 32-bit program.
>
>> My problem was figuring out the right place to add such a call.
>> 
>> We know it has to be before we enter regcache_read_pc, as at this point
>> the regcache is already created, and has the wrong architecture.
>> 
>> And it can't really be earlier than linux_nat_filter_event I think, as
>> before this point we don't know that the target has stopped.  We can't
>> probe the target for features (I would assume) if the target is not
>> currently stopped.
>> 
>> This seems to leave either save_stop_reason, or in the early stages of
>> get_thread_regcache maybe.
>> 
>> The problem with save_stop_reason is that it's Linux specific, so any
>> non-Linux targets will need to add their own code to catch this
>> situation.
>
> I think we should change save_stop_reason.  But, change it to avoid reading
> the PC instead.
>
> I don't think that the fact that other targets need to handle this too
> is an issue.
>
>>> It kind of sounds like if GDB detected the incompatibility when we first fetch the
>>> target description, similarly to how we detect it in the cases above, and GDB picked
>>> the target arch or errored out after detecting the incompatibility, then we wouldn't
>>> need a patch like yours?
>> 
>> I agree.  One other aspect is, do we have any native targets that don't
>> support reading a target description?  Hopefully not.
>
> If we do, we have an action plan -- add such support.  I think a tdesc can be just an
> <architecture> element, for instance.
>
>> 
>>>                          How come the mismatch isn't detected then (when we first
>>> retrieve the target description) today?
>> 
>> Hopefully the above makes that clear, but the TLDR answer is: we attempt
>> to read the registers using the current architecture before we fetch the
>> target description.
>> 
>> I suspected that, in part, this patch would be a bit of a straw-man, I'd
>> appreciate any insight you have for how we might reorder things so that
>> the target description can be read before we try to read the registers.
>> 
>
> So I gave the patch below a try, and it seems to works well -- readcache_read_pc
> is no longer called before target_find_description, and I saw no testsuite
> regressions (this is without your series, just pristine master).
>
> Now, this patch as is makes sense for linux-nat.c, but then I went to do the
> same thing for gdbserver, which has an equivalent save_stop_reason in linux-low.cc,
> and there this approach won't work as is for the simple fact that lwp->stop_pc
> is used in a lot more places.
>
> So to avoid gdb vs gdbserver divergence, it may be better to not take this patch
> as is, but instead tweak save_stop_reason to avoid reading the stop pc while
> the inferior is going through the shell, based on some per-inferior flag or some
> such.  Maybe we can repurpose progspace->executing_startup for this?  That
> flag used to be used by Cell (which is gone), but seems unused nowadays.  There's
> also other similar flags in inferior itself, like needs_setup, and
> in_initial_library_scan.  So we'd add a flag like one of those, set it while the
> inferior is going through the startup_inferior dance, and make save_stop_reason avoid
> reading the PC while that flag is set.
>
> Note the patch below applies on top of:
>
>   [PATCH] gdb+gdbserver/Linux: Remove USE_SIGTRAP_SIGINFO fallback
>   https://sourceware.org/pipermail/gdb-patches/2022-June/190372.html
>
> Attaching will need some other fix, because in that case, the procedure is that the core
> requests an attach, and then the target reports an initial stop, and that stop
> makes infrun read the thread's PC, before setup_inferior is called.  It may be
> we need to call setup_inferior earlier.  Or maybe we can just add a target_find_description
> call in linux_nat_target::attach, like remote.c does:
>
>  void
>  extended_remote_target::attach (const char *args, int from_tty)
>  {
>  ...
>    /* Next, if the target can specify a description, read it.  We do
>       this before anything involving memory or registers.  */
>    target_find_description ();
>
> I haven't looked at that in much detail, and I have to leave for tonight.

How about the patch below to solve the attach case?

Thanks,
Andrew

---

commit 73f25fb4e74b528c18fa40e2477ca6f11667ed47
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Wed Jun 29 10:06:38 2022 +0100

    gdb: fetch target description during attach on linux
    
    This commit aims to address the problem of attaching to a native Linux
    process when the current BFD within GDB (as set by the 'file' command)
    is for the wrong architecture.  For example, running on an x86-64
    GNU/Linux target, attaching to an x86-64 process, but GDB is given a
    riscv-v binary.  Currently, in such a situation I see this assertion:
    
      (gdb) file /tmp/riscv.exe
      (gdb) attach 3276515
      Attaching to program: /tmp/riscv.exe, process 3276515
      ../../src/gdb/i387-tdep.c:596: internal-error: i387_supply_fxsave: Assertion `tdep->st0_regnum >= I386_ST0_REGNUM' failed.
    
    The assertion is cause because, after attaching, we try to handle the
    first stop event.  To do this we try to read registers from the
    target, which causes us to call target_ops::fetch_registers, which for
    x86-64 leads to amd64_linux_nat_target::fetch_registers, and for my
    machine, from there I end up (eventually) in i387_supply_fxsave.
    
    This would all be fine, except, as the current file is a riscv-v
    executable, the gdbarch for the current inferior is set to be a riscv-v
    gdbarch, and the gdbarch_tdep is a riscv_gdbarch_tdep.  So, in
    i387_supply_fxsave we do this:
    
      i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
    
    We incorrectly cast the tdep object, and now have undefined behaviour.
    
    The solution to this problem is to ensure that GDB fetches the target
    description early enough that we can change the architecture of the
    current inferior to be x86-64 before we handle the first stop event.
    Currently the target description is fetched in post_create_inferior,
    but this is really too late, by this point the first stop even has
    been handled, and if the current inferior's architecture was wrong,
    then we will have already experienced undefined behaviour by this
    point.
    
    And so, in this commit, I propose calling target_find_description from
    linux_nat_target::attach.  By this point the target has been attached
    too, and is stopped, but GDB has not yet processed the stop,
    i.e. tried to read the $pc register from the target.  This is almost
    enough to resolve the issue, but there is one additional problem.
    
    I did consider adding the target_find_description call to the
    attach_command function, in theory, this would have solved the "needs
    to get the target description earlier" problem for all targets,
    however, I didn't do this.  The comments in attach_command concerned
    me a little, my reading of them was that not every target is
    guaranteed to be stopped by the time we return to attach_command, and
    I'm pretty sure that calling target_find_description for a target that
    is not stopped is a bad idea (as it could require probing for target
    features, which might not be allowed on a running target).  And so, I
    figure, this might be something that needs handling on a target by
    target basis.
    
    Having arranged to fetch the target description earlier, there is just
    one problem left to solve.
    
    As part of calling target_find_description we call gdbarch_update_p,
    which calls gdbarch_find_by_info, which calls gdbarch_info_fill and
    then looks up a suitable gdbarch.
    
    In gdbarch_info_fill, if we have both a target description and a BFD
    supplied by the 'file' command, then we will call
    choose_architecture_for_target to select which of these architectures
    we should use.
    
    The goal of choose_architecture_for_target is to handle the case where
    one of the architectures (target description or BFD architecture) is
    more specific, we then want to use the more specific architecture.
    
    However, in my case we end up trying to choose between the target
    description's x86-64 architecture, and the BFD's riscv-v architecture,
    these architectures are not at all compatible, and so, currently,
    choose_architecture_for_target returns the risc-v architecture.
    
    This means we continue to try and access the target using the risc-v
    gdbarch and riscv_gdbarch_tdep structures, which leads to the same
    assertion.
    
    My second proposal in this patch is that, when we are selecting
    between two completely incompatible architectures in the function
    choose_architecture_for_target, we should default to using the
    architecture of the target description.  This means we will then only
    try to access the target using a gdbarch that is compatible with the
    advertised target description.
    
    With these two fixes in place, now, when I attach to an x86-64 process
    but use a riscv-v binary with GDB, I see this:
    
      (gdb) file /tmp/riscv.exe
      (gdb) attach 3276515
      Attaching to program: /tmp/riscv.exe, process 3276515
      warning: Selected architecture riscv:rv32 is not compatible with reported target architecture i386:x86-64
      Reading symbols from /lib64/libc.so.6...
      (No debugging symbols found in /lib64/libc.so.6)
      Reading symbols from /lib64/ld-linux-x86-64.so.2...
      (No debugging symbols found in /lib64/ld-linux-x86-64.so.2)
      Failed to read a valid object file image from memory.
      0x00007f316710c1e7 in nanosleep () from /lib64/libc.so.6
      (gdb) show architecture
      The target architecture is set to "auto" (currently "i386:x86-64").
    
    The 'Failed to read a valid object file image from memory.' messages
    comes from symbol_file_add_from_memory, which is called from
    add_vsyscall_page.  I think the problem here is that when we try to
    create a BFD to represent the vsysall page we base this BFD off of
    GDB's current BFD, which is a risc-v binary in my case.
    
    However, before that error, we do get the warning about the two
    architectures being incompatible, and, as you can see GDB has selected
    the architecture of the target description.
    
    The debug session is pretty useless at this point as GDB is using the
    symbols from one binary while trying to debug a completely different
    process, but I think this is fine.  GDB didn't crash, and gave a hint
    that there was a problem with the architectures, hopefully, from this
    the user can figure out their mistake.
    
    No test as I don't know how I can reliably compile a binary for a
    different architecture as part of the testsuite.

diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index ff946ee3767..c7994d208db 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -480,10 +480,17 @@ choose_architecture_for_target (const struct target_desc *target_desc,
       if (tdesc_compatible_p (target_desc, selected))
 	return from_target;
 
+      /* The architecture of the BFD and the target are not compatible.
+	 Warn the user, and then use the architecture of the target.  If we
+	 select the architecture of the BFD, and are running on a native
+	 target, then we can end up trying to fetch registers using a
+	 gdbarch of the wrong architecture, e.g. in the case where GDB
+	 attaches to a running process of one architecture, while the
+	 symbol file loaded into GDB is for a different architecture.  */
       warning (_("Selected architecture %s is not compatible "
 		 "with reported target architecture %s"),
 	       selected->printable_name, from_target->printable_name);
-      return selected;
+      return from_target;
     }
 
   if (compat1 == NULL)
@@ -503,11 +510,14 @@ choose_architecture_for_target (const struct target_desc *target_desc,
     return compat1;
 
   /* We have no idea which one is better.  This is a bug, but not
-     a critical problem; warn the user.  */
+     a critical problem; warn the user, then use the architecture of the
+     target.  If we instead chose the architecture of the BFD, and we are
+     using a native target, then GDB can end up trying to fetch registers
+     from the target using an invalid gdbarch.  */
   warning (_("Selected architecture %s is ambiguous with "
 	     "reported target architecture %s"),
 	   selected->printable_name, from_target->printable_name);
-  return selected;
+  return from_target;
 }
 
 /* Functions to manipulate the architecture of the target.  */
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index aa6e3c4b57d..2a2d508668d 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -1141,6 +1141,9 @@ linux_nat_target::attach (const char *args, int from_tty)
      threads and associate pthread info with each LWP.  */
   linux_proc_attach_tgid_threads (lp->ptid.pid (),
 				  attach_proc_task_lwp_callback);
+
+  /* Now the process is stopped we can fetch the target description.  */
+  target_find_description ();
 }
 
 /* Ptrace-detach the thread with pid PID.  */


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCHv3 6/6] gdb: native target invalid architecture detection
  2022-06-30  9:33             ` [PATCHv3 6/6] gdb: native target invalid architecture detection Andrew Burgess
@ 2022-06-30 11:44               ` Pedro Alves
  2022-07-11 10:47                 ` Andrew Burgess
  0 siblings, 1 reply; 83+ messages in thread
From: Pedro Alves @ 2022-06-30 11:44 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

On 2022-06-30 10:33, Andrew Burgess wrote:
> Pedro Alves <pedro@palves.net> writes:
> 
>> On 2022-06-27 17:27, Andrew Burgess wrote:
>>> Pedro Alves <pedro@palves.net> writes:
>>>> On 2022-06-13 17:15, Andrew Burgess via Gdb-patches wrote:
>>>> I have another question.  I'm confused on how if e.g., on x86-64, you
>>>> load a RISC-V binary into GDB, and the try to run it, we don't end up
>>>> with architecture of the target description instead.
>>>
>>> The problem is that we end up trying to read the registers before we
>>> read the target description.  Which I suspect you will say sounds wrong,
>>> and I agree.
>>>

...

>> Attaching will need some other fix, because in that case, the procedure is that the core
>> requests an attach, and then the target reports an initial stop, and that stop
>> makes infrun read the thread's PC, before setup_inferior is called.  It may be
>> we need to call setup_inferior earlier.  Or maybe we can just add a target_find_description
>> call in linux_nat_target::attach, like remote.c does:
>>
>>  void
>>  extended_remote_target::attach (const char *args, int from_tty)
>>  {
>>  ...
>>    /* Next, if the target can specify a description, read it.  We do
>>       this before anything involving memory or registers.  */
>>    target_find_description ();
>>
>> I haven't looked at that in much detail, and I have to leave for tonight.
> 
> How about the patch below to solve the attach case?

I think this should be two patches.  The part about picking the architecture
of the target isn't specific to attaching.  We're counting on it for "run" too.

>     No test as I don't know how I can reliably compile a binary for a
>     different architecture as part of the testsuite.

We don't even need a binary to trigger badness.  Just need to manually
specify an incompatible architecture, with "set architecture", and then "run".
Like, with current master:

$ gdb -ex "set architecture riscv" ~/gdb/tests/main
GNU gdb (GDB) 13.0.50.20220630-git
...
Reading symbols from /home/pedro/gdb/tests/main...
The target architecture is set to "riscv".
(gdb) r
Starting program: /pedro/gdb/tests/main 
warning: Selected architecture riscv is not compatible with reported target architecture i386:x86-64
warning: Architecture rejected target-supplied description
../../src/gdb/i387-tdep.c:957: internal-error: i387_supply_xsave: Assertion `tdep->st0_regnum >= I386_ST0_REGNUM' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
----- Backtrace -----
0x556325d5365b gdb_internal_backtrace_1
        ../../src/gdb/bt-utils.c:122
0x556325d53714 _Z22gdb_internal_backtracev
        ../../src/gdb/bt-utils.c:168
...

A slight difference here compared to actually having a binary of the wrong arch,
is that this isn't "set architecture auto", so by making choose_architecture_for_target
chose the target architecture, we'd be overriding the explicit user selection.  Maybe
that's OK, not sure.  Maybe the right thing to do in that case (when arch is not auto)
is to error out (and kill/detach the inferior) instead of warning.

^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCHv4 0/6] Detect invalid casts of gdbarch_tdep structures
  2022-06-28 14:28     ` [PATCHv4 0/6] Detect invalid casts of gdbarch_tdep structures Andrew Burgess
                         ` (5 preceding siblings ...)
  2022-06-28 14:28       ` [PATCHv4 6/6] gdb: ensure the cast in gdbarch_tdep is valid Andrew Burgess
@ 2022-07-11 10:46       ` Andrew Burgess
  2022-07-21 18:21         ` Andrew Burgess
  6 siblings, 1 reply; 83+ messages in thread
From: Andrew Burgess @ 2022-07-11 10:46 UTC (permalink / raw)
  To: gdb-patches


Ping!

Andrew Burgess <aburgess@redhat.com> writes:

> Changes since v3:
>
>  - Title of series has changed as the last patch, relating to
>    detection of incorrect architecture with a native target, have been
>    dropped.
>
>  - Patches #1 and #2 are unchanged,
>
>  - Patch #3 has had minor updates based on feedback from Luis and Pedro,
>
>  - Patch #4 is unchanged,
>
>  - Patch #5 is new, based on Pedro's feedback,
>
>  - Patch #6 has been updated to make use of the work added in patch
>    #5.
>
> Changes since v2:
>
>  - Patch #3 has been replaced after feedback from Luis.  New patch
>    fixes sider issues for arm, mips, and frv targets, this includes
>    the issue the v2 patch fixed.
>
>  - Nothing else has changed.
>
> Changes since v1:
>
>  - Patches #1 and #2 are unchanged.
>
>  - Patch #3 is new in this version.
>
>  - Patch #4 is unchanged (was patch 3).
>
>  - Patch #5 is updated inline with John's feedback (was patch 4).
>
>  - Patch #6 is extended to handle multi-arch case for rs6000/ppc and
>    arm/aarch64, commit message is updated to discuss these cases, as
>    well as mentioning i386/x86-64 (was patch 5).
>
> ---
>
> Andrew Burgess (6):
>   gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope
>   gdb/mips: rewrite show_mask_address
>   gdb: select suitable thread for gdbarch_adjust_breakpoint_address
>   gdb: move the type cast into gdbarch_tdep
>   gdbsupport: add checked_static_cast
>   gdb: ensure the cast in gdbarch_tdep is valid
>
>  gdb/aarch64-fbsd-nat.c               |   4 +-
>  gdb/aarch64-fbsd-tdep.c              |   6 +-
>  gdb/aarch64-linux-nat.c              |  20 ++--
>  gdb/aarch64-linux-tdep.c             |  10 +-
>  gdb/aarch64-newlib-tdep.c            |   2 +-
>  gdb/aarch64-tdep.c                   |  48 ++++-----
>  gdb/aix-thread.c                     |  28 +++---
>  gdb/alpha-linux-tdep.c               |   2 +-
>  gdb/alpha-netbsd-tdep.c              |   2 +-
>  gdb/alpha-obsd-tdep.c                |   2 +-
>  gdb/alpha-tdep.c                     |  14 +--
>  gdb/amd64-darwin-tdep.c              |   2 +-
>  gdb/amd64-fbsd-nat.c                 |   4 +-
>  gdb/amd64-fbsd-tdep.c                |   4 +-
>  gdb/amd64-linux-tdep.c               |   8 +-
>  gdb/amd64-netbsd-tdep.c              |   2 +-
>  gdb/amd64-obsd-tdep.c                |   2 +-
>  gdb/amd64-sol2-tdep.c                |   2 +-
>  gdb/amd64-tdep.c                     |  34 +++----
>  gdb/amd64-windows-tdep.c             |   2 +-
>  gdb/arc-linux-tdep.c                 |   4 +-
>  gdb/arc-newlib-tdep.c                |   2 +-
>  gdb/arc-tdep.c                       |   8 +-
>  gdb/arch-utils.c                     |   6 +-
>  gdb/arm-fbsd-nat.c                   |   4 +-
>  gdb/arm-fbsd-tdep.c                  |   6 +-
>  gdb/arm-linux-nat.c                  |   8 +-
>  gdb/arm-linux-tdep.c                 |   4 +-
>  gdb/arm-netbsd-nat.c                 |   8 +-
>  gdb/arm-netbsd-tdep.c                |   4 +-
>  gdb/arm-none-tdep.c                  |   2 +-
>  gdb/arm-obsd-tdep.c                  |   2 +-
>  gdb/arm-tdep.c                       | 142 ++++++++++++++-------------
>  gdb/arm-wince-tdep.c                 |   2 +-
>  gdb/avr-tdep.c                       |  12 +--
>  gdb/bfin-tdep.c                      |   4 +-
>  gdb/breakpoint.c                     |  27 +++--
>  gdb/cris-linux-tdep.c                |   2 +-
>  gdb/cris-tdep.c                      |  18 ++--
>  gdb/csky-tdep.c                      |   8 +-
>  gdb/frv-tdep.c                       |   4 +-
>  gdb/ft32-tdep.c                      |   2 +-
>  gdb/gdbarch.h                        |  27 ++++-
>  gdb/hppa-bsd-tdep.c                  |   2 +-
>  gdb/hppa-linux-tdep.c                |   4 +-
>  gdb/hppa-tdep.c                      |  12 +--
>  gdb/i386-bsd-tdep.c                  |   2 +-
>  gdb/i386-darwin-tdep.c               |   4 +-
>  gdb/i386-fbsd-tdep.c                 |   4 +-
>  gdb/i386-gnu-tdep.c                  |   2 +-
>  gdb/i386-go32-tdep.c                 |   2 +-
>  gdb/i386-linux-tdep.c                |   4 +-
>  gdb/i386-netbsd-tdep.c               |   4 +-
>  gdb/i386-nto-tdep.c                  |   6 +-
>  gdb/i386-obsd-tdep.c                 |   2 +-
>  gdb/i386-sol2-tdep.c                 |   2 +-
>  gdb/i386-tdep.c                      |  98 +++++++++---------
>  gdb/i386-windows-tdep.c              |   2 +-
>  gdb/i387-tdep.c                      |  20 ++--
>  gdb/ia64-linux-tdep.c                |   2 +-
>  gdb/ia64-tdep.c                      |  12 +--
>  gdb/loongarch-linux-tdep.c           |   2 +-
>  gdb/loongarch-tdep.c                 |   4 +-
>  gdb/m32c-tdep.c                      |  58 +++++------
>  gdb/m68hc11-tdep.c                   |  12 +--
>  gdb/m68k-bsd-tdep.c                  |   2 +-
>  gdb/m68k-linux-tdep.c                |   2 +-
>  gdb/m68k-tdep.c                      |  38 +++----
>  gdb/mep-tdep.c                       |   6 +-
>  gdb/mips-linux-tdep.c                |   4 +-
>  gdb/mips-tdep.c                      |  85 ++++++++--------
>  gdb/mn10300-tdep.c                   |   2 +-
>  gdb/mn10300-tdep.h                   |   2 +-
>  gdb/msp430-tdep.c                    |  12 +--
>  gdb/nds32-tdep.c                     |  20 ++--
>  gdb/nios2-linux-tdep.c               |   2 +-
>  gdb/nios2-tdep.c                     |   4 +-
>  gdb/or1k-tdep.c                      |   8 +-
>  gdb/ppc-fbsd-nat.c                   |   4 +-
>  gdb/ppc-fbsd-tdep.c                  |   8 +-
>  gdb/ppc-linux-nat.c                  |  22 ++---
>  gdb/ppc-linux-tdep.c                 |  18 ++--
>  gdb/ppc-netbsd-nat.c                 |   6 +-
>  gdb/ppc-netbsd-tdep.c                |   2 +-
>  gdb/ppc-obsd-nat.c                   |   4 +-
>  gdb/ppc-obsd-tdep.c                  |   2 +-
>  gdb/ppc-sysv-tdep.c                  |  22 ++---
>  gdb/ppc64-tdep.c                     |   2 +-
>  gdb/riscv-linux-tdep.c               |   2 +-
>  gdb/riscv-tdep.c                     |  26 ++---
>  gdb/rl78-tdep.c                      |   8 +-
>  gdb/rs6000-aix-nat.c                 |   6 +-
>  gdb/rs6000-aix-tdep.c                |  16 +--
>  gdb/rs6000-lynx178-tdep.c            |   4 +-
>  gdb/rs6000-tdep.c                    | 132 ++++++++++++-------------
>  gdb/rx-tdep.c                        |   2 +-
>  gdb/s390-linux-tdep.c                |  20 ++--
>  gdb/s390-tdep.c                      |  42 ++++----
>  gdb/sh-linux-tdep.c                  |   2 +-
>  gdb/sh-netbsd-tdep.c                 |   2 +-
>  gdb/sh-tdep.c                        |   8 +-
>  gdb/sparc-linux-tdep.c               |   4 +-
>  gdb/sparc-netbsd-tdep.c              |   2 +-
>  gdb/sparc-sol2-tdep.c                |   2 +-
>  gdb/sparc-tdep.c                     |  14 +--
>  gdb/sparc64-fbsd-tdep.c              |   2 +-
>  gdb/sparc64-linux-tdep.c             |   4 +-
>  gdb/sparc64-netbsd-tdep.c            |   2 +-
>  gdb/sparc64-obsd-tdep.c              |   2 +-
>  gdb/sparc64-sol2-tdep.c              |   2 +-
>  gdb/sparc64-tdep.c                   |  10 +-
>  gdb/tic6x-linux-tdep.c               |   6 +-
>  gdb/tic6x-tdep.c                     |   6 +-
>  gdb/v850-tdep.c                      |   6 +-
>  gdb/windows-nat.c                    |   2 +-
>  gdb/xtensa-linux-nat.c               |   4 +-
>  gdb/xtensa-linux-tdep.c              |   2 +-
>  gdb/xtensa-tdep.c                    |  54 +++++-----
>  gdb/z80-tdep.c                       |   8 +-
>  gdbsupport/gdb-checked-static-cast.h |  68 +++++++++++++
>  120 files changed, 811 insertions(+), 700 deletions(-)
>  create mode 100644 gdbsupport/gdb-checked-static-cast.h
>
> -- 
> 2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCHv3 6/6] gdb: native target invalid architecture detection
  2022-06-30 11:44               ` Pedro Alves
@ 2022-07-11 10:47                 ` Andrew Burgess
  0 siblings, 0 replies; 83+ messages in thread
From: Andrew Burgess @ 2022-07-11 10:47 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches

Pedro Alves <pedro@palves.net> writes:

> On 2022-06-30 10:33, Andrew Burgess wrote:
>> Pedro Alves <pedro@palves.net> writes:
>> 
>>> On 2022-06-27 17:27, Andrew Burgess wrote:
>>>> Pedro Alves <pedro@palves.net> writes:
>>>>> On 2022-06-13 17:15, Andrew Burgess via Gdb-patches wrote:
>>>>> I have another question.  I'm confused on how if e.g., on x86-64, you
>>>>> load a RISC-V binary into GDB, and the try to run it, we don't end up
>>>>> with architecture of the target description instead.
>>>>
>>>> The problem is that we end up trying to read the registers before we
>>>> read the target description.  Which I suspect you will say sounds wrong,
>>>> and I agree.
>>>>
>
> ...
>
>>> Attaching will need some other fix, because in that case, the procedure is that the core
>>> requests an attach, and then the target reports an initial stop, and that stop
>>> makes infrun read the thread's PC, before setup_inferior is called.  It may be
>>> we need to call setup_inferior earlier.  Or maybe we can just add a target_find_description
>>> call in linux_nat_target::attach, like remote.c does:
>>>
>>>  void
>>>  extended_remote_target::attach (const char *args, int from_tty)
>>>  {
>>>  ...
>>>    /* Next, if the target can specify a description, read it.  We do
>>>       this before anything involving memory or registers.  */
>>>    target_find_description ();
>>>
>>> I haven't looked at that in much detail, and I have to leave for tonight.
>> 
>> How about the patch below to solve the attach case?
>
> I think this should be two patches.  The part about picking the architecture
> of the target isn't specific to attaching.  We're counting on it for "run" too.
>
>>     No test as I don't know how I can reliably compile a binary for a
>>     different architecture as part of the testsuite.
>
> We don't even need a binary to trigger badness.  Just need to manually
> specify an incompatible architecture, with "set architecture", and
> then "run".

Thanks, I'll work on splitting this patch, and repost.

Andrew


> Like, with current master:
>
> $ gdb -ex "set architecture riscv" ~/gdb/tests/main
> GNU gdb (GDB) 13.0.50.20220630-git
> ...
> Reading symbols from /home/pedro/gdb/tests/main...
> The target architecture is set to "riscv".
> (gdb) r
> Starting program: /pedro/gdb/tests/main 
> warning: Selected architecture riscv is not compatible with reported target architecture i386:x86-64
> warning: Architecture rejected target-supplied description
> ../../src/gdb/i387-tdep.c:957: internal-error: i387_supply_xsave: Assertion `tdep->st0_regnum >= I386_ST0_REGNUM' failed.
> A problem internal to GDB has been detected,
> further debugging may prove unreliable.
> ----- Backtrace -----
> 0x556325d5365b gdb_internal_backtrace_1
>         ../../src/gdb/bt-utils.c:122
> 0x556325d53714 _Z22gdb_internal_backtracev
>         ../../src/gdb/bt-utils.c:168
> ...
>
> A slight difference here compared to actually having a binary of the wrong arch,
> is that this isn't "set architecture auto", so by making choose_architecture_for_target
> chose the target architecture, we'd be overriding the explicit user selection.  Maybe
> that's OK, not sure.  Maybe the right thing to do in that case (when arch is not auto)
> is to error out (and kill/detach the inferior) instead of warning.


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCHv4 0/6] Detect invalid casts of gdbarch_tdep structures
  2022-07-11 10:46       ` [PATCHv4 0/6] Detect invalid casts of gdbarch_tdep structures Andrew Burgess
@ 2022-07-21 18:21         ` Andrew Burgess
  2022-07-22  0:50           ` Luis Machado
  0 siblings, 1 reply; 83+ messages in thread
From: Andrew Burgess @ 2022-07-21 18:21 UTC (permalink / raw)
  To: gdb-patches

Andrew Burgess <aburgess@redhat.com> writes:

> Ping!

I've now merged this series.  Let me know if there are any problems.

Thanks,
Andrew


>
> Andrew Burgess <aburgess@redhat.com> writes:
>
>> Changes since v3:
>>
>>  - Title of series has changed as the last patch, relating to
>>    detection of incorrect architecture with a native target, have been
>>    dropped.
>>
>>  - Patches #1 and #2 are unchanged,
>>
>>  - Patch #3 has had minor updates based on feedback from Luis and Pedro,
>>
>>  - Patch #4 is unchanged,
>>
>>  - Patch #5 is new, based on Pedro's feedback,
>>
>>  - Patch #6 has been updated to make use of the work added in patch
>>    #5.
>>
>> Changes since v2:
>>
>>  - Patch #3 has been replaced after feedback from Luis.  New patch
>>    fixes sider issues for arm, mips, and frv targets, this includes
>>    the issue the v2 patch fixed.
>>
>>  - Nothing else has changed.
>>
>> Changes since v1:
>>
>>  - Patches #1 and #2 are unchanged.
>>
>>  - Patch #3 is new in this version.
>>
>>  - Patch #4 is unchanged (was patch 3).
>>
>>  - Patch #5 is updated inline with John's feedback (was patch 4).
>>
>>  - Patch #6 is extended to handle multi-arch case for rs6000/ppc and
>>    arm/aarch64, commit message is updated to discuss these cases, as
>>    well as mentioning i386/x86-64 (was patch 5).
>>
>> ---
>>
>> Andrew Burgess (6):
>>   gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope
>>   gdb/mips: rewrite show_mask_address
>>   gdb: select suitable thread for gdbarch_adjust_breakpoint_address
>>   gdb: move the type cast into gdbarch_tdep
>>   gdbsupport: add checked_static_cast
>>   gdb: ensure the cast in gdbarch_tdep is valid
>>
>>  gdb/aarch64-fbsd-nat.c               |   4 +-
>>  gdb/aarch64-fbsd-tdep.c              |   6 +-
>>  gdb/aarch64-linux-nat.c              |  20 ++--
>>  gdb/aarch64-linux-tdep.c             |  10 +-
>>  gdb/aarch64-newlib-tdep.c            |   2 +-
>>  gdb/aarch64-tdep.c                   |  48 ++++-----
>>  gdb/aix-thread.c                     |  28 +++---
>>  gdb/alpha-linux-tdep.c               |   2 +-
>>  gdb/alpha-netbsd-tdep.c              |   2 +-
>>  gdb/alpha-obsd-tdep.c                |   2 +-
>>  gdb/alpha-tdep.c                     |  14 +--
>>  gdb/amd64-darwin-tdep.c              |   2 +-
>>  gdb/amd64-fbsd-nat.c                 |   4 +-
>>  gdb/amd64-fbsd-tdep.c                |   4 +-
>>  gdb/amd64-linux-tdep.c               |   8 +-
>>  gdb/amd64-netbsd-tdep.c              |   2 +-
>>  gdb/amd64-obsd-tdep.c                |   2 +-
>>  gdb/amd64-sol2-tdep.c                |   2 +-
>>  gdb/amd64-tdep.c                     |  34 +++----
>>  gdb/amd64-windows-tdep.c             |   2 +-
>>  gdb/arc-linux-tdep.c                 |   4 +-
>>  gdb/arc-newlib-tdep.c                |   2 +-
>>  gdb/arc-tdep.c                       |   8 +-
>>  gdb/arch-utils.c                     |   6 +-
>>  gdb/arm-fbsd-nat.c                   |   4 +-
>>  gdb/arm-fbsd-tdep.c                  |   6 +-
>>  gdb/arm-linux-nat.c                  |   8 +-
>>  gdb/arm-linux-tdep.c                 |   4 +-
>>  gdb/arm-netbsd-nat.c                 |   8 +-
>>  gdb/arm-netbsd-tdep.c                |   4 +-
>>  gdb/arm-none-tdep.c                  |   2 +-
>>  gdb/arm-obsd-tdep.c                  |   2 +-
>>  gdb/arm-tdep.c                       | 142 ++++++++++++++-------------
>>  gdb/arm-wince-tdep.c                 |   2 +-
>>  gdb/avr-tdep.c                       |  12 +--
>>  gdb/bfin-tdep.c                      |   4 +-
>>  gdb/breakpoint.c                     |  27 +++--
>>  gdb/cris-linux-tdep.c                |   2 +-
>>  gdb/cris-tdep.c                      |  18 ++--
>>  gdb/csky-tdep.c                      |   8 +-
>>  gdb/frv-tdep.c                       |   4 +-
>>  gdb/ft32-tdep.c                      |   2 +-
>>  gdb/gdbarch.h                        |  27 ++++-
>>  gdb/hppa-bsd-tdep.c                  |   2 +-
>>  gdb/hppa-linux-tdep.c                |   4 +-
>>  gdb/hppa-tdep.c                      |  12 +--
>>  gdb/i386-bsd-tdep.c                  |   2 +-
>>  gdb/i386-darwin-tdep.c               |   4 +-
>>  gdb/i386-fbsd-tdep.c                 |   4 +-
>>  gdb/i386-gnu-tdep.c                  |   2 +-
>>  gdb/i386-go32-tdep.c                 |   2 +-
>>  gdb/i386-linux-tdep.c                |   4 +-
>>  gdb/i386-netbsd-tdep.c               |   4 +-
>>  gdb/i386-nto-tdep.c                  |   6 +-
>>  gdb/i386-obsd-tdep.c                 |   2 +-
>>  gdb/i386-sol2-tdep.c                 |   2 +-
>>  gdb/i386-tdep.c                      |  98 +++++++++---------
>>  gdb/i386-windows-tdep.c              |   2 +-
>>  gdb/i387-tdep.c                      |  20 ++--
>>  gdb/ia64-linux-tdep.c                |   2 +-
>>  gdb/ia64-tdep.c                      |  12 +--
>>  gdb/loongarch-linux-tdep.c           |   2 +-
>>  gdb/loongarch-tdep.c                 |   4 +-
>>  gdb/m32c-tdep.c                      |  58 +++++------
>>  gdb/m68hc11-tdep.c                   |  12 +--
>>  gdb/m68k-bsd-tdep.c                  |   2 +-
>>  gdb/m68k-linux-tdep.c                |   2 +-
>>  gdb/m68k-tdep.c                      |  38 +++----
>>  gdb/mep-tdep.c                       |   6 +-
>>  gdb/mips-linux-tdep.c                |   4 +-
>>  gdb/mips-tdep.c                      |  85 ++++++++--------
>>  gdb/mn10300-tdep.c                   |   2 +-
>>  gdb/mn10300-tdep.h                   |   2 +-
>>  gdb/msp430-tdep.c                    |  12 +--
>>  gdb/nds32-tdep.c                     |  20 ++--
>>  gdb/nios2-linux-tdep.c               |   2 +-
>>  gdb/nios2-tdep.c                     |   4 +-
>>  gdb/or1k-tdep.c                      |   8 +-
>>  gdb/ppc-fbsd-nat.c                   |   4 +-
>>  gdb/ppc-fbsd-tdep.c                  |   8 +-
>>  gdb/ppc-linux-nat.c                  |  22 ++---
>>  gdb/ppc-linux-tdep.c                 |  18 ++--
>>  gdb/ppc-netbsd-nat.c                 |   6 +-
>>  gdb/ppc-netbsd-tdep.c                |   2 +-
>>  gdb/ppc-obsd-nat.c                   |   4 +-
>>  gdb/ppc-obsd-tdep.c                  |   2 +-
>>  gdb/ppc-sysv-tdep.c                  |  22 ++---
>>  gdb/ppc64-tdep.c                     |   2 +-
>>  gdb/riscv-linux-tdep.c               |   2 +-
>>  gdb/riscv-tdep.c                     |  26 ++---
>>  gdb/rl78-tdep.c                      |   8 +-
>>  gdb/rs6000-aix-nat.c                 |   6 +-
>>  gdb/rs6000-aix-tdep.c                |  16 +--
>>  gdb/rs6000-lynx178-tdep.c            |   4 +-
>>  gdb/rs6000-tdep.c                    | 132 ++++++++++++-------------
>>  gdb/rx-tdep.c                        |   2 +-
>>  gdb/s390-linux-tdep.c                |  20 ++--
>>  gdb/s390-tdep.c                      |  42 ++++----
>>  gdb/sh-linux-tdep.c                  |   2 +-
>>  gdb/sh-netbsd-tdep.c                 |   2 +-
>>  gdb/sh-tdep.c                        |   8 +-
>>  gdb/sparc-linux-tdep.c               |   4 +-
>>  gdb/sparc-netbsd-tdep.c              |   2 +-
>>  gdb/sparc-sol2-tdep.c                |   2 +-
>>  gdb/sparc-tdep.c                     |  14 +--
>>  gdb/sparc64-fbsd-tdep.c              |   2 +-
>>  gdb/sparc64-linux-tdep.c             |   4 +-
>>  gdb/sparc64-netbsd-tdep.c            |   2 +-
>>  gdb/sparc64-obsd-tdep.c              |   2 +-
>>  gdb/sparc64-sol2-tdep.c              |   2 +-
>>  gdb/sparc64-tdep.c                   |  10 +-
>>  gdb/tic6x-linux-tdep.c               |   6 +-
>>  gdb/tic6x-tdep.c                     |   6 +-
>>  gdb/v850-tdep.c                      |   6 +-
>>  gdb/windows-nat.c                    |   2 +-
>>  gdb/xtensa-linux-nat.c               |   4 +-
>>  gdb/xtensa-linux-tdep.c              |   2 +-
>>  gdb/xtensa-tdep.c                    |  54 +++++-----
>>  gdb/z80-tdep.c                       |   8 +-
>>  gdbsupport/gdb-checked-static-cast.h |  68 +++++++++++++
>>  120 files changed, 811 insertions(+), 700 deletions(-)
>>  create mode 100644 gdbsupport/gdb-checked-static-cast.h
>>
>> -- 
>> 2.25.4


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCHv4 0/6] Detect invalid casts of gdbarch_tdep structures
  2022-07-21 18:21         ` Andrew Burgess
@ 2022-07-22  0:50           ` Luis Machado
  2022-07-23  0:02             ` [PATCH] Rename gdbarch_tdep template function to gdbarch_tdep_cast for g++ 4.8 Mark Wielaard
  0 siblings, 1 reply; 83+ messages in thread
From: Luis Machado @ 2022-07-22  0:50 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

On 7/21/22 19:21, Andrew Burgess via Gdb-patches wrote:
> Andrew Burgess <aburgess@redhat.com> writes:
> 
>> Ping!
> 
> I've now merged this series.  Let me know if there are any problems.
> 
> Thanks,
> Andrew

It seems the gdb-centos-x86_64 builder ran into issues:

https://builder.sourceware.org/buildbot/#/builders/71/builds/787


^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCH] Rename gdbarch_tdep template function to gdbarch_tdep_cast for g++ 4.8
  2022-07-22  0:50           ` Luis Machado
@ 2022-07-23  0:02             ` Mark Wielaard
  2022-07-25 11:19               ` Andrew Burgess
  0 siblings, 1 reply; 83+ messages in thread
From: Mark Wielaard @ 2022-07-23  0:02 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess, Luis Machado, Mark Wielaard

commit 08106042d "gdb: move the type cast into gdbarch_tdep" created
a template function with the same name as a struct gdbarch_tdep. This
confused g++ 4.8 believing the struct gdbarch_tdep was an incomplete
type. Fix this by renaming the template function to gdbarch_tdep_cast.
---
 gdb/aarch64-fbsd-nat.c     |   4 +-
 gdb/aarch64-fbsd-tdep.c    |   6 +-
 gdb/aarch64-linux-nat.c    |  20 +++---
 gdb/aarch64-linux-tdep.c   |  10 +--
 gdb/aarch64-newlib-tdep.c  |   2 +-
 gdb/aarch64-tdep.c         |  48 +++++++-------
 gdb/aix-thread.c           |  28 ++++----
 gdb/alpha-linux-tdep.c     |   2 +-
 gdb/alpha-netbsd-tdep.c    |   2 +-
 gdb/alpha-obsd-tdep.c      |   2 +-
 gdb/alpha-tdep.c           |  14 ++--
 gdb/amd64-darwin-tdep.c    |   2 +-
 gdb/amd64-fbsd-nat.c       |   4 +-
 gdb/amd64-fbsd-tdep.c      |   4 +-
 gdb/amd64-linux-tdep.c     |   8 +--
 gdb/amd64-netbsd-tdep.c    |   2 +-
 gdb/amd64-obsd-tdep.c      |   2 +-
 gdb/amd64-sol2-tdep.c      |   2 +-
 gdb/amd64-tdep.c           |  34 +++++-----
 gdb/amd64-windows-tdep.c   |   2 +-
 gdb/arc-linux-tdep.c       |   4 +-
 gdb/arc-newlib-tdep.c      |   2 +-
 gdb/arc-tdep.c             |   8 +--
 gdb/arm-fbsd-nat.c         |   4 +-
 gdb/arm-fbsd-tdep.c        |   6 +-
 gdb/arm-linux-nat.c        |   8 +--
 gdb/arm-linux-tdep.c       |   4 +-
 gdb/arm-netbsd-nat.c       |   8 +--
 gdb/arm-netbsd-tdep.c      |   4 +-
 gdb/arm-none-tdep.c        |   2 +-
 gdb/arm-obsd-tdep.c        |   2 +-
 gdb/arm-tdep.c             | 110 +++++++++++++++----------------
 gdb/arm-wince-tdep.c       |   2 +-
 gdb/avr-tdep.c             |  12 ++--
 gdb/bfin-tdep.c            |   4 +-
 gdb/cris-linux-tdep.c      |   2 +-
 gdb/cris-tdep.c            |  18 ++---
 gdb/csky-tdep.c            |   8 +--
 gdb/frv-tdep.c             |   4 +-
 gdb/ft32-tdep.c            |   2 +-
 gdb/gdbarch.h              |   2 +-
 gdb/hppa-bsd-tdep.c        |   2 +-
 gdb/hppa-linux-tdep.c      |   4 +-
 gdb/hppa-tdep.c            |  12 ++--
 gdb/i386-bsd-tdep.c        |   2 +-
 gdb/i386-darwin-tdep.c     |   4 +-
 gdb/i386-fbsd-tdep.c       |   4 +-
 gdb/i386-gnu-tdep.c        |   2 +-
 gdb/i386-go32-tdep.c       |   2 +-
 gdb/i386-linux-tdep.c      |   4 +-
 gdb/i386-netbsd-tdep.c     |   4 +-
 gdb/i386-nto-tdep.c        |   6 +-
 gdb/i386-obsd-tdep.c       |   2 +-
 gdb/i386-sol2-tdep.c       |   2 +-
 gdb/i386-tdep.c            |  98 +++++++++++++--------------
 gdb/i386-windows-tdep.c    |   2 +-
 gdb/i387-tdep.c            |  20 +++---
 gdb/ia64-linux-tdep.c      |   2 +-
 gdb/ia64-tdep.c            |  12 ++--
 gdb/loongarch-linux-tdep.c |   2 +-
 gdb/loongarch-tdep.c       |   4 +-
 gdb/m32c-tdep.c            |  58 ++++++++--------
 gdb/m68hc11-tdep.c         |  12 ++--
 gdb/m68k-bsd-tdep.c        |   2 +-
 gdb/m68k-linux-tdep.c      |   2 +-
 gdb/m68k-tdep.c            |  38 +++++------
 gdb/mep-tdep.c             |   6 +-
 gdb/mips-linux-tdep.c      |   4 +-
 gdb/mips-tdep.c            |  50 +++++++-------
 gdb/mn10300-tdep.c         |   2 +-
 gdb/mn10300-tdep.h         |   2 +-
 gdb/msp430-tdep.c          |  12 ++--
 gdb/nds32-tdep.c           |  20 +++---
 gdb/nios2-linux-tdep.c     |   2 +-
 gdb/nios2-tdep.c           |   4 +-
 gdb/or1k-tdep.c            |   8 +--
 gdb/ppc-fbsd-nat.c         |   4 +-
 gdb/ppc-fbsd-tdep.c        |   8 +--
 gdb/ppc-linux-nat.c        |  22 +++----
 gdb/ppc-linux-tdep.c       |  18 ++---
 gdb/ppc-netbsd-nat.c       |   6 +-
 gdb/ppc-netbsd-tdep.c      |   2 +-
 gdb/ppc-obsd-nat.c         |   4 +-
 gdb/ppc-obsd-tdep.c        |   2 +-
 gdb/ppc-sysv-tdep.c        |  22 +++----
 gdb/ppc64-tdep.c           |   2 +-
 gdb/riscv-linux-tdep.c     |   2 +-
 gdb/riscv-tdep.c           |  26 ++++----
 gdb/rl78-tdep.c            |   8 +--
 gdb/rs6000-aix-nat.c       |   6 +-
 gdb/rs6000-aix-tdep.c      |  16 ++---
 gdb/rs6000-lynx178-tdep.c  |   4 +-
 gdb/rs6000-tdep.c          | 132 ++++++++++++++++++-------------------
 gdb/rx-tdep.c              |   2 +-
 gdb/s390-linux-tdep.c      |  20 +++---
 gdb/s390-tdep.c            |  42 ++++++------
 gdb/sh-linux-tdep.c        |   2 +-
 gdb/sh-netbsd-tdep.c       |   2 +-
 gdb/sh-tdep.c              |   8 +--
 gdb/sparc-linux-tdep.c     |   4 +-
 gdb/sparc-netbsd-tdep.c    |   2 +-
 gdb/sparc-sol2-tdep.c      |   2 +-
 gdb/sparc-tdep.c           |  14 ++--
 gdb/sparc64-fbsd-tdep.c    |   2 +-
 gdb/sparc64-linux-tdep.c   |   4 +-
 gdb/sparc64-netbsd-tdep.c  |   2 +-
 gdb/sparc64-obsd-tdep.c    |   2 +-
 gdb/sparc64-sol2-tdep.c    |   2 +-
 gdb/sparc64-tdep.c         |  10 +--
 gdb/tic6x-linux-tdep.c     |   6 +-
 gdb/tic6x-tdep.c           |   6 +-
 gdb/v850-tdep.c            |   6 +-
 gdb/windows-nat.c          |   2 +-
 gdb/xtensa-linux-nat.c     |   4 +-
 gdb/xtensa-linux-tdep.c    |   2 +-
 gdb/xtensa-tdep.c          |  54 +++++++--------
 gdb/z80-tdep.c             |   8 +--
 117 files changed, 659 insertions(+), 659 deletions(-)

diff --git a/gdb/aarch64-fbsd-nat.c b/gdb/aarch64-fbsd-nat.c
index 708ddc40d58..43dfb97ff52 100644
--- a/gdb/aarch64-fbsd-nat.c
+++ b/gdb/aarch64-fbsd-nat.c
@@ -90,7 +90,7 @@ aarch64_fbsd_nat_target::fetch_registers (struct regcache *regcache,
 				    &aarch64_fbsd_fpregset);
 
   gdbarch *gdbarch = regcache->arch ();
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
   if (tdep->has_tls ())
     {
       const struct regcache_map_entry aarch64_fbsd_tls_regmap[] =
@@ -123,7 +123,7 @@ aarch64_fbsd_nat_target::store_registers (struct regcache *regcache,
 				    PT_SETFPREGS, &aarch64_fbsd_fpregset);
 
   gdbarch *gdbarch = regcache->arch ();
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
   if (tdep->has_tls ())
     {
       const struct regcache_map_entry aarch64_fbsd_tls_regmap[] =
diff --git a/gdb/aarch64-fbsd-tdep.c b/gdb/aarch64-fbsd-tdep.c
index 4a6b4115234..0cbb40149b2 100644
--- a/gdb/aarch64-fbsd-tdep.c
+++ b/gdb/aarch64-fbsd-tdep.c
@@ -143,7 +143,7 @@ aarch64_fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					   void *cb_data,
 					   const struct regcache *regcache)
 {
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
 
   cb (".reg", AARCH64_FBSD_SIZEOF_GREGSET, AARCH64_FBSD_SIZEOF_GREGSET,
       &aarch64_fbsd_gregset, NULL, cb_data);
@@ -190,7 +190,7 @@ static CORE_ADDR
 aarch64_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 				       CORE_ADDR lm_addr, CORE_ADDR offset)
 {
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
   struct regcache *regcache;
 
   regcache = get_thread_arch_regcache (current_inferior ()->process_target (),
@@ -213,7 +213,7 @@ aarch64_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 static void
 aarch64_fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support.  */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c
index a457fcd48ad..3de7d407149 100644
--- a/gdb/aarch64-linux-nat.c
+++ b/gdb/aarch64-linux-nat.c
@@ -359,7 +359,7 @@ static void
 fetch_pauth_masks_from_thread (struct regcache *regcache)
 {
   aarch64_gdbarch_tdep *tdep
-    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
+    = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (regcache->arch ());
   int ret;
   struct iovec iovec;
   uint64_t pauth_regset[2] = {0, 0};
@@ -385,7 +385,7 @@ static void
 fetch_mteregs_from_thread (struct regcache *regcache)
 {
   aarch64_gdbarch_tdep *tdep
-    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
+    = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (regcache->arch ());
   int regno = tdep->mte_reg_base;
 
   gdb_assert (regno != -1);
@@ -410,7 +410,7 @@ static void
 store_mteregs_to_thread (struct regcache *regcache)
 {
   aarch64_gdbarch_tdep *tdep
-    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
+    = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (regcache->arch ());
   int regno = tdep->mte_reg_base;
 
   gdb_assert (regno != -1);
@@ -439,7 +439,7 @@ static void
 fetch_tlsregs_from_thread (struct regcache *regcache)
 {
   aarch64_gdbarch_tdep *tdep
-    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
+    = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (regcache->arch ());
   int regno = tdep->tls_regnum;
 
   gdb_assert (regno != -1);
@@ -464,7 +464,7 @@ static void
 store_tlsregs_to_thread (struct regcache *regcache)
 {
   aarch64_gdbarch_tdep *tdep
-    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
+    = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (regcache->arch ());
   int regno = tdep->tls_regnum;
 
   gdb_assert (regno != -1);
@@ -493,7 +493,7 @@ static void
 aarch64_fetch_registers (struct regcache *regcache, int regno)
 {
   aarch64_gdbarch_tdep *tdep
-    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
+    = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (regcache->arch ());
 
   if (regno == -1)
     {
@@ -543,7 +543,7 @@ static void
 aarch32_fetch_registers (struct regcache *regcache, int regno)
 {
   arm_gdbarch_tdep *tdep
-    = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
+    = gdbarch_tdep_cast<arm_gdbarch_tdep> (regcache->arch ());
 
   if (regno == -1)
     {
@@ -579,7 +579,7 @@ static void
 aarch64_store_registers (struct regcache *regcache, int regno)
 {
   aarch64_gdbarch_tdep *tdep
-    = gdbarch_tdep<aarch64_gdbarch_tdep> (regcache->arch ());
+    = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (regcache->arch ());
 
   if (regno == -1)
     {
@@ -619,7 +619,7 @@ static void
 aarch32_store_registers (struct regcache *regcache, int regno)
 {
   arm_gdbarch_tdep *tdep
-    = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
+    = gdbarch_tdep_cast<arm_gdbarch_tdep> (regcache->arch ());
 
   if (regno == -1)
     {
@@ -893,7 +893,7 @@ aarch64_linux_nat_target::thread_architecture (ptid_t ptid)
 
   /* Only return it if the current vector length matches the one in the tdep.  */
   aarch64_gdbarch_tdep *tdep
-    = gdbarch_tdep<aarch64_gdbarch_tdep> (inf->gdbarch);
+    = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (inf->gdbarch);
   uint64_t vq = aarch64_sve_get_vq (ptid.lwp ());
   if (vq == tdep->vq)
     return inf->gdbarch;
diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c
index 15773c75da8..ed9e3b1e2bc 100644
--- a/gdb/aarch64-linux-tdep.c
+++ b/gdb/aarch64-linux-tdep.c
@@ -289,7 +289,7 @@ aarch64_linux_sigframe_init (const struct tramp_frame *self,
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
   CORE_ADDR sp = get_frame_register_unsigned (this_frame, AARCH64_SP_REGNUM);
   CORE_ADDR sigcontext_addr = (sp + AARCH64_RT_SIGFRAME_UCONTEXT_OFFSET
 			       + AARCH64_UCONTEXT_SIGCONTEXT_OFFSET );
@@ -643,7 +643,7 @@ aarch64_linux_collect_sve_regset (const struct regset *regset,
   gdb_byte *header = (gdb_byte *) buf;
   struct gdbarch *gdbarch = regcache->arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
   uint64_t vq = tdep->vq;
 
   gdb_assert (buf != NULL);
@@ -679,7 +679,7 @@ aarch64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					    void *cb_data,
 					    const struct regcache *regcache)
 {
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
 
   cb (".reg", AARCH64_LINUX_SIZEOF_GREGSET, AARCH64_LINUX_SIZEOF_GREGSET,
       &aarch64_linux_gregset, NULL, cb_data);
@@ -1748,7 +1748,7 @@ aarch64_linux_report_signal_info (struct gdbarch *gdbarch,
 				  struct ui_out *uiout,
 				  enum gdb_signal siggnal)
 {
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
 
   if (!tdep->has_mte () || siggnal != GDB_SIGNAL_SEGV)
     return;
@@ -1970,7 +1970,7 @@ aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 								    NULL };
   static const char *const stap_register_indirection_suffixes[] = { "]",
 								    NULL };
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
 
   tdep->lowest_pc = 0x8000;
 
diff --git a/gdb/aarch64-newlib-tdep.c b/gdb/aarch64-newlib-tdep.c
index c9236b17801..1be7dd86041 100644
--- a/gdb/aarch64-newlib-tdep.c
+++ b/gdb/aarch64-newlib-tdep.c
@@ -29,7 +29,7 @@
 static void
 aarch64_newlib_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
 
   /* Jump buffer - support for longjmp.
      Offset of original PC in jump buffer (in registers).  */
diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
index 8670197a888..03fe79c1190 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -502,7 +502,7 @@ aarch64_analyze_prologue (struct gdbarch *gdbarch,
       else if (inst.opcode->iclass == ic_system)
 	{
 	  aarch64_gdbarch_tdep *tdep
-	    = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+	    = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
 	  int ra_state_val = 0;
 
 	  if (insn == 0xd503233f /* paciasp.  */
@@ -640,7 +640,7 @@ aarch64_analyze_prologue_test (void)
   struct aarch64_prologue_cache cache;
   cache.saved_regs = trad_frame_alloc_saved_regs (gdbarch);
 
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
 
   /* Test the simple prologue in which frame pointer is used.  */
   {
@@ -1076,7 +1076,7 @@ aarch64_prologue_frame_unwind_stop_reason (struct frame_info *this_frame,
 
   /* Halt the backtrace at "_start".  */
   gdbarch *arch = get_frame_arch (this_frame);
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (arch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (arch);
   if (cache->prev_pc <= tdep->lowest_pc)
     return UNWIND_OUTERMOST;
 
@@ -1120,7 +1120,7 @@ aarch64_prologue_prev_register (struct frame_info *this_frame,
       CORE_ADDR lr;
       struct gdbarch *gdbarch = get_frame_arch (this_frame);
       aarch64_gdbarch_tdep *tdep
-	= gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+	= gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
 
       lr = frame_unwind_register_unsigned (this_frame, AARCH64_LR_REGNUM);
 
@@ -1289,7 +1289,7 @@ aarch64_dwarf2_prev_register (struct frame_info *this_frame,
 			      void **this_cache, int regnum)
 {
   gdbarch *arch = get_frame_arch (this_frame);
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (arch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (arch);
   CORE_ADDR lr;
 
   switch (regnum)
@@ -1315,7 +1315,7 @@ aarch64_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
 			       struct dwarf2_frame_state_reg *reg,
 			       struct frame_info *this_frame)
 {
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
 
   switch (regnum)
     {
@@ -1355,7 +1355,7 @@ static bool
 aarch64_execute_dwarf_cfa_vendor_op (struct gdbarch *gdbarch, gdb_byte op,
 				     struct dwarf2_frame_state *fs)
 {
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
   struct dwarf2_frame_state_reg *ra_state;
 
   if (op == DW_CFA_AARCH64_negate_ra_state)
@@ -1996,7 +1996,7 @@ aarch64_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
 static struct type *
 aarch64_vnq_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vnq_type == NULL)
     {
@@ -2023,7 +2023,7 @@ aarch64_vnq_type (struct gdbarch *gdbarch)
 static struct type *
 aarch64_vnd_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vnd_type == NULL)
     {
@@ -2053,7 +2053,7 @@ aarch64_vnd_type (struct gdbarch *gdbarch)
 static struct type *
 aarch64_vns_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vns_type == NULL)
     {
@@ -2083,7 +2083,7 @@ aarch64_vns_type (struct gdbarch *gdbarch)
 static struct type *
 aarch64_vnh_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vnh_type == NULL)
     {
@@ -2116,7 +2116,7 @@ aarch64_vnh_type (struct gdbarch *gdbarch)
 static struct type *
 aarch64_vnb_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vnb_type == NULL)
     {
@@ -2143,7 +2143,7 @@ aarch64_vnb_type (struct gdbarch *gdbarch)
 static struct type *
 aarch64_vnv_type (struct gdbarch *gdbarch)
 {
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep->vnv_type == NULL)
     {
@@ -2214,7 +2214,7 @@ aarch64_vnv_type (struct gdbarch *gdbarch)
 static int
 aarch64_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 {
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
 
   if (reg >= AARCH64_DWARF_X0 && reg <= AARCH64_DWARF_X0 + 30)
     return AARCH64_X0_REGNUM + reg - AARCH64_DWARF_X0;
@@ -2518,7 +2518,7 @@ aarch64_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
   CORE_ADDR jb_addr;
   gdb_byte buf[X_REGISTER_SIZE];
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   jb_addr = get_frame_register_unsigned (frame, AARCH64_X0_REGNUM);
@@ -2549,7 +2549,7 @@ aarch64_gen_return_address (struct gdbarch *gdbarch,
 static const char *
 aarch64_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
 
   static const char *const q_name[] =
     {
@@ -2663,7 +2663,7 @@ aarch64_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 static struct type *
 aarch64_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
 
   int p_regnum = regnum - gdbarch_num_regs (gdbarch);
 
@@ -2700,7 +2700,7 @@ static int
 aarch64_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 				    const struct reggroup *group)
 {
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
 
   int p_regnum = regnum - gdbarch_num_regs (gdbarch);
 
@@ -2754,7 +2754,7 @@ static struct value *
 aarch64_pseudo_read_value (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int regnum)
 {
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
   struct value *result_value = allocate_value (register_type (gdbarch, regnum));
 
   VALUE_LVAL (result_value) = lval_register;
@@ -2824,7 +2824,7 @@ static void
 aarch64_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache,
 		      int regnum, const gdb_byte *buf)
 {
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
   regnum -= gdbarch_num_regs (gdbarch);
 
   if (regnum >= AARCH64_Q0_REGNUM && regnum < AARCH64_Q0_REGNUM + 32)
@@ -3377,7 +3377,7 @@ aarch64_get_tdesc_vq (const struct target_desc *tdesc)
 static int
 aarch64_cannot_store_register (struct gdbarch *gdbarch, int regnum)
 {
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
 
   if (!tdep->has_pauth ())
     return 0;
@@ -3444,7 +3444,7 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
     {
       aarch64_gdbarch_tdep *tdep
-	= gdbarch_tdep<aarch64_gdbarch_tdep> (best_arch->gdbarch);
+	= gdbarch_tdep_cast<aarch64_gdbarch_tdep> (best_arch->gdbarch);
       if (tdep && tdep->vq == vq)
 	return best_arch->gdbarch;
     }
@@ -3693,7 +3693,7 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 aarch64_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+  aarch64_gdbarch_tdep *tdep = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (gdbarch);
 
   if (tdep == NULL)
     return;
@@ -3915,7 +3915,7 @@ aarch64_record_branch_except_sys (aarch64_insn_decode_record *aarch64_insn_r)
 {
 
   aarch64_gdbarch_tdep *tdep
-    = gdbarch_tdep<aarch64_gdbarch_tdep> (aarch64_insn_r->gdbarch);
+    = gdbarch_tdep_cast<aarch64_gdbarch_tdep> (aarch64_insn_r->gdbarch);
   uint8_t insn_bits24_27, insn_bits28_31, insn_bits22_23;
   uint32_t record_buf[4];
 
diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c
index 4c9195a7f12..f49d721bd1f 100644
--- a/gdb/aix-thread.c
+++ b/gdb/aix-thread.c
@@ -1111,7 +1111,7 @@ static void
 supply_gprs64 (struct regcache *regcache, uint64_t *vals)
 {
   ppc_gdbarch_tdep *tdep
-    = gdbarch_tdep<ppc_gdbarch_tdep> (regcache->arch ());
+    = gdbarch_tdep_cast<ppc_gdbarch_tdep> (regcache->arch ());
   int regno;
 
   for (regno = 0; regno < ppc_num_gprs; regno++)
@@ -1133,7 +1133,7 @@ static void
 supply_fprs (struct regcache *regcache, double *vals)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int regno;
 
   /* This function should never be called on architectures without
@@ -1151,7 +1151,7 @@ supply_fprs (struct regcache *regcache, double *vals)
 static int
 special_register_p (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   return regno == gdbarch_pc_regnum (gdbarch)
       || regno == tdep->ppc_ps_regnum
@@ -1174,7 +1174,7 @@ supply_sprs64 (struct regcache *regcache,
 	       uint32_t fpscr)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   regcache->raw_supply (gdbarch_pc_regnum (gdbarch), (char *) &iar);
   regcache->raw_supply (tdep->ppc_ps_regnum, (char *) &msr);
@@ -1196,7 +1196,7 @@ supply_sprs32 (struct regcache *regcache,
 	       uint32_t fpscr)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   regcache->raw_supply (gdbarch_pc_regnum (gdbarch), (char *) &iar);
   regcache->raw_supply (tdep->ppc_ps_regnum, (char *) &msr);
@@ -1219,7 +1219,7 @@ static void
 fetch_regs_user_thread (struct regcache *regcache, pthdb_pthread_t pdtid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int status, i;
   pthdb_context_t ctx;
 
@@ -1274,7 +1274,7 @@ fetch_regs_kernel_thread (struct regcache *regcache, int regno,
 			  pthdb_tid_t tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   uint64_t gprs64[ppc_num_gprs];
   uint32_t gprs32[ppc_num_gprs];
   double fprs[ppc_num_fprs];
@@ -1377,7 +1377,7 @@ static void
 fill_gprs64 (const struct regcache *regcache, uint64_t *vals)
 {
   ppc_gdbarch_tdep *tdep
-    = gdbarch_tdep<ppc_gdbarch_tdep> (regcache->arch ());
+    = gdbarch_tdep_cast<ppc_gdbarch_tdep> (regcache->arch ());
   int regno;
 
   for (regno = 0; regno < ppc_num_gprs; regno++)
@@ -1390,7 +1390,7 @@ static void
 fill_gprs32 (const struct regcache *regcache, uint32_t *vals)
 {
   ppc_gdbarch_tdep *tdep
-    = gdbarch_tdep<ppc_gdbarch_tdep> (regcache->arch ());
+    = gdbarch_tdep_cast<ppc_gdbarch_tdep> (regcache->arch ());
   int regno;
 
   for (regno = 0; regno < ppc_num_gprs; regno++)
@@ -1404,7 +1404,7 @@ static void
 fill_fprs (const struct regcache *regcache, double *vals)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int regno;
 
   /* This function should never be called on architectures without
@@ -1428,7 +1428,7 @@ fill_sprs64 (const struct regcache *regcache,
 	     uint32_t *fpscr)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   /* Verify that the size of the size of the IAR buffer is the
      same as the raw size of the PC (in the register cache).  If
@@ -1462,7 +1462,7 @@ fill_sprs32 (const struct regcache *regcache,
 	     uint32_t *fpscr)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   /* Verify that the size of the size of the IAR buffer is the
      same as the raw size of the PC (in the register cache).  If
@@ -1499,7 +1499,7 @@ static void
 store_regs_user_thread (const struct regcache *regcache, pthdb_pthread_t pdtid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int status, i;
   pthdb_context_t ctx;
   uint32_t int32;
@@ -1589,7 +1589,7 @@ store_regs_kernel_thread (const struct regcache *regcache, int regno,
 			  pthdb_tid_t tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   uint64_t gprs64[ppc_num_gprs];
   uint32_t gprs32[ppc_num_gprs];
   double fprs[ppc_num_fprs];
diff --git a/gdb/alpha-linux-tdep.c b/gdb/alpha-linux-tdep.c
index c103aafc1ff..eaae46f03f0 100644
--- a/gdb/alpha-linux-tdep.c
+++ b/gdb/alpha-linux-tdep.c
@@ -362,7 +362,7 @@ alpha_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   /* Hook into the MDEBUG frame unwinder.  */
   alpha_mdebug_init_abi (info, gdbarch);
 
-  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep_cast<alpha_gdbarch_tdep> (gdbarch);
   tdep->dynamic_sigtramp_offset = alpha_linux_sigtramp_offset;
   tdep->sigcontext_addr = alpha_linux_sigcontext_addr;
   tdep->pc_in_sigtramp = alpha_linux_pc_in_sigtramp;
diff --git a/gdb/alpha-netbsd-tdep.c b/gdb/alpha-netbsd-tdep.c
index 72d7019377f..3beb9908c2f 100644
--- a/gdb/alpha-netbsd-tdep.c
+++ b/gdb/alpha-netbsd-tdep.c
@@ -250,7 +250,7 @@ static void
 alphanbsd_init_abi (struct gdbarch_info info,
 		    struct gdbarch *gdbarch)
 {
-  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep_cast<alpha_gdbarch_tdep> (gdbarch);
 
   /* Hook into the DWARF CFI frame unwinder.  */
   alpha_dwarf2_init_abi (info, gdbarch);
diff --git a/gdb/alpha-obsd-tdep.c b/gdb/alpha-obsd-tdep.c
index c0d672c3f72..58ecbffea4e 100644
--- a/gdb/alpha-obsd-tdep.c
+++ b/gdb/alpha-obsd-tdep.c
@@ -97,7 +97,7 @@ alphaobsd_sigcontext_addr (struct frame_info *this_frame)
 static void
 alphaobsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep_cast<alpha_gdbarch_tdep> (gdbarch);
 
   /* Hook into the DWARF CFI frame unwinder.  */
   alpha_dwarf2_init_abi (info, gdbarch);
diff --git a/gdb/alpha-tdep.c b/gdb/alpha-tdep.c
index 44efc8e4bbb..3c2adac43e3 100644
--- a/gdb/alpha-tdep.c
+++ b/gdb/alpha-tdep.c
@@ -615,7 +615,7 @@ alpha_return_value (struct gdbarch *gdbarch, struct value *function,
 		    gdb_byte *readbuf, const gdb_byte *writebuf)
 {
   enum type_code code = type->code ();
-  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep_cast<alpha_gdbarch_tdep> (gdbarch);
 
   if ((code == TYPE_CODE_STRUCT
        || code == TYPE_CODE_UNION
@@ -851,7 +851,7 @@ static int
 alpha_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep_cast<alpha_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR jb_addr;
   gdb_byte raw_buffer[ALPHA_REGISTER_SIZE];
@@ -891,7 +891,7 @@ alpha_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
   *this_prologue_cache = info;
 
   gdbarch *arch = get_frame_arch (this_frame);
-  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (arch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep_cast<alpha_gdbarch_tdep> (arch);
   info->sigcontext_addr = tdep->sigcontext_addr (this_frame);
 
   return info;
@@ -904,7 +904,7 @@ static CORE_ADDR
 alpha_sigtramp_register_address (struct gdbarch *gdbarch,
 				 CORE_ADDR sigcontext_addr, int regnum)
 { 
-  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep_cast<alpha_gdbarch_tdep> (gdbarch);
 
   if (regnum >= 0 && regnum < 32)
     return sigcontext_addr + tdep->sc_regs_offset + regnum * 8;
@@ -925,7 +925,7 @@ alpha_sigtramp_frame_this_id (struct frame_info *this_frame,
 			      struct frame_id *this_id)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep_cast<alpha_gdbarch_tdep> (gdbarch);
   struct alpha_sigtramp_unwind_cache *info
     = alpha_sigtramp_frame_unwind_cache (this_frame, this_prologue_cache);
   CORE_ADDR stack_addr, code_addr;
@@ -1000,7 +1000,7 @@ alpha_sigtramp_frame_sniffer (const struct frame_unwind *self,
 
   /* We shouldn't even bother to try if the OSABI didn't register a
      sigcontext_addr handler or pc_in_sigtramp handler.  */
-  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep_cast<alpha_gdbarch_tdep> (gdbarch);
   if (tdep->sigcontext_addr == NULL)
     return 0;
 
@@ -1041,7 +1041,7 @@ static int heuristic_fence_post = 0;
 static CORE_ADDR
 alpha_heuristic_proc_start (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
-  alpha_gdbarch_tdep *tdep = gdbarch_tdep<alpha_gdbarch_tdep> (gdbarch);
+  alpha_gdbarch_tdep *tdep = gdbarch_tdep_cast<alpha_gdbarch_tdep> (gdbarch);
   CORE_ADDR last_non_nop = pc;
   CORE_ADDR fence = pc - heuristic_fence_post;
   CORE_ADDR orig_pc = pc;
diff --git a/gdb/amd64-darwin-tdep.c b/gdb/amd64-darwin-tdep.c
index 7fc35536bc6..a6aa052d75b 100644
--- a/gdb/amd64-darwin-tdep.c
+++ b/gdb/amd64-darwin-tdep.c
@@ -97,7 +97,7 @@ amd64_darwin_sigcontext_addr (struct frame_info *this_frame)
 static void
 x86_darwin_init_abi_64 (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   amd64_init_abi (info, gdbarch,
 		  amd64_target_description (X86_XSTATE_SSE_MASK, true));
diff --git a/gdb/amd64-fbsd-nat.c b/gdb/amd64-fbsd-nat.c
index 7023a182e78..43228bd7835 100644
--- a/gdb/amd64-fbsd-nat.c
+++ b/gdb/amd64-fbsd-nat.c
@@ -102,7 +102,7 @@ amd64_fbsd_nat_target::fetch_registers (struct regcache *regcache, int regnum)
 {
   struct gdbarch *gdbarch = regcache->arch ();
 #if defined(PT_GETFSBASE) || defined(PT_GETGSBASE)
-  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 #endif
   pid_t pid = get_ptrace_pid (regcache->ptid ());
   const struct regset *gregset = find_gregset (gdbarch);
@@ -174,7 +174,7 @@ amd64_fbsd_nat_target::store_registers (struct regcache *regcache, int regnum)
 {
   struct gdbarch *gdbarch = regcache->arch ();
 #if defined(PT_GETFSBASE) || defined(PT_GETGSBASE)
-  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 #endif
   pid_t pid = get_ptrace_pid (regcache->ptid ());
   const struct regset *gregset = find_gregset (gdbarch);
diff --git a/gdb/amd64-fbsd-tdep.c b/gdb/amd64-fbsd-tdep.c
index 8e40283d838..45e1b5aafce 100644
--- a/gdb/amd64-fbsd-tdep.c
+++ b/gdb/amd64-fbsd-tdep.c
@@ -262,7 +262,7 @@ amd64fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					void *cb_data,
 					const struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   cb (".reg", AMD64_FBSD_SIZEOF_GREGSET, AMD64_FBSD_SIZEOF_GREGSET,
       &amd64_fbsd_gregset, NULL, cb_data);
@@ -299,7 +299,7 @@ amd64fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 static void
 amd64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support. */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
index 35703a36785..561d9584a70 100644
--- a/gdb/amd64-linux-tdep.c
+++ b/gdb/amd64-linux-tdep.c
@@ -1659,7 +1659,7 @@ amd64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					  void *cb_data,
 					  const struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   cb (".reg", 27 * 8, 27 * 8, &i386_gregset, NULL, cb_data);
   cb (".reg2", 512, 512, &amd64_fpregset, NULL, cb_data);
@@ -1796,7 +1796,7 @@ static void
 amd64_linux_init_abi_common(struct gdbarch_info info, struct gdbarch *gdbarch,
 			    int num_disp_step_buffers)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, num_disp_step_buffers);
 
@@ -1849,7 +1849,7 @@ amd64_linux_init_abi_common(struct gdbarch_info info, struct gdbarch *gdbarch,
 static void
 amd64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   struct tdesc_arch_data *tdesc_data = info.tdesc_data;
   const struct tdesc_feature *feature;
   int valid_p;
@@ -2063,7 +2063,7 @@ amd64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 static void
 amd64_x32_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   struct tdesc_arch_data *tdesc_data = info.tdesc_data;
   const struct tdesc_feature *feature;
   int valid_p;
diff --git a/gdb/amd64-netbsd-tdep.c b/gdb/amd64-netbsd-tdep.c
index 59d723caa55..4c80649a5c1 100644
--- a/gdb/amd64-netbsd-tdep.c
+++ b/gdb/amd64-netbsd-tdep.c
@@ -97,7 +97,7 @@ int amd64nbsd_r_reg_offset[] =
 static void
 amd64nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   /* Initialize general-purpose register set details first.  */
   tdep->gregset_reg_offset = amd64nbsd_r_reg_offset;
diff --git a/gdb/amd64-obsd-tdep.c b/gdb/amd64-obsd-tdep.c
index f0bc7c474a6..97baa18e76f 100644
--- a/gdb/amd64-obsd-tdep.c
+++ b/gdb/amd64-obsd-tdep.c
@@ -420,7 +420,7 @@ static const struct frame_unwind amd64obsd_trapframe_unwind =
 static void
 amd64obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   amd64_init_abi (info, gdbarch,
 		  amd64_target_description (X86_XSTATE_SSE_MASK, true));
diff --git a/gdb/amd64-sol2-tdep.c b/gdb/amd64-sol2-tdep.c
index ce96eb045ec..4a7eb6f4539 100644
--- a/gdb/amd64-sol2-tdep.c
+++ b/gdb/amd64-sol2-tdep.c
@@ -80,7 +80,7 @@ amd64_sol2_mcontext_addr (struct frame_info *this_frame)
 static void
 amd64_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   tdep->gregset_reg_offset = amd64_sol2_gregset_reg_offset;
   tdep->gregset_num_regs = ARRAY_SIZE (amd64_sol2_gregset_reg_offset);
diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index 0563b32a54b..806fe4a6af5 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -247,7 +247,7 @@ static const int amd64_dwarf_regmap_len =
 static int
 amd64_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   int ymm0_regnum = tdep->ymm0_regnum;
   int regnum = -1;
 
@@ -331,7 +331,7 @@ static const char * const amd64_dword_names[] =
 static const char *
 amd64_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   if (i386_byte_regnum_p (gdbarch, regnum))
     return amd64_byte_names[regnum - tdep->al_regnum];
   else if (i386_zmm_regnum_p (gdbarch, regnum))
@@ -353,7 +353,7 @@ amd64_pseudo_register_read_value (struct gdbarch *gdbarch,
 				  readable_regcache *regcache,
 				  int regnum)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   value *result_value = allocate_value (register_type (gdbarch, regnum));
   VALUE_LVAL (result_value) = lval_register;
@@ -413,7 +413,7 @@ amd64_pseudo_register_write (struct gdbarch *gdbarch,
 			     struct regcache *regcache,
 			     int regnum, const gdb_byte *buf)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   if (i386_byte_regnum_p (gdbarch, regnum))
     {
@@ -465,7 +465,7 @@ static int
 amd64_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				  struct agent_expr *ax, int regnum)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   if (i386_byte_regnum_p (gdbarch, regnum))
     {
@@ -2749,7 +2749,7 @@ static struct amd64_frame_cache *
 amd64_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct amd64_frame_cache *cache;
   CORE_ADDR addr;
@@ -2832,7 +2832,7 @@ amd64_sigtramp_frame_sniffer (const struct frame_unwind *self,
 			      void **this_cache)
 {
   gdbarch *arch = get_frame_arch (this_frame);
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (arch);
 
   /* We shouldn't even bother if we don't have a sigcontext_addr
      handler.  */
@@ -3032,7 +3032,7 @@ amd64_supply_fpregset (const struct regset *regset, struct regcache *regcache,
 		       int regnum, const void *fpregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   gdb_assert (len >= tdep->sizeof_fpregset);
   amd64_supply_fxsave (regcache, regnum, fpregs);
@@ -3049,7 +3049,7 @@ amd64_collect_fpregset (const struct regset *regset,
 			int regnum, void *fpregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   gdb_assert (len >= tdep->sizeof_fpregset);
   amd64_collect_fxsave (regcache, regnum, fpregs);
@@ -3073,7 +3073,7 @@ amd64_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
   gdb_byte buf[8];
   CORE_ADDR jb_addr;
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   int jb_pc_offset = tdep->jb_pc_offset;
   int len = TYPE_LENGTH (builtin_type (gdbarch)->builtin_func_ptr);
 
@@ -3117,7 +3117,7 @@ void
 amd64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch,
 		const target_desc *default_tdesc)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   const struct target_desc *tdesc = info.target_desc;
   static const char *const stap_integer_prefixes[] = { "$", NULL };
   static const char *const stap_register_prefixes[] = { "%", NULL };
@@ -3296,7 +3296,7 @@ amd64_none_init_abi (gdbarch_info info, gdbarch *arch)
 static struct type *
 amd64_x32_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   switch (regnum - tdep->eax_regnum)
     {
@@ -3314,7 +3314,7 @@ void
 amd64_x32_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch,
 		    const target_desc *default_tdesc)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   amd64_init_abi (info, gdbarch, default_tdesc);
 
@@ -3384,7 +3384,7 @@ amd64_supply_fxsave (struct regcache *regcache, int regnum,
 		     const void *fxsave)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   i387_supply_fxsave (regcache, regnum, fxsave);
 
@@ -3407,7 +3407,7 @@ amd64_supply_xsave (struct regcache *regcache, int regnum,
 		    const void *xsave)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   i387_supply_xsave (regcache, regnum, xsave);
 
@@ -3442,7 +3442,7 @@ amd64_collect_fxsave (const struct regcache *regcache, int regnum,
 		      void *fxsave)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   gdb_byte *regs = (gdb_byte *) fxsave;
 
   i387_collect_fxsave (regcache, regnum, fxsave);
@@ -3463,7 +3463,7 @@ amd64_collect_xsave (const struct regcache *regcache, int regnum,
 		     void *xsave, int gcore)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   gdb_byte *regs = (gdb_byte *) xsave;
 
   i387_collect_xsave (regcache, regnum, xsave, gcore);
diff --git a/gdb/amd64-windows-tdep.c b/gdb/amd64-windows-tdep.c
index a9aef0bab88..9018328102a 100644
--- a/gdb/amd64-windows-tdep.c
+++ b/gdb/amd64-windows-tdep.c
@@ -1277,7 +1277,7 @@ amd64_windows_auto_wide_charset (void)
 static void
 amd64_windows_init_abi_common (gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   /* The dwarf2 unwinder (appended very early by i386_gdbarch_init) is
      preferred over the SEH one.  The reasons are:
diff --git a/gdb/arc-linux-tdep.c b/gdb/arc-linux-tdep.c
index d72bdaf24ac..2cb8c3958ae 100644
--- a/gdb/arc-linux-tdep.c
+++ b/gdb/arc-linux-tdep.c
@@ -411,7 +411,7 @@ static std::vector<CORE_ADDR>
 arc_linux_software_single_step (struct regcache *regcache)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep_cast<arc_gdbarch_tdep> (gdbarch);
   struct gdb_non_printing_memory_disassembler dis (gdbarch);
 
   /* Read current instruction.  */
@@ -694,7 +694,7 @@ arc_linux_core_read_description (struct gdbarch *gdbarch,
 static void
 arc_linux_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep_cast<arc_gdbarch_tdep> (gdbarch);
 
   arc_linux_debug_printf ("GNU/Linux OS/ABI initialization.");
 
diff --git a/gdb/arc-newlib-tdep.c b/gdb/arc-newlib-tdep.c
index 2499dff43ec..ece10c6cd94 100644
--- a/gdb/arc-newlib-tdep.c
+++ b/gdb/arc-newlib-tdep.c
@@ -36,7 +36,7 @@ arc_newlib_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
   arc_newlib_debug_printf ("Initialization.");
 
-  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep_cast<arc_gdbarch_tdep> (gdbarch);
 
   /* Offset of original PC in longjmp jump buffer (in registers).  Value of PC
      offset can be found in newlib/libc/machine/arc/setjmp.S.  */
diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c
index 11e0551266e..fdc836048e4 100644
--- a/gdb/arc-tdep.c
+++ b/gdb/arc-tdep.c
@@ -1002,7 +1002,7 @@ arc_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
   arc_debug_printf ("called");
 
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep_cast<arc_gdbarch_tdep> (gdbarch);
   int pc_offset = tdep->jb_pc * ARC_REGISTER_SIZE;
   gdb_byte buf[ARC_REGISTER_SIZE];
   CORE_ADDR jb_addr = get_frame_register_unsigned (frame, ARC_FIRST_ARG_REGNUM);
@@ -1810,7 +1810,7 @@ arc_make_sigtramp_frame_cache (struct frame_info *this_frame)
   arc_debug_printf ("called");
 
   gdbarch *arch = get_frame_arch (this_frame);
-  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (arch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep_cast<arc_gdbarch_tdep> (arch);
 
   /* Allocate new frame cache instance and space for saved register info.  */
   struct arc_frame_cache *cache = FRAME_OBSTACK_ZALLOC (struct arc_frame_cache);
@@ -1887,7 +1887,7 @@ arc_sigtramp_frame_sniffer (const struct frame_unwind *self,
   arc_debug_printf ("called");
 
   gdbarch *arch = get_frame_arch (this_frame);
-  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (arch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep_cast<arc_gdbarch_tdep> (arch);
 
   /* If we have a sigcontext_addr handler, then just return 1 (same as the
      "default_frame_sniffer ()").  */
@@ -2414,7 +2414,7 @@ arc_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 arc_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
+  arc_gdbarch_tdep *tdep = gdbarch_tdep_cast<arc_gdbarch_tdep> (gdbarch);
 
   gdb_printf (file, "arc_dump_tdep: jb_pc = %i\n", tdep->jb_pc);
 
diff --git a/gdb/arm-fbsd-nat.c b/gdb/arm-fbsd-nat.c
index b161b7ed908..10013650105 100644
--- a/gdb/arm-fbsd-nat.c
+++ b/gdb/arm-fbsd-nat.c
@@ -55,7 +55,7 @@ arm_fbsd_nat_target::fetch_registers (struct regcache *regcache, int regnum)
 #endif
 #ifdef PT_GETREGSET
   gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->tls_regnum > 0)
     {
@@ -90,7 +90,7 @@ arm_fbsd_nat_target::store_registers (struct regcache *regcache, int regnum)
 #endif
 #ifdef PT_GETREGSET
   gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->tls_regnum > 0)
     {
diff --git a/gdb/arm-fbsd-tdep.c b/gdb/arm-fbsd-tdep.c
index 61c8f0cecad..2139eebb9f9 100644
--- a/gdb/arm-fbsd-tdep.c
+++ b/gdb/arm-fbsd-tdep.c
@@ -159,7 +159,7 @@ arm_fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				       void *cb_data,
 				       const struct regcache *regcache)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   cb (".reg", ARM_FBSD_SIZEOF_GREGSET, ARM_FBSD_SIZEOF_GREGSET,
       &arm_fbsd_gregset, NULL, cb_data);
@@ -233,7 +233,7 @@ static CORE_ADDR
 arm_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 				   CORE_ADDR lm_addr, CORE_ADDR offset)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
   struct regcache *regcache;
 
   regcache = get_thread_arch_regcache (current_inferior ()->process_target (),
@@ -256,7 +256,7 @@ arm_fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 static void
 arm_fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support.  */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/arm-linux-nat.c b/gdb/arm-linux-nat.c
index 0188c78fe7a..de0189e5f62 100644
--- a/gdb/arm-linux-nat.c
+++ b/gdb/arm-linux-nat.c
@@ -339,7 +339,7 @@ fetch_vfp_regs (struct regcache *regcache)
   gdb_byte regbuf[ARM_VFP3_REGS_SIZE];
   int ret, tid;
   struct gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   /* Get the thread id for the ptrace call.  */
   tid = regcache->ptid ().lwp ();
@@ -368,7 +368,7 @@ store_vfp_regs (const struct regcache *regcache)
   gdb_byte regbuf[ARM_VFP3_REGS_SIZE];
   int ret, tid;
   struct gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   /* Get the thread id for the ptrace call.  */
   tid = regcache->ptid ().lwp ();
@@ -413,7 +413,7 @@ void
 arm_linux_nat_target::fetch_registers (struct regcache *regcache, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   if (-1 == regno)
     {
@@ -450,7 +450,7 @@ void
 arm_linux_nat_target::store_registers (struct regcache *regcache, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   if (-1 == regno)
     {
diff --git a/gdb/arm-linux-tdep.c b/gdb/arm-linux-tdep.c
index 1feb69fe6dd..be9aa384202 100644
--- a/gdb/arm-linux-tdep.c
+++ b/gdb/arm-linux-tdep.c
@@ -712,7 +712,7 @@ arm_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					void *cb_data,
 					const struct regcache *regcache)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   cb (".reg", ARM_LINUX_SIZEOF_GREGSET, ARM_LINUX_SIZEOF_GREGSET,
       &arm_linux_gregset, NULL, cb_data);
@@ -1716,7 +1716,7 @@ arm_linux_init_abi (struct gdbarch_info info,
 								    NULL };
   static const char *const stap_register_indirection_suffixes[] = { "]",
 								    NULL };
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 1);
 
diff --git a/gdb/arm-netbsd-nat.c b/gdb/arm-netbsd-nat.c
index 251159154c9..62cae277749 100644
--- a/gdb/arm-netbsd-nat.c
+++ b/gdb/arm-netbsd-nat.c
@@ -50,7 +50,7 @@ static arm_netbsd_nat_target the_arm_netbsd_nat_target;
 static void
 arm_supply_vfpregset (struct regcache *regcache, struct fpreg *fpregset)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (regcache->arch ());
   if (tdep->vfp_register_count == 0)
     return;
 
@@ -97,7 +97,7 @@ fetch_fp_register (struct regcache *regcache, int regno)
       return;
     }
 
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (regcache->arch ());
   if (regno == ARM_FPSCR_REGNUM && tdep->vfp_register_count != 0)
     regcache->raw_supply (ARM_FPSCR_REGNUM, (char *) &vfp.vfp_fpscr);
   else if (regno >= ARM_D0_REGNUM
@@ -279,7 +279,7 @@ store_fp_register (const struct regcache *regcache, int regno)
       return;
     }
 
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (regcache->arch ());
   if (regno == ARM_FPSCR_REGNUM && tdep->vfp_register_count != 0)
     regcache->raw_collect (ARM_FPSCR_REGNUM, (char *) &vfp.vfp_fpscr);
   else if (regno >= ARM_D0_REGNUM
@@ -301,7 +301,7 @@ store_fp_register (const struct regcache *regcache, int regno)
 static void
 store_fp_regs (const struct regcache *regcache)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (regcache->arch ());
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (regcache->arch ());
   int lwp = regcache->ptid ().lwp ();
   if (tdep->vfp_register_count == 0)
     return;
diff --git a/gdb/arm-netbsd-tdep.c b/gdb/arm-netbsd-tdep.c
index aa4d15df4c6..de429b728b5 100644
--- a/gdb/arm-netbsd-tdep.c
+++ b/gdb/arm-netbsd-tdep.c
@@ -111,7 +111,7 @@ static void
 arm_netbsd_init_abi_common (struct gdbarch_info info,
 			    struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   tdep->lowest_pc = 0x8000;
   switch (info.byte_order)
@@ -148,7 +148,7 @@ static void
 arm_netbsd_elf_init_abi (struct gdbarch_info info,
 			 struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   arm_netbsd_init_abi_common (info, gdbarch);
 
diff --git a/gdb/arm-none-tdep.c b/gdb/arm-none-tdep.c
index 0d5eb04826e..53845e15701 100644
--- a/gdb/arm-none-tdep.c
+++ b/gdb/arm-none-tdep.c
@@ -177,7 +177,7 @@ arm_none_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				       void *cb_data,
 				       const struct regcache *regcache)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   cb (".reg", ARM_NONE_SIZEOF_GREGSET, ARM_NONE_SIZEOF_GREGSET,
       &arm_none_gregset, nullptr, cb_data);
diff --git a/gdb/arm-obsd-tdep.c b/gdb/arm-obsd-tdep.c
index 634c76b7561..93a6dcde173 100644
--- a/gdb/arm-obsd-tdep.c
+++ b/gdb/arm-obsd-tdep.c
@@ -76,7 +76,7 @@ static void
 armobsd_init_abi (struct gdbarch_info info,
 		  struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->fp_model == ARM_FLOAT_AUTO)
     tdep->fp_model = ARM_FLOAT_SOFT_VFP;
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index d3b4fce98a3..c75cbf5da00 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -355,7 +355,7 @@ static void
 arm_cache_init (struct arm_prologue_cache *cache, struct frame_info *frame)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   arm_cache_init (cache, gdbarch);
   cache->sp = get_frame_register_unsigned (frame, ARM_SP_REGNUM);
@@ -553,7 +553,7 @@ bool arm_unwind_secure_frames = true;
 int
 arm_psr_thumb_bit (struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->is_m)
     return XPSR_T;
@@ -665,7 +665,7 @@ arm_pc_is_thumb (struct gdbarch *gdbarch, CORE_ADDR memaddr)
   struct bound_minimal_symbol sym;
   char type;
   arm_displaced_step_copy_insn_closure *dsc = nullptr;
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   if (gdbarch_displaced_step_copy_insn_closure_by_addr_p (gdbarch))
     dsc = ((arm_displaced_step_copy_insn_closure * )
@@ -769,7 +769,7 @@ arm_pc_is_thumb (struct gdbarch *gdbarch, CORE_ADDR memaddr)
 static int
 arm_m_addr_is_magic (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
   if (tdep->have_sec_ext)
     {
       switch ((addr & 0xff000000))
@@ -811,7 +811,7 @@ arm_m_addr_is_magic (struct gdbarch *gdbarch, CORE_ADDR addr)
 static CORE_ADDR
 arm_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR val)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   /* On M-profile devices, do not strip the low bit from EXC_RETURN
      (the magic exception return address).  */
@@ -939,7 +939,7 @@ thumb_analyze_prologue (struct gdbarch *gdbarch,
 			CORE_ADDR start, CORE_ADDR limit,
 			struct arm_prologue_cache *cache)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
   int i;
@@ -1879,7 +1879,7 @@ arm_analyze_prologue (struct gdbarch *gdbarch,
   CORE_ADDR offset, current_pc;
   pv_t regs[ARM_FPS_REGNUM];
   CORE_ADDR unrecognized_pc = 0;
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   /* Search the prologue looking for instructions that set up the
      frame pointer, adjust the stack pointer, and save registers.
@@ -2127,7 +2127,7 @@ arm_scan_prologue (struct frame_info *this_frame,
   CORE_ADDR prologue_start, prologue_end;
   CORE_ADDR prev_pc = get_frame_pc (this_frame);
   CORE_ADDR block_addr = get_frame_address_in_block (this_frame);
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   /* Assume there is no frame until proven otherwise.  */
   cache->framereg = ARM_SP_REGNUM;
@@ -2232,7 +2232,7 @@ arm_make_prologue_cache (struct frame_info *this_frame)
     return cache;
 
   arm_gdbarch_tdep *tdep =
-    gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
+    gdbarch_tdep_cast<arm_gdbarch_tdep> (get_frame_arch (this_frame));
 
   prev_sp = unwound_fp + cache->framesize;
   arm_cache_set_active_sp_value (cache, tdep, prev_sp);
@@ -2263,7 +2263,7 @@ arm_prologue_unwind_stop_reason (struct frame_info *this_frame,
   /* This is meant to halt the backtrace at "_start".  */
   pc = get_frame_pc (this_frame);
   gdbarch *arch = get_frame_arch (this_frame);
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (arch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (arch);
   if (pc <= tdep->lowest_pc)
     return UNWIND_OUTERMOST;
 
@@ -2291,7 +2291,7 @@ arm_prologue_this_id (struct frame_info *this_frame,
   cache = (struct arm_prologue_cache *) *this_cache;
 
   arm_gdbarch_tdep *tdep
-    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
+    = gdbarch_tdep_cast<arm_gdbarch_tdep> (get_frame_arch (this_frame));
 
   /* Use function start address as part of the frame ID.  If we cannot
      identify the start address (due to missing symbol information),
@@ -2318,7 +2318,7 @@ arm_prologue_prev_register (struct frame_info *this_frame,
     *this_cache = arm_make_prologue_cache (this_frame);
   cache = (struct arm_prologue_cache *) *this_cache;
 
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   /* If this frame has signed the return address, mark it as so.  */
   if (tdep->have_pacbti && cache->ra_signed_state.has_value ()
@@ -2986,7 +2986,7 @@ arm_exidx_fill_cache (struct frame_info *this_frame, gdb_byte *entry)
 
   /* We already got the previous SP.  */
   arm_gdbarch_tdep *tdep
-    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
+    = gdbarch_tdep_cast<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   arm_cache_set_active_sp_value (cache, tdep, vsp);
 
   return cache;
@@ -3111,7 +3111,7 @@ arm_make_epilogue_frame_cache (struct frame_info *this_frame)
 
   /* Since we are in epilogue, the SP has been restored.  */
   arm_gdbarch_tdep *tdep
-    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
+    = gdbarch_tdep_cast<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   arm_cache_set_active_sp_value (cache, tdep,
 				 get_frame_register_unsigned (this_frame,
 							      ARM_SP_REGNUM));
@@ -3150,7 +3150,7 @@ arm_epilogue_frame_this_id (struct frame_info *this_frame,
     func = pc;
 
   arm_gdbarch_tdep *tdep
-    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
+    = gdbarch_tdep_cast<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   *this_id = frame_id_build (arm_cache_get_prev_sp_value (cache, tdep), pc);
 }
 
@@ -3274,7 +3274,7 @@ arm_make_stub_cache (struct frame_info *this_frame)
   arm_cache_init (cache, this_frame);
 
   arm_gdbarch_tdep *tdep
-    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
+    = gdbarch_tdep_cast<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   arm_cache_set_active_sp_value (cache, tdep,
 				 get_frame_register_unsigned (this_frame,
 							      ARM_SP_REGNUM));
@@ -3296,7 +3296,7 @@ arm_stub_this_id (struct frame_info *this_frame,
   cache = (struct arm_prologue_cache *) *this_cache;
 
   arm_gdbarch_tdep *tdep
-    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
+    = gdbarch_tdep_cast<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   *this_id = frame_id_build (arm_cache_get_prev_sp_value (cache, tdep),
 			     get_frame_pc (this_frame));
 }
@@ -3344,7 +3344,7 @@ static struct arm_prologue_cache *
 arm_m_exception_cache (struct frame_info *this_frame)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct arm_prologue_cache *cache;
   CORE_ADDR lr;
@@ -3655,7 +3655,7 @@ arm_m_exception_this_id (struct frame_info *this_frame,
 
   /* Our frame ID for a stub frame is the current SP and LR.  */
   arm_gdbarch_tdep *tdep
-    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
+    = gdbarch_tdep_cast<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   *this_id = frame_id_build (arm_cache_get_prev_sp_value (cache, tdep),
 			     get_frame_pc (this_frame));
 }
@@ -3677,7 +3677,7 @@ arm_m_exception_prev_register (struct frame_info *this_frame,
 
   /* The value was already reconstructed into PREV_SP.  */
   arm_gdbarch_tdep *tdep
-    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
+    = gdbarch_tdep_cast<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   if (prev_regnum == ARM_SP_REGNUM)
     return frame_unwind_got_constant (this_frame, prev_regnum,
 				      arm_cache_get_prev_sp_value (cache, tdep));
@@ -3765,7 +3765,7 @@ arm_normal_frame_base (struct frame_info *this_frame, void **this_cache)
   cache = (struct arm_prologue_cache *) *this_cache;
 
   arm_gdbarch_tdep *tdep
-    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
+    = gdbarch_tdep_cast<arm_gdbarch_tdep> (get_frame_arch (this_frame));
   return arm_cache_get_prev_sp_value (cache, tdep) - cache->framesize;
 }
 
@@ -3781,7 +3781,7 @@ arm_dwarf2_prev_register (struct frame_info *this_frame, void **this_cache,
 			  int regnum)
 {
   struct gdbarch * gdbarch = get_frame_arch (this_frame);
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
   CORE_ADDR lr;
   ULONGEST cpsr;
 
@@ -4305,7 +4305,7 @@ arm_vfp_call_candidate (struct type *t, enum arm_vfp_cprc_base_type *base_type,
 static int
 arm_vfp_abi_for_function (struct gdbarch *gdbarch, struct type *func_type)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   /* Variadic functions always use the base ABI.  Assume that functions
      without debug info are not variadic.  */
@@ -4339,7 +4339,7 @@ arm_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   int use_vfp_abi;
   struct type *ftype;
   unsigned vfp_regs_free = (1 << 16) - 1;
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   /* Determine the type of this function and whether the VFP ABI
      applies.  */
@@ -4611,7 +4611,7 @@ arm_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
 static struct type *
 arm_ext_type (struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   if (!tdep->arm_ext_type)
     tdep->arm_ext_type
@@ -4624,7 +4624,7 @@ arm_ext_type (struct gdbarch *gdbarch)
 static struct type *
 arm_neon_double_type (struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->neon_double_type == NULL)
     {
@@ -4663,7 +4663,7 @@ arm_neon_double_type (struct gdbarch *gdbarch)
 static struct type *
 arm_neon_quad_type (struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->neon_quad_type == NULL)
     {
@@ -4701,7 +4701,7 @@ arm_neon_quad_type (struct gdbarch *gdbarch)
 static bool
 is_q_pseudo (struct gdbarch *gdbarch, int regnum)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   /* Q pseudo registers are available for both NEON (Q0~Q15) and
      MVE (Q0~Q7) features.  */
@@ -4722,7 +4722,7 @@ is_q_pseudo (struct gdbarch *gdbarch, int regnum)
 static bool
 is_s_pseudo (struct gdbarch *gdbarch, int regnum)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->have_s_pseudos
       && regnum >= tdep->s_pseudo_base
@@ -4741,7 +4741,7 @@ is_s_pseudo (struct gdbarch *gdbarch, int regnum)
 static bool
 is_mve_pseudo (struct gdbarch *gdbarch, int regnum)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->have_mve
       && regnum >= tdep->mve_pseudo_base
@@ -4760,7 +4760,7 @@ is_mve_pseudo (struct gdbarch *gdbarch, int regnum)
 static bool
 is_pacbti_pseudo (struct gdbarch *gdbarch, int regnum)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->have_pacbti
       && regnum >= tdep->pacbti_pseudo_base
@@ -4776,7 +4776,7 @@ is_pacbti_pseudo (struct gdbarch *gdbarch, int regnum)
 static struct type *
 arm_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   if (is_s_pseudo (gdbarch, regnum))
     return builtin_type (gdbarch)->builtin_float;
@@ -4855,7 +4855,7 @@ arm_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
   /* PACBTI register containing the Pointer Authentication Code.  */
   if (reg == ARM_DWARF_RA_AUTH_CODE)
     {
-      arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+      arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
       if (tdep->have_pacbti)
 	return tdep->pacbti_pseudo_base;
@@ -5001,7 +5001,7 @@ arm_adjust_breakpoint_address (struct gdbarch *gdbarch, CORE_ADDR bpaddr)
   int buf_len;
   enum bfd_endian order = gdbarch_byte_order_for_code (gdbarch);
   int i, any, last_it, last_it_count;
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   /* If we are using BKPT breakpoints, none of this is necessary.  */
   if (tdep->thumb2_breakpoint == NULL)
@@ -8309,7 +8309,7 @@ arm_displaced_init_closure (struct gdbarch *gdbarch, CORE_ADDR from,
 			    CORE_ADDR to,
 			    arm_displaced_step_copy_insn_closure *dsc)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
   unsigned int i, len, offset;
   enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
   int size = dsc->is_thumb? 2 : 4;
@@ -8472,7 +8472,7 @@ static const gdb_byte arm_default_thumb_be_breakpoint[] = THUMB_BE_BREAKPOINT;
 static int
 arm_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
 
   if (arm_pc_is_thumb (gdbarch, *pcptr))
@@ -8507,7 +8507,7 @@ arm_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 static const gdb_byte *
 arm_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   switch (kind)
     {
@@ -8579,7 +8579,7 @@ arm_extract_return_value (struct type *type, struct regcache *regs,
 {
   struct gdbarch *gdbarch = regs->arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   if (TYPE_CODE_FLT == type->code ())
     {
@@ -8690,7 +8690,7 @@ arm_return_in_memory (struct gdbarch *gdbarch, struct type *type)
       return (TYPE_LENGTH (type) > 16);
     }
 
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
   if (tdep->arm_abi != ARM_ABI_APCS)
     {
       /* The AAPCS says all aggregates not larger than a word are returned
@@ -8796,7 +8796,7 @@ arm_store_return_value (struct type *type, struct regcache *regs,
   if (type->code () == TYPE_CODE_FLT)
     {
       gdb_byte buf[ARM_FP_REGISTER_SIZE];
-      arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+      arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
       switch (tdep->fp_model)
 	{
@@ -8885,7 +8885,7 @@ arm_return_value (struct gdbarch *gdbarch, struct value *function,
 		  struct type *valtype, struct regcache *regcache,
 		  gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
   struct type *func_type = function ? value_type (function) : NULL;
   enum arm_vfp_cprc_base_type vfp_base_type;
   int vfp_base_count;
@@ -8977,7 +8977,7 @@ static int
 arm_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR jb_addr;
   gdb_byte buf[ARM_INT_REGISTER_SIZE];
@@ -9170,7 +9170,7 @@ show_fp_model (struct ui_file *file, int from_tty,
       && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm)
     {
       arm_gdbarch_tdep *tdep
-	= gdbarch_tdep<arm_gdbarch_tdep> (target_gdbarch ());
+	= gdbarch_tdep_cast<arm_gdbarch_tdep> (target_gdbarch ());
 
       gdb_printf (file, _("\
 The current ARM floating point model is \"auto\" (currently \"%s\").\n"),
@@ -9210,7 +9210,7 @@ arm_show_abi (struct ui_file *file, int from_tty,
       && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_arm)
     {
       arm_gdbarch_tdep *tdep
-	= gdbarch_tdep<arm_gdbarch_tdep> (target_gdbarch ());
+	= gdbarch_tdep_cast<arm_gdbarch_tdep> (target_gdbarch ());
 
       gdb_printf (file, _("\
 The current ARM ABI is \"auto\" (currently \"%s\").\n"),
@@ -9289,7 +9289,7 @@ show_disassembly_style_sfunc (struct ui_file *file, int from_tty,
 static const char *
 arm_register_name (struct gdbarch *gdbarch, int i)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   if (is_s_pseudo (gdbarch, i))
     {
@@ -9460,7 +9460,7 @@ static enum register_status
 arm_mve_pseudo_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 		     int regnum, gdb_byte *buf)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   /* P0 is the first 16 bits of VPR.  */
   return regcache->raw_read_part (tdep->mve_vpr_regnum, 0, 2, buf);
@@ -9474,7 +9474,7 @@ arm_pseudo_read (struct gdbarch *gdbarch, readable_regcache *regcache,
   char name_buf[4];
   gdb_byte reg_buf[8];
   int offset, double_regnum;
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   gdb_assert (regnum >= num_regs);
 
@@ -9546,7 +9546,7 @@ static void
 arm_mve_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache,
 		      int regnum, const gdb_byte *buf)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   /* P0 is the first 16 bits of VPR.  */
   regcache->raw_write_part (tdep->mve_vpr_regnum, 0, 2, buf);
@@ -9560,7 +9560,7 @@ arm_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache,
   char name_buf[4];
   gdb_byte reg_buf[8];
   int offset, double_regnum;
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   gdb_assert (regnum >= num_regs);
 
@@ -9648,7 +9648,7 @@ arm_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 static void
 arm_register_g_packet_guesses (struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->is_m)
     {
@@ -9691,7 +9691,7 @@ arm_register_g_packet_guesses (struct gdbarch *gdbarch)
 static int
 arm_code_of_frame_writable (struct gdbarch *gdbarch, struct frame_info *frame)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep->is_m && get_frame_type (frame) == SIGTRAMP_FRAME)
     {
@@ -10250,7 +10250,7 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
     {
       arm_gdbarch_tdep *tdep
-	= gdbarch_tdep<arm_gdbarch_tdep> (best_arch->gdbarch);
+	= gdbarch_tdep_cast<arm_gdbarch_tdep> (best_arch->gdbarch);
 
       if (arm_abi != ARM_ABI_AUTO && arm_abi != tdep->arm_abi)
 	continue;
@@ -10570,7 +10570,7 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 arm_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   if (tdep == NULL)
     return;
@@ -12779,7 +12779,7 @@ arm_record_coproc_data_proc (arm_insn_decode_record *arm_insn_r)
 {
   uint32_t op, op1_ebit, coproc, bits_24_25;
   arm_gdbarch_tdep *tdep
-    = gdbarch_tdep<arm_gdbarch_tdep> (arm_insn_r->gdbarch);
+    = gdbarch_tdep_cast<arm_gdbarch_tdep> (arm_insn_r->gdbarch);
   struct regcache *reg_cache = arm_insn_r->regcache;
 
   arm_insn_r->opcode = bits (arm_insn_r->arm_insn, 24, 27);
@@ -13267,7 +13267,7 @@ static int
 thumb_record_ldm_stm_swi (arm_insn_decode_record *thumb_insn_r)
 {
   arm_gdbarch_tdep *tdep
-    = gdbarch_tdep<arm_gdbarch_tdep>  (thumb_insn_r->gdbarch);
+    = gdbarch_tdep_cast<arm_gdbarch_tdep>  (thumb_insn_r->gdbarch);
   struct regcache *reg_cache = thumb_insn_r->regcache;
 
   uint32_t ret = 0; /* function return value: -1:record failure ;  0:success  */
diff --git a/gdb/arm-wince-tdep.c b/gdb/arm-wince-tdep.c
index 5063b308809..fbe1ede4a45 100644
--- a/gdb/arm-wince-tdep.c
+++ b/gdb/arm-wince-tdep.c
@@ -115,7 +115,7 @@ arm_wince_skip_main_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
 static void
 arm_wince_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep_cast<arm_gdbarch_tdep> (gdbarch);
 
   windows_init_abi (info, gdbarch);
 
diff --git a/gdb/avr-tdep.c b/gdb/avr-tdep.c
index 4722f7ee748..e4f51867bac 100644
--- a/gdb/avr-tdep.c
+++ b/gdb/avr-tdep.c
@@ -232,7 +232,7 @@ avr_register_type (struct gdbarch *gdbarch, int reg_nr)
   if (reg_nr == AVR_PC_REGNUM)
     return builtin_type (gdbarch)->builtin_uint32;
 
-  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
+  avr_gdbarch_tdep *tdep = gdbarch_tdep_cast<avr_gdbarch_tdep> (gdbarch);
   if (reg_nr == AVR_PSEUDO_PC_REGNUM)
     return tdep->pc_type;
 
@@ -750,7 +750,7 @@ avr_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR pc_beg, CORE_ADDR pc_end,
   gdb_assert (vpc < AVR_MAX_PROLOGUE_SIZE);
 
   /* Handle static small stack allocation using rcall or push.  */
-  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
+  avr_gdbarch_tdep *tdep = gdbarch_tdep_cast<avr_gdbarch_tdep> (gdbarch);
   while (scan_stage == 1 && vpc < len)
     {
       insn = extract_unsigned_integer (&prologue[vpc], 2, byte_order);
@@ -1053,7 +1053,7 @@ avr_frame_unwind_cache (struct frame_info *this_frame,
 
   /* The previous frame's SP needed to be computed.  Save the computed
      value.  */
-  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
+  avr_gdbarch_tdep *tdep = gdbarch_tdep_cast<avr_gdbarch_tdep> (gdbarch);
   info->saved_regs[AVR_SP_REGNUM].set_value (info->prev_sp
 					     - 1 + tdep->call_length);
 
@@ -1135,7 +1135,7 @@ avr_frame_prev_register (struct frame_info *this_frame,
 	  int i;
 	  gdb_byte buf[3];
 	  struct gdbarch *gdbarch = get_frame_arch (this_frame);
-	  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
+	  avr_gdbarch_tdep *tdep = gdbarch_tdep_cast<avr_gdbarch_tdep> (gdbarch);
 
 	  read_memory (info->saved_regs[AVR_PC_REGNUM].addr (),
 		       buf, tdep->call_length);
@@ -1277,7 +1277,7 @@ avr_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 {
   int i;
   gdb_byte buf[3];
-  avr_gdbarch_tdep *tdep = gdbarch_tdep<avr_gdbarch_tdep> (gdbarch);
+  avr_gdbarch_tdep *tdep = gdbarch_tdep_cast<avr_gdbarch_tdep> (gdbarch);
   int call_length = tdep->call_length;
   CORE_ADDR return_pc = avr_convert_iaddr_to_raw (bp_addr);
   int regnum = AVR_ARGN_REGNUM;
@@ -1461,7 +1461,7 @@ avr_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
     {
       avr_gdbarch_tdep *tdep
-	= gdbarch_tdep<avr_gdbarch_tdep> (best_arch->gdbarch);
+	= gdbarch_tdep_cast<avr_gdbarch_tdep> (best_arch->gdbarch);
 
       if (tdep->call_length == call_length)
 	return best_arch->gdbarch;
diff --git a/gdb/bfin-tdep.c b/gdb/bfin-tdep.c
index f232e22c37c..175f2424574 100644
--- a/gdb/bfin-tdep.c
+++ b/gdb/bfin-tdep.c
@@ -766,7 +766,7 @@ bfin_frame_align (struct gdbarch *gdbarch, CORE_ADDR address)
 enum bfin_abi
 bfin_abi (struct gdbarch *gdbarch)
 {
-  bfin_gdbarch_tdep *tdep = gdbarch_tdep<bfin_gdbarch_tdep> (gdbarch);
+  bfin_gdbarch_tdep *tdep = gdbarch_tdep_cast<bfin_gdbarch_tdep> (gdbarch);
   return tdep->bfin_abi;
 }
 
@@ -792,7 +792,7 @@ bfin_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       bfin_gdbarch_tdep *tdep
-	= gdbarch_tdep<bfin_gdbarch_tdep> (arches->gdbarch);
+	= gdbarch_tdep_cast<bfin_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->bfin_abi != abi)
 	continue;
diff --git a/gdb/cris-linux-tdep.c b/gdb/cris-linux-tdep.c
index b3ed7450e99..5da68cbe6a5 100644
--- a/gdb/cris-linux-tdep.c
+++ b/gdb/cris-linux-tdep.c
@@ -33,7 +33,7 @@
 static void
 cris_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep_cast<cris_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/cris-tdep.c b/gdb/cris-tdep.c
index 73110d97f2f..8b5a92efe0d 100644
--- a/gdb/cris-tdep.c
+++ b/gdb/cris-tdep.c
@@ -313,7 +313,7 @@ cris_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
 				  void **this_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep_cast<cris_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct cris_unwind_cache *info;
   CORE_ADDR addr;
@@ -450,7 +450,7 @@ static int
 crisv32_single_step_through_delay (struct gdbarch *gdbarch,
 				   struct frame_info *this_frame)
 {
-  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep_cast<cris_gdbarch_tdep> (gdbarch);
   ULONGEST erp;
   int ret = 0;
 
@@ -696,7 +696,7 @@ cris_frame_unwind_cache (struct frame_info *this_frame,
 			 void **this_prologue_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep_cast<cris_gdbarch_tdep> (gdbarch);
   struct cris_unwind_cache *info;
 
   if ((*this_prologue_cache))
@@ -1334,7 +1334,7 @@ crisv32_scan_prologue (CORE_ADDR pc, struct frame_info *this_frame,
 static CORE_ADDR
 cris_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
-  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep_cast<cris_gdbarch_tdep> (gdbarch);
   CORE_ADDR func_addr, func_end;
   struct symtab_and_line sal;
   CORE_ADDR pc_after_prologue;
@@ -1369,7 +1369,7 @@ cris_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 static const gdb_byte *
 cris_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
-  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep_cast<cris_gdbarch_tdep> (gdbarch);
   static unsigned char break8_insn[] = {0x38, 0xe9};
   static unsigned char break15_insn[] = {0x3f, 0xe9};
 
@@ -1388,7 +1388,7 @@ static int
 cris_spec_reg_applicable (struct gdbarch *gdbarch,
 			  struct cris_spec_reg spec_reg)
 {
-  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep_cast<cris_gdbarch_tdep> (gdbarch);
   unsigned int version = tdep->cris_version;
   
   switch (spec_reg.applicable_version)
@@ -3767,7 +3767,7 @@ cris_supply_gregset (const struct regset *regset, struct regcache *regcache,
 		     int regnum, const void *gregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep_cast<cris_gdbarch_tdep> (gdbarch);
   int i;
   const cris_elf_greg_t *regp = static_cast<const cris_elf_greg_t *>(gregs);
 
@@ -3861,7 +3861,7 @@ Makes GDB use the NRP register instead of the ERP register in certain cases."),
 static void
 cris_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  cris_gdbarch_tdep *tdep = gdbarch_tdep<cris_gdbarch_tdep> (gdbarch);
+  cris_gdbarch_tdep *tdep = gdbarch_tdep_cast<cris_gdbarch_tdep> (gdbarch);
   if (tdep != NULL)
     {
       gdb_printf (file, "cris_dump_tdep: tdep->cris_version = %i\n",
@@ -3941,7 +3941,7 @@ cris_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       cris_gdbarch_tdep *tdep
-	= gdbarch_tdep<cris_gdbarch_tdep> (arches->gdbarch);
+	= gdbarch_tdep_cast<cris_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->cris_version == usr_cmd_cris_version
 	  && tdep->cris_mode == usr_cmd_cris_mode
diff --git a/gdb/csky-tdep.c b/gdb/csky-tdep.c
index 01d4a0f28cb..a29652e1cf0 100644
--- a/gdb/csky-tdep.c
+++ b/gdb/csky-tdep.c
@@ -2684,7 +2684,7 @@ csky_pseudo_register_name (struct gdbarch *gdbarch, int regno)
 {
   int num_regs = gdbarch_num_regs (gdbarch);
   csky_gdbarch_tdep *tdep
-    = gdbarch_tdep<csky_gdbarch_tdep> (gdbarch);
+    = gdbarch_tdep_cast<csky_gdbarch_tdep> (gdbarch);
 
   regno -= num_regs;
 
@@ -2732,7 +2732,7 @@ csky_pseudo_register_read (struct gdbarch *gdbarch,
 {
   int num_regs = gdbarch_num_regs (gdbarch);
   csky_gdbarch_tdep *tdep
-    = gdbarch_tdep<csky_gdbarch_tdep> (gdbarch);
+    = gdbarch_tdep_cast<csky_gdbarch_tdep> (gdbarch);
 
   regnum -= num_regs;
 
@@ -2784,7 +2784,7 @@ csky_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
 {
   int num_regs = gdbarch_num_regs (gdbarch);
   csky_gdbarch_tdep *tdep
-    = gdbarch_tdep<csky_gdbarch_tdep> (gdbarch);
+    = gdbarch_tdep_cast<csky_gdbarch_tdep> (gdbarch);
 
   regnum -= num_regs;
 
@@ -2912,7 +2912,7 @@ csky_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       csky_gdbarch_tdep *tdep
-	= gdbarch_tdep<csky_gdbarch_tdep> (arches->gdbarch);
+	= gdbarch_tdep_cast<csky_gdbarch_tdep> (arches->gdbarch);
       if (fpu_abi != tdep->fpu_abi)
         continue;
       if (vdsp_version != tdep->vdsp_version)
diff --git a/gdb/frv-tdep.c b/gdb/frv-tdep.c
index 34f437764a9..ddd3e7181ef 100644
--- a/gdb/frv-tdep.c
+++ b/gdb/frv-tdep.c
@@ -93,7 +93,7 @@ struct frv_gdbarch_tdep : gdbarch_tdep
 enum frv_abi
 frv_abi (struct gdbarch *gdbarch)
 {
-  frv_gdbarch_tdep *tdep = gdbarch_tdep<frv_gdbarch_tdep> (gdbarch);
+  frv_gdbarch_tdep *tdep = gdbarch_tdep_cast<frv_gdbarch_tdep> (gdbarch);
   return tdep->frv_abi;
 }
 
@@ -275,7 +275,7 @@ frv_register_name (struct gdbarch *gdbarch, int reg)
   if (reg >= frv_num_regs + frv_num_pseudo_regs)
     return "?toolarge?";
 
-  frv_gdbarch_tdep *tdep = gdbarch_tdep<frv_gdbarch_tdep> (gdbarch);
+  frv_gdbarch_tdep *tdep = gdbarch_tdep_cast<frv_gdbarch_tdep> (gdbarch);
   return tdep->register_names[reg];
 }
 
diff --git a/gdb/ft32-tdep.c b/gdb/ft32-tdep.c
index 024ca47ce4d..8949806ba0c 100644
--- a/gdb/ft32-tdep.c
+++ b/gdb/ft32-tdep.c
@@ -110,7 +110,7 @@ ft32_register_type (struct gdbarch *gdbarch, int reg_nr)
 {
   if (reg_nr == FT32_PC_REGNUM)
     {
-      ft32_gdbarch_tdep *tdep = gdbarch_tdep<ft32_gdbarch_tdep> (gdbarch);
+      ft32_gdbarch_tdep *tdep = gdbarch_tdep_cast<ft32_gdbarch_tdep> (gdbarch);
       return tdep->pc_type;
     }
   else if (reg_nr == FT32_SP_REGNUM || reg_nr == FT32_FP_REGNUM)
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index 16c73915c64..16dc0cfc0ec 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -162,7 +162,7 @@ extern struct gdbarch_tdep *gdbarch_tdep_1 (struct gdbarch *gdbarch);
 
 template<typename TDepType>
 static inline TDepType *
-gdbarch_tdep (struct gdbarch *gdbarch)
+gdbarch_tdep_cast (struct gdbarch *gdbarch)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep_1 (gdbarch);
   return gdb::checked_static_cast<TDepType *> (tdep);
diff --git a/gdb/hppa-bsd-tdep.c b/gdb/hppa-bsd-tdep.c
index c405511529d..104182fae1a 100644
--- a/gdb/hppa-bsd-tdep.c
+++ b/gdb/hppa-bsd-tdep.c
@@ -118,7 +118,7 @@ hppabsd_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
 void
 hppabsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep_cast<hppa_gdbarch_tdep> (gdbarch);
 
   /* OpenBSD and NetBSD have a 64-bit 'long double'.  */
   set_gdbarch_long_double_bit (gdbarch, 64);
diff --git a/gdb/hppa-linux-tdep.c b/gdb/hppa-linux-tdep.c
index f17d2ae6b02..82bcda34a04 100644
--- a/gdb/hppa-linux-tdep.c
+++ b/gdb/hppa-linux-tdep.c
@@ -476,7 +476,7 @@ hppa_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					 void *cb_data,
 					 const struct regcache *regcache)
 {
-  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep_cast<hppa_gdbarch_tdep> (gdbarch);
 
   cb (".reg", 80 * tdep->bytes_per_address, 80 * tdep->bytes_per_address,
       &hppa_linux_regset, NULL, cb_data);
@@ -486,7 +486,7 @@ hppa_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 static void
 hppa_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep_cast<hppa_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/hppa-tdep.c b/gdb/hppa-tdep.c
index 9f93a945a6a..a5029bc3fe4 100644
--- a/gdb/hppa-tdep.c
+++ b/gdb/hppa-tdep.c
@@ -247,7 +247,7 @@ internalize_unwinds (struct objfile *objfile, struct unwind_table_entry *table,
   if (size > 0)
     {
       struct gdbarch *gdbarch = objfile->arch ();
-      hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
+      hppa_gdbarch_tdep *tdep = gdbarch_tdep_cast<hppa_gdbarch_tdep> (gdbarch);
       unsigned long tmp;
       unsigned i;
       char *buf = (char *) alloca (size);
@@ -718,7 +718,7 @@ hppa32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   /* Global pointer (r19) of the function we are trying to call.  */
   CORE_ADDR gp;
 
-  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep_cast<hppa_gdbarch_tdep> (gdbarch);
 
   for (write_pass = 0; write_pass < 2; write_pass++)
     {
@@ -955,7 +955,7 @@ hppa64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 			function_call_return_method return_method,
 			CORE_ADDR struct_addr)
 {
-  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep_cast<hppa_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int i, offset = 0;
   CORE_ADDR gp;
@@ -2241,7 +2241,7 @@ hppa_frame_cache (struct frame_info *this_frame, void **this_cache)
   }
 
   {
-    hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
+    hppa_gdbarch_tdep *tdep = gdbarch_tdep_cast<hppa_gdbarch_tdep> (gdbarch);
 
     if (tdep->unwind_adjust_stub)
       tdep->unwind_adjust_stub (this_frame, cache->base, cache->saved_regs);
@@ -2471,7 +2471,7 @@ hppa_stub_unwind_sniffer (const struct frame_unwind *self,
 {
   CORE_ADDR pc = get_frame_address_in_block (this_frame);
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep_cast<hppa_gdbarch_tdep> (gdbarch);
 
   if (pc == 0
       || (tdep->in_solib_call_trampoline != NULL
@@ -3147,7 +3147,7 @@ hppa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 hppa_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
+  hppa_gdbarch_tdep *tdep = gdbarch_tdep_cast<hppa_gdbarch_tdep> (gdbarch);
 
   gdb_printf (file, "bytes_per_address = %d\n", 
 	      tdep->bytes_per_address);
diff --git a/gdb/i386-bsd-tdep.c b/gdb/i386-bsd-tdep.c
index dbbd3c786c3..e2c9ac0042b 100644
--- a/gdb/i386-bsd-tdep.c
+++ b/gdb/i386-bsd-tdep.c
@@ -74,7 +74,7 @@ int i386bsd_sc_reg_offset[] =
 void
 i386bsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   tdep->jb_pc_offset = 0;
 
diff --git a/gdb/i386-darwin-tdep.c b/gdb/i386-darwin-tdep.c
index 2a9198aceb3..8cbe1a90826 100644
--- a/gdb/i386-darwin-tdep.c
+++ b/gdb/i386-darwin-tdep.c
@@ -156,7 +156,7 @@ i386_darwin_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 			     function_call_return_method return_method,
 			     CORE_ADDR struct_addr)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   gdb_byte buf[4];
   int i;
@@ -248,7 +248,7 @@ i386_darwin_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 static void
 i386_darwin_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   /* We support the SSE registers.  */
   tdep->num_xmm_regs = I386_NUM_XREGS - 1;
diff --git a/gdb/i386-fbsd-tdep.c b/gdb/i386-fbsd-tdep.c
index b7a524db68c..9d8d7c1615a 100644
--- a/gdb/i386-fbsd-tdep.c
+++ b/gdb/i386-fbsd-tdep.c
@@ -325,7 +325,7 @@ i386fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				       void *cb_data,
 				       const struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   cb (".reg", I386_FBSD_SIZEOF_GREGSET, I386_FBSD_SIZEOF_GREGSET,
       &i386_fbsd_gregset, NULL, cb_data);
@@ -365,7 +365,7 @@ i386fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 static void
 i386fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support. */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/i386-gnu-tdep.c b/gdb/i386-gnu-tdep.c
index 3d97fe36a85..97a512975be 100644
--- a/gdb/i386-gnu-tdep.c
+++ b/gdb/i386-gnu-tdep.c
@@ -173,7 +173,7 @@ static int i386gnu_gregset_reg_offset[] =
 static void
 i386gnu_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   /* GNU uses ELF.  */
   i386_elf_init_abi (info, gdbarch);
diff --git a/gdb/i386-go32-tdep.c b/gdb/i386-go32-tdep.c
index 0c0c08e3579..9d591158be6 100644
--- a/gdb/i386-go32-tdep.c
+++ b/gdb/i386-go32-tdep.c
@@ -26,7 +26,7 @@
 static void
 i386_go32_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   /* DJGPP doesn't have any special frames for signal handlers.  */
   tdep->sigtramp_p = NULL;
diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c
index 6033104230f..0764b8d9bd9 100644
--- a/gdb/i386-linux-tdep.c
+++ b/gdb/i386-linux-tdep.c
@@ -763,7 +763,7 @@ i386_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					 void *cb_data,
 					 const struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   cb (".reg", 68, 68, &i386_gregset, NULL, cb_data);
 
@@ -825,7 +825,7 @@ i386_linux_displaced_step_copy_insn (struct gdbarch *gdbarch,
 static void
 i386_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   const struct target_desc *tdesc = info.target_desc;
   struct tdesc_arch_data *tdesc_data = info.tdesc_data;
   const struct tdesc_feature *feature;
diff --git a/gdb/i386-netbsd-tdep.c b/gdb/i386-netbsd-tdep.c
index a9ebc3dd827..f0aa7f4837e 100644
--- a/gdb/i386-netbsd-tdep.c
+++ b/gdb/i386-netbsd-tdep.c
@@ -372,7 +372,7 @@ i386nbsd_sigtramp_cache_init (const struct tramp_frame *self,
 static void 
 i386nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   /* Obviously NetBSD is BSD-based.  */
   i386bsd_init_abi (info, gdbarch);
@@ -407,7 +407,7 @@ i386nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 static void
 i386nbsdelf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   /* It's still NetBSD.  */
   i386nbsd_init_abi (info, gdbarch);
diff --git a/gdb/i386-nto-tdep.c b/gdb/i386-nto-tdep.c
index 259867f262b..731f9d326b0 100644
--- a/gdb/i386-nto-tdep.c
+++ b/gdb/i386-nto-tdep.c
@@ -77,7 +77,7 @@ static void
 i386nto_supply_gregset (struct regcache *regcache, char *gpregs)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   gdb_assert (tdep->gregset_reg_offset == i386nto_gregset_reg_offset);
   i386_gregset.supply_regset (&i386_gregset, regcache, -1,
@@ -126,7 +126,7 @@ static int
 i386nto_register_area (struct gdbarch *gdbarch,
 		       int regno, int regset, unsigned *off)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   *off = 0;
   if (regset == NTO_REG_GENERAL)
@@ -315,7 +315,7 @@ init_i386nto_ops (void)
 static void
 i386nto_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   static struct target_so_ops nto_svr4_so_ops;
 
   /* Deal with our strange signals.  */
diff --git a/gdb/i386-obsd-tdep.c b/gdb/i386-obsd-tdep.c
index 798094509c6..e0bd677d866 100644
--- a/gdb/i386-obsd-tdep.c
+++ b/gdb/i386-obsd-tdep.c
@@ -407,7 +407,7 @@ static const struct frame_unwind i386obsd_trapframe_unwind = {
 static void 
 i386obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   /* Obviously OpenBSD is BSD-based.  */
   i386bsd_init_abi (info, gdbarch);
diff --git a/gdb/i386-sol2-tdep.c b/gdb/i386-sol2-tdep.c
index 5ee108d3578..a5c7ccf74a3 100644
--- a/gdb/i386-sol2-tdep.c
+++ b/gdb/i386-sol2-tdep.c
@@ -65,7 +65,7 @@ i386_sol2_mcontext_addr (struct frame_info *this_frame)
 static void
 i386_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   /* Solaris is SVR4-based.  */
   i386_svr4_init_abi (info, gdbarch);
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index d500f6998c5..f940f60ac21 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -169,7 +169,7 @@ const int num_lower_zmm_regs = 16;
 static int
 i386_mmx_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   int mm0_regnum = tdep->mm0_regnum;
 
   if (mm0_regnum < 0)
@@ -184,7 +184,7 @@ i386_mmx_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_byte_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   regnum -= tdep->al_regnum;
   return regnum >= 0 && regnum < tdep->num_byte_regs;
@@ -195,7 +195,7 @@ i386_byte_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_word_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   regnum -= tdep->ax_regnum;
   return regnum >= 0 && regnum < tdep->num_word_regs;
@@ -206,7 +206,7 @@ i386_word_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_dword_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   int eax_regnum = tdep->eax_regnum;
 
   if (eax_regnum < 0)
@@ -221,7 +221,7 @@ i386_dword_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_zmmh_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   int zmm0h_regnum = tdep->zmm0h_regnum;
 
   if (zmm0h_regnum < 0)
@@ -234,7 +234,7 @@ i386_zmmh_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_zmm_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   int zmm0_regnum = tdep->zmm0_regnum;
 
   if (zmm0_regnum < 0)
@@ -247,7 +247,7 @@ i386_zmm_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_k_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   int k0_regnum = tdep->k0_regnum;
 
   if (k0_regnum < 0)
@@ -260,7 +260,7 @@ i386_k_regnum_p (struct gdbarch *gdbarch, int regnum)
 static int
 i386_ymmh_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   int ymm0h_regnum = tdep->ymm0h_regnum;
 
   if (ymm0h_regnum < 0)
@@ -275,7 +275,7 @@ i386_ymmh_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_ymm_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   int ymm0_regnum = tdep->ymm0_regnum;
 
   if (ymm0_regnum < 0)
@@ -288,7 +288,7 @@ i386_ymm_regnum_p (struct gdbarch *gdbarch, int regnum)
 static int
 i386_ymmh_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   int ymm16h_regnum = tdep->ymm16h_regnum;
 
   if (ymm16h_regnum < 0)
@@ -301,7 +301,7 @@ i386_ymmh_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_ymm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   int ymm16_regnum = tdep->ymm16_regnum;
 
   if (ymm16_regnum < 0)
@@ -316,7 +316,7 @@ i386_ymm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_bnd_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   int bnd0_regnum = tdep->bnd0_regnum;
 
   if (bnd0_regnum < 0)
@@ -331,7 +331,7 @@ i386_bnd_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_xmm_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   int num_xmm_regs = I387_NUM_XMM_REGS (tdep);
 
   if (num_xmm_regs == 0)
@@ -346,7 +346,7 @@ i386_xmm_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_xmm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   int num_xmm_avx512_regs = I387_NUM_XMM_AVX512_REGS (tdep);
 
   if (num_xmm_avx512_regs == 0)
@@ -359,7 +359,7 @@ i386_xmm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
 static int
 i386_mxcsr_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   if (I387_NUM_XMM_REGS (tdep) == 0)
     return 0;
@@ -372,7 +372,7 @@ i386_mxcsr_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_fp_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   if (I387_ST0_REGNUM (tdep) < 0)
     return 0;
@@ -384,7 +384,7 @@ i386_fp_regnum_p (struct gdbarch *gdbarch, int regnum)
 int
 i386_fpc_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   if (I387_ST0_REGNUM (tdep) < 0)
     return 0;
@@ -398,7 +398,7 @@ i386_fpc_regnum_p (struct gdbarch *gdbarch, int regnum)
 static int
 i386_bndr_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
    if (I387_BND0R_REGNUM (tdep) < 0)
      return 0;
@@ -412,7 +412,7 @@ i386_bndr_regnum_p (struct gdbarch *gdbarch, int regnum)
 static int
 i386_mpx_ctrl_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
    if (I387_BNDCFGU_REGNUM (tdep) < 0)
      return 0;
@@ -426,7 +426,7 @@ i386_mpx_ctrl_regnum_p (struct gdbarch *gdbarch, int regnum)
 bool
 i386_pkru_regnum_p (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   int pkru_regnum = tdep->pkru_regnum;
 
   if (pkru_regnum < 0)
@@ -462,7 +462,7 @@ i386_register_name (struct gdbarch *gdbarch, int regnum)
 const char *
 i386_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   if (i386_bnd_regnum_p (gdbarch, regnum))
     return i386_bnd_names[regnum - tdep->bnd0_regnum];
   if (i386_mmx_regnum_p (gdbarch, regnum))
@@ -485,7 +485,7 @@ i386_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 static int
 i386_dbx_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   /* This implements what GCC calls the "default" register map
      (dbx_register_map[]).  */
@@ -532,7 +532,7 @@ i386_dbx_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 static int
 i386_svr4_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   /* This implements the GCC register map that tries to be compatible
      with the SVR4 C compiler for DWARF (svr4_dbx_register_map[]).  */
@@ -2434,7 +2434,7 @@ static struct i386_frame_cache *
 i386_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct i386_frame_cache *cache;
   CORE_ADDR addr;
@@ -2524,7 +2524,7 @@ i386_sigtramp_frame_sniffer (const struct frame_unwind *self,
 			     void **this_prologue_cache)
 {
   gdbarch *arch = get_frame_arch (this_frame);
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (arch);
 
   /* We shouldn't even bother if we don't have a sigcontext_addr
      handler.  */
@@ -2611,7 +2611,7 @@ i386_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
   CORE_ADDR sp, jb_addr;
   struct gdbarch *gdbarch = get_frame_arch (frame);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   int jb_pc_offset = tdep->jb_pc_offset;
 
   /* If JB_PC_OFFSET is -1, we have no way to find out where the
@@ -2860,7 +2860,7 @@ static void
 i386_extract_return_value (struct gdbarch *gdbarch, struct type *type,
 			   struct regcache *regcache, gdb_byte *valbuf)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   int len = TYPE_LENGTH (type);
   gdb_byte buf[I386_MAX_REGISTER_SIZE];
 
@@ -2918,7 +2918,7 @@ static void
 i386_store_return_value (struct gdbarch *gdbarch, struct type *type,
 			 struct regcache *regcache, const gdb_byte *valbuf)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   int len = TYPE_LENGTH (type);
 
   if (type->code () == TYPE_CODE_FLT)
@@ -2997,7 +2997,7 @@ static const char *struct_convention = default_struct_convention;
 static int
 i386_reg_struct_return_p (struct gdbarch *gdbarch, struct type *type)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   enum type_code code = type->code ();
   int len = TYPE_LENGTH (type);
 
@@ -3099,7 +3099,7 @@ i386_return_value (struct gdbarch *gdbarch, struct value *function,
 struct type *
 i387_ext_type (struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   if (!tdep->i387_ext_type)
     {
@@ -3117,7 +3117,7 @@ i387_ext_type (struct gdbarch *gdbarch)
 static struct type *
 i386_bnd_type (struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
 
   if (!tdep->i386_bnd_type)
@@ -3153,7 +3153,7 @@ i386_bnd_type (struct gdbarch *gdbarch)
 static struct type *
 i386_zmm_type (struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   if (!tdep->i386_zmm_type)
     {
@@ -3212,7 +3212,7 @@ i386_zmm_type (struct gdbarch *gdbarch)
 static struct type *
 i386_ymm_type (struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   if (!tdep->i386_ymm_type)
     {
@@ -3269,7 +3269,7 @@ i386_ymm_type (struct gdbarch *gdbarch)
 static struct type *
 i386_mmx_type (struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   if (!tdep->i386_mmx_type)
     {
@@ -3346,7 +3346,7 @@ static int
 i386_mmx_regnum_to_fp_regnum (readable_regcache *regcache, int regnum)
 {
   gdbarch *arch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (arch);
   int mmxreg, fpreg;
   ULONGEST fstat;
   int tos;
@@ -3387,7 +3387,7 @@ i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
     }
   else
     {
-      i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+      i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
       if (i386_bnd_regnum_p (gdbarch, regnum))
 	{
 	  regnum -= tdep->bnd0_regnum;
@@ -3577,7 +3577,7 @@ i386_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
     }
   else
     {
-      i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+      i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
       if (i386_bnd_regnum_p (gdbarch, regnum))
 	{
@@ -3685,7 +3685,7 @@ int
 i386_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				 struct agent_expr *ax, int regnum)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   if (i386_mmx_regnum_p (gdbarch, regnum))
     {
@@ -3902,7 +3902,7 @@ i386_supply_gregset (const struct regset *regset, struct regcache *regcache,
 		     int regnum, const void *gregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   const gdb_byte *regs = (const gdb_byte *) gregs;
   int i;
 
@@ -3927,7 +3927,7 @@ i386_collect_gregset (const struct regset *regset,
 		      int regnum, void *gregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   gdb_byte *regs = (gdb_byte *) gregs;
   int i;
 
@@ -3950,7 +3950,7 @@ i386_supply_fpregset (const struct regset *regset, struct regcache *regcache,
 		      int regnum, const void *fpregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   if (len == I387_SIZEOF_FXSAVE)
     {
@@ -3973,7 +3973,7 @@ i386_collect_fpregset (const struct regset *regset,
 		       int regnum, void *fpregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   if (len == I387_SIZEOF_FXSAVE)
     {
@@ -4005,7 +4005,7 @@ i386_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				   void *cb_data,
 				   const struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   cb (".reg", tdep->sizeof_gregset, tdep->sizeof_gregset, &i386_gregset, NULL,
       cb_data);
@@ -4510,7 +4510,7 @@ i386_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 void
 i386_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   /* System V Release 4 uses ELF.  */
   i386_elf_init_abi (info, gdbarch);
@@ -4552,7 +4552,7 @@ int
 i386_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 			  const struct reggroup *group)
 {
-  const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  const i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   int fp_regnum_p, mmx_regnum_p, xmm_regnum_p, mxcsr_regnum_p,
       ymm_regnum_p, ymmh_regnum_p, ymm_avx512_regnum_p, ymmh_avx512_regnum_p,
       bndr_regnum_p, bnd_regnum_p, zmm_regnum_p, zmmh_regnum_p,
@@ -4997,7 +4997,7 @@ static int i386_record_floats (struct gdbarch *gdbarch,
 			       struct i386_record_s *ir,
 			       uint32_t iregnum)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   int i;
 
   /* Oza: Because of floating point insn push/pop of fpu stack is going to
@@ -5068,7 +5068,7 @@ i386_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
   ULONGEST addr;
   gdb_byte buf[I386_MAX_REGISTER_SIZE];
   struct i386_record_s ir;
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   uint8_t rex_w = -1;
   uint8_t rex_r = 0;
 
@@ -8839,7 +8839,7 @@ i386_mpx_bd_base (void)
 
   rcache = get_current_regcache ();
   gdbarch *arch = rcache->arch ();
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (arch);
 
   regstatus = regcache_raw_read_unsigned (rcache, tdep->bndcfgu_regnum, &ret);
 
@@ -8853,7 +8853,7 @@ int
 i386_mpx_enabled (void)
 {
   gdbarch *arch = get_current_arch ();
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (arch);
   const struct target_desc *tdesc = tdep->tdesc;
 
   return (tdesc_find_feature (tdesc, "org.gnu.gdb.i386.mpx") != NULL);
diff --git a/gdb/i386-windows-tdep.c b/gdb/i386-windows-tdep.c
index 9eec6e28109..5a560fa628b 100644
--- a/gdb/i386-windows-tdep.c
+++ b/gdb/i386-windows-tdep.c
@@ -136,7 +136,7 @@ i386_windows_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 static void
 i386_windows_init_abi_common (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   set_gdbarch_skip_trampoline_code (gdbarch, i386_windows_skip_trampoline_code);
 
diff --git a/gdb/i387-tdep.c b/gdb/i387-tdep.c
index 42ed4eebc2c..cb06306c704 100644
--- a/gdb/i387-tdep.c
+++ b/gdb/i387-tdep.c
@@ -204,7 +204,7 @@ void
 i387_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
 		       struct frame_info *frame, const char *args)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   ULONGEST fctrl;
   int fctrl_p;
   ULONGEST fstat;
@@ -440,7 +440,7 @@ void
 i387_supply_fsave (struct regcache *regcache, int regnum, const void *fsave)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   const gdb_byte *regs = (const gdb_byte *) fsave;
   int i;
@@ -495,7 +495,7 @@ void
 i387_collect_fsave (const struct regcache *regcache, int regnum, void *fsave)
 {
   gdbarch *arch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (arch);
   gdb_byte *regs = (gdb_byte *) fsave;
   int i;
 
@@ -589,7 +589,7 @@ void
 i387_supply_fxsave (struct regcache *regcache, int regnum, const void *fxsave)
 {
   gdbarch *arch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (arch);
   const gdb_byte *regs = (const gdb_byte *) fxsave;
   int i;
 
@@ -673,7 +673,7 @@ void
 i387_collect_fxsave (const struct regcache *regcache, int regnum, void *fxsave)
 {
   gdbarch *arch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (arch);
   gdb_byte *regs = (gdb_byte *) fxsave;
   int i;
 
@@ -906,7 +906,7 @@ i387_xsave_get_clear_bv (struct gdbarch *gdbarch, const void *xsave)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   const gdb_byte *regs = (const gdb_byte *) xsave;
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   /* Get `xstat_bv'.  The supported bits in `xstat_bv' are 8 bytes.  */
   ULONGEST xstate_bv = extract_unsigned_integer (XSAVE_XSTATE_BV_ADDR (regs),
@@ -926,7 +926,7 @@ i387_supply_xsave (struct regcache *regcache, int regnum,
 {
   struct gdbarch *gdbarch = regcache->arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   const gdb_byte *regs = (const gdb_byte *) xsave;
   int i;
   /* In 64-bit mode the split between "low" and "high" ZMM registers is at
@@ -1349,7 +1349,7 @@ i387_collect_xsave (const struct regcache *regcache, int regnum,
 {
   struct gdbarch *gdbarch = regcache->arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   gdb_byte *p, *regs = (gdb_byte *) xsave;
   gdb_byte raw[I386_MAX_REGISTER_SIZE];
   ULONGEST initial_xstate_bv, clear_bv, xstate_bv = 0;
@@ -1934,7 +1934,7 @@ i387_tag (const gdb_byte *raw)
 void
 i387_return_value (struct gdbarch *gdbarch, struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
   ULONGEST fstat;
 
   /* Set the top of the floating-point register stack to 7.  The
@@ -1957,7 +1957,7 @@ i387_return_value (struct gdbarch *gdbarch, struct regcache *regcache)
 void
 i387_reset_bnd_regs (struct gdbarch *gdbarch, struct regcache *regcache)
 {
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   if (I387_BND0R_REGNUM (tdep) > 0)
     {
diff --git a/gdb/ia64-linux-tdep.c b/gdb/ia64-linux-tdep.c
index 508d4e6f7c6..be87fa8d711 100644
--- a/gdb/ia64-linux-tdep.c
+++ b/gdb/ia64-linux-tdep.c
@@ -216,7 +216,7 @@ ia64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 static void
 ia64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep_cast<ia64_gdbarch_tdep> (gdbarch);
   static const char *const stap_register_prefixes[] = { "r", NULL };
   static const char *const stap_register_indirection_prefixes[] = { "[",
 								    NULL };
diff --git a/gdb/ia64-tdep.c b/gdb/ia64-tdep.c
index b7c1c0decae..30f09b37ddb 100644
--- a/gdb/ia64-tdep.c
+++ b/gdb/ia64-tdep.c
@@ -310,7 +310,7 @@ static const struct floatformat *floatformats_ia64_ext[2] =
 static struct type *
 ia64_ext_type (struct gdbarch *gdbarch)
 {
-  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep_cast<ia64_gdbarch_tdep> (gdbarch);
 
   if (!tdep->ia64_ext_type)
     tdep->ia64_ext_type
@@ -2177,7 +2177,7 @@ ia64_sigtramp_frame_init_saved_regs (struct frame_info *this_frame,
 				     struct ia64_frame_cache *cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep_cast<ia64_gdbarch_tdep> (gdbarch);
 
   if (tdep->sigcontext_register_address)
     {
@@ -2336,7 +2336,7 @@ ia64_sigtramp_frame_sniffer (const struct frame_unwind *self,
 			     void **this_cache)
 {
   gdbarch *arch = get_frame_arch (this_frame);
-  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (arch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep_cast<ia64_gdbarch_tdep> (arch);
   if (tdep->pc_in_sigtramp)
     {
       CORE_ADDR pc = get_frame_pc (this_frame);
@@ -2485,7 +2485,7 @@ ia64_access_reg (unw_addr_space_t as, unw_regnum_t uw_regnum, unw_word_t *val,
   unw_word_t bsp, sof, cfm, psr, ip;
   struct frame_info *this_frame = (struct frame_info *) arg;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep_cast<ia64_gdbarch_tdep> (gdbarch);
   
   /* We never call any libunwind routines that need to write registers.  */
   gdb_assert (!write);
@@ -3485,7 +3485,7 @@ ia64_find_global_pointer_from_dynamic_section (struct gdbarch *gdbarch,
 static CORE_ADDR
 ia64_find_global_pointer (struct gdbarch *gdbarch, CORE_ADDR faddr)
 {
-  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep_cast<ia64_gdbarch_tdep> (gdbarch);
   CORE_ADDR addr = 0;
 
   if (tdep->find_global_pointer_from_solib)
@@ -3680,7 +3680,7 @@ ia64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 		      function_call_return_method return_method,
 		      CORE_ADDR struct_addr)
 {
-  ia64_gdbarch_tdep *tdep = gdbarch_tdep<ia64_gdbarch_tdep> (gdbarch);
+  ia64_gdbarch_tdep *tdep = gdbarch_tdep_cast<ia64_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int argno;
   struct value *arg;
diff --git a/gdb/loongarch-linux-tdep.c b/gdb/loongarch-linux-tdep.c
index 3a81ff31972..0ad208ebdb2 100644
--- a/gdb/loongarch-linux-tdep.c
+++ b/gdb/loongarch-linux-tdep.c
@@ -255,7 +255,7 @@ loongarch_linux_syscall_next_pc (struct frame_info *frame)
 static void
 loongarch_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  loongarch_gdbarch_tdep *tdep = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
+  loongarch_gdbarch_tdep *tdep = gdbarch_tdep_cast<loongarch_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/loongarch-tdep.c b/gdb/loongarch-tdep.c
index 5711e6f05d7..88e31c26da7 100644
--- a/gdb/loongarch-tdep.c
+++ b/gdb/loongarch-tdep.c
@@ -225,7 +225,7 @@ static CORE_ADDR
 loongarch_next_pc (struct regcache *regcache, CORE_ADDR cur_pc)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  loongarch_gdbarch_tdep *tdep = gdbarch_tdep<loongarch_gdbarch_tdep> (gdbarch);
+  loongarch_gdbarch_tdep *tdep = gdbarch_tdep_cast<loongarch_gdbarch_tdep> (gdbarch);
   insn_t insn = loongarch_fetch_instruction (cur_pc);
   size_t insn_len = loongarch_insn_length (insn);
   CORE_ADDR next_pc = cur_pc + insn_len;
@@ -1237,7 +1237,7 @@ loongarch_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 	 we are looking for.  If it doesn't then we can't reuse this
 	 gdbarch.  */
       loongarch_gdbarch_tdep *candidate_tdep
-	= gdbarch_tdep<loongarch_gdbarch_tdep> (arches->gdbarch);
+	= gdbarch_tdep_cast<loongarch_gdbarch_tdep> (arches->gdbarch);
 
       if (candidate_tdep->abi_features != abi_features)
 	continue;
diff --git a/gdb/m32c-tdep.c b/gdb/m32c-tdep.c
index 37456d16cb3..41ba294e865 100644
--- a/gdb/m32c-tdep.c
+++ b/gdb/m32c-tdep.c
@@ -142,7 +142,7 @@ struct m32c_gdbarch_tdep : gdbarch_tdep
 static void
 make_types (struct gdbarch *arch)
 {
-  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep_cast<m32c_gdbarch_tdep> (arch);
   unsigned long mach = gdbarch_bfd_arch_info (arch)->mach;
   int data_addr_reg_bits, code_addr_reg_bits;
   char type_name[50];
@@ -215,7 +215,7 @@ make_types (struct gdbarch *arch)
 static const char *
 m32c_register_name (struct gdbarch *gdbarch, int num)
 {
-  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep_cast<m32c_gdbarch_tdep> (gdbarch);
   return tdep->regs[num].name;
 }
 
@@ -223,7 +223,7 @@ m32c_register_name (struct gdbarch *gdbarch, int num)
 static struct type *
 m32c_register_type (struct gdbarch *arch, int reg_nr)
 {
-  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep_cast<m32c_gdbarch_tdep> (arch);
   return tdep->regs[reg_nr].type;
 }
 
@@ -231,7 +231,7 @@ m32c_register_type (struct gdbarch *arch, int reg_nr)
 static int
 m32c_register_sim_regno (struct gdbarch *gdbarch, int reg_nr)
 {
-  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep_cast<m32c_gdbarch_tdep> (gdbarch);
   return tdep->regs[reg_nr].sim_num;
 }
 
@@ -239,7 +239,7 @@ m32c_register_sim_regno (struct gdbarch *gdbarch, int reg_nr)
 static int
 m32c_debug_info_reg_to_regnum (struct gdbarch *gdbarch, int reg_nr)
 {
-  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep_cast<m32c_gdbarch_tdep> (gdbarch);
   if (0 <= reg_nr && reg_nr <= M32C_MAX_DWARF_REGNUM
       && tdep->dwarf_regs[reg_nr])
     return tdep->dwarf_regs[reg_nr]->num;
@@ -254,7 +254,7 @@ static int
 m32c_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 			  const struct reggroup *group)
 {
-  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep_cast<m32c_gdbarch_tdep> (gdbarch);
   struct m32c_reg *reg = &tdep->regs[regnum];
 
   /* The anonymous raw registers aren't in any groups.  */
@@ -330,7 +330,7 @@ static int
 m32c_read_flg (readable_regcache *cache)
 {
   gdbarch *arch = cache->arch ();
-  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep_cast<m32c_gdbarch_tdep> (arch);
   ULONGEST flg;
 
   cache->raw_read (tdep->flg->num, &flg);
@@ -530,7 +530,7 @@ static enum register_status
 m32c_r3r2r1r0_read (struct m32c_reg *reg, readable_regcache *cache, gdb_byte *buf)
 {
   gdbarch *arch = reg->arch;
-  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep_cast<m32c_gdbarch_tdep> (arch);
   int len = TYPE_LENGTH (tdep->r0->type);
   enum register_status status;
 
@@ -567,7 +567,7 @@ m32c_r3r2r1r0_write (struct m32c_reg *reg, struct regcache *cache,
 		     const gdb_byte *buf)
 {
   gdbarch *arch = reg->arch;
-  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep_cast<m32c_gdbarch_tdep> (arch);
   int len = TYPE_LENGTH (tdep->r0->type);
 
   if (gdbarch_byte_order (reg->arch) == BFD_ENDIAN_BIG)
@@ -595,7 +595,7 @@ m32c_pseudo_register_read (struct gdbarch *arch,
 			   int cookednum,
 			   gdb_byte *buf)
 {
-  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep_cast<m32c_gdbarch_tdep> (arch);
   struct m32c_reg *reg;
 
   gdb_assert (0 <= cookednum && cookednum < tdep->num_regs);
@@ -613,7 +613,7 @@ m32c_pseudo_register_write (struct gdbarch *arch,
 			    int cookednum,
 			    const gdb_byte *buf)
 {
-  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep_cast<m32c_gdbarch_tdep> (arch);
   struct m32c_reg *reg;
 
   gdb_assert (0 <= cookednum && cookednum < tdep->num_regs);
@@ -638,7 +638,7 @@ add_reg (struct gdbarch *arch,
 	 struct m32c_reg *ry,
 	 int n)
 {
-  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep_cast<m32c_gdbarch_tdep> (arch);
   struct m32c_reg *r = &tdep->regs[tdep->num_regs];
 
   gdb_assert (tdep->num_regs < M32C_MAX_NUM_REGS);
@@ -678,7 +678,7 @@ set_dwarf_regnum (struct m32c_reg *reg, int num)
 
   /* Update the DWARF->reg mapping.  */
   gdbarch *arch = reg->arch;
-  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep_cast<m32c_gdbarch_tdep> (arch);
   tdep->dwarf_regs[num] = reg;
 }
 
@@ -800,7 +800,7 @@ mark_save_restore (struct m32c_reg *reg)
 static void
 make_regs (struct gdbarch *arch)
 {
-  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep_cast<m32c_gdbarch_tdep> (arch);
   int mach = gdbarch_bfd_arch_info (arch)->mach;
   int num_raw_regs;
   int num_cooked_regs;
@@ -1349,7 +1349,7 @@ m32c_pv_enter (struct m32c_pv_state *state, int size)
     return 1;
 
   gdbarch *arch = state->arch;
-  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep_cast<m32c_gdbarch_tdep> (arch);
   if (m32c_pv_push (state, state->fb, tdep->push_addr_bytes))
     return 1;
 
@@ -1379,7 +1379,7 @@ static int
 m32c_pv_pushm (struct m32c_pv_state *state, int src)
 {
   gdbarch *arch = state->arch;
-  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep_cast<m32c_gdbarch_tdep> (arch);
 
   /* The bits in SRC indicating which registers to save are:
      r0 r1 r2 r3 a0 a1 sb fb */
@@ -1400,7 +1400,7 @@ static int
 m32c_is_1st_arg_reg (struct m32c_pv_state *state, pv_t value)
 {
   gdbarch *arch = state->arch;
-  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep_cast<m32c_gdbarch_tdep> (arch);
 
   return (value.kind == pvk_register
 	  && (gdbarch_bfd_arch_info (state->arch)->mach == bfd_mach_m16c
@@ -1415,7 +1415,7 @@ static int
 m32c_is_arg_reg (struct m32c_pv_state *state, pv_t value)
 {
   gdbarch *arch = state->arch;
-  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep_cast<m32c_gdbarch_tdep> (arch);
 
   return (value.kind == pvk_register
 	  && (gdbarch_bfd_arch_info (state->arch)->mach == bfd_mach_m16c
@@ -1440,7 +1440,7 @@ m32c_is_arg_spill (struct m32c_pv_state *st,
 		   pv_t value)
 {
   gdbarch *arch = st->arch;
-  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep_cast<m32c_gdbarch_tdep> (arch);
 
   return (m32c_is_arg_reg (st, value)
 	  && loc.kind == srcdest_mem
@@ -1464,7 +1464,7 @@ m32c_is_struct_return (struct m32c_pv_state *st,
 		       pv_t value)
 {
   gdbarch *arch = st->arch;
-  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep_cast<m32c_gdbarch_tdep> (arch);
 
   return (m32c_is_1st_arg_reg (st, value)
 	  && !st->stack->find_reg (st->arch, value.reg, 0)
@@ -1482,7 +1482,7 @@ static int
 m32c_pushm_is_reg_save (struct m32c_pv_state *st, int src)
 {
   gdbarch *arch = st->arch;
-  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep_cast<m32c_gdbarch_tdep> (arch);
 
   /* The bits in SRC indicating which registers to save are:
      r0 r1 r2 r3 a0 a1 sb fb */
@@ -1510,7 +1510,7 @@ check_for_saved (void *prologue_untyped, pv_t addr, CORE_ADDR size, pv_t value)
 {
   struct m32c_prologue *prologue = (struct m32c_prologue *) prologue_untyped;
   struct gdbarch *arch = prologue->arch;
-  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep_cast<m32c_gdbarch_tdep> (arch);
 
   /* Is this the unchanged value of some register being saved on the
      stack?  */
@@ -1550,7 +1550,7 @@ m32c_analyze_prologue (struct gdbarch *arch,
 		       CORE_ADDR start, CORE_ADDR limit,
 		       struct m32c_prologue *prologue)
 {
-  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep_cast<m32c_gdbarch_tdep> (arch);
   unsigned long mach = gdbarch_bfd_arch_info (arch)->mach;
   CORE_ADDR after_last_frame_related_insn;
   struct m32c_pv_state st;
@@ -1881,7 +1881,7 @@ m32c_frame_base (struct frame_info *this_frame,
   struct m32c_prologue *p
     = m32c_analyze_frame_prologue (this_frame, this_prologue_cache);
   gdbarch *arch = get_frame_arch (this_frame);
-  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep_cast<m32c_gdbarch_tdep> (arch);
 
   /* In functions that use alloca, the distance between the stack
      pointer and the frame base varies dynamically, so we can't use
@@ -1932,7 +1932,7 @@ m32c_prev_register (struct frame_info *this_frame,
 		    void **this_prologue_cache, int regnum)
 {
   gdbarch *arch = get_frame_arch (this_frame);
-  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (arch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep_cast<m32c_gdbarch_tdep> (arch);
   struct m32c_prologue *p
     = m32c_analyze_frame_prologue (this_frame, this_prologue_cache);
   CORE_ADDR frame_base = m32c_frame_base (this_frame, this_prologue_cache);
@@ -2015,7 +2015,7 @@ m32c_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 		      function_call_return_method return_method,
 		      CORE_ADDR struct_addr)
 {
-  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep_cast<m32c_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   unsigned long mach = gdbarch_bfd_arch_info (gdbarch)->mach;
   CORE_ADDR cfa;
@@ -2178,7 +2178,7 @@ m32c_return_value (struct gdbarch *gdbarch,
 		   gdb_byte *readbuf,
 		   const gdb_byte *writebuf)
 {
-  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep_cast<m32c_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   enum return_value_convention conv;
   ULONGEST valtype_len = TYPE_LENGTH (valtype);
@@ -2309,7 +2309,7 @@ static CORE_ADDR
 m32c_skip_trampoline_code (struct frame_info *frame, CORE_ADDR stop_pc)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep_cast<m32c_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   /* It would be nicer to simply look up the addresses of known
@@ -2555,7 +2555,7 @@ m32c_virtual_frame_pointer (struct gdbarch *gdbarch, CORE_ADDR pc,
   struct m32c_prologue p;
 
   struct regcache *regcache = get_current_regcache ();
-  m32c_gdbarch_tdep *tdep = gdbarch_tdep<m32c_gdbarch_tdep> (gdbarch);
+  m32c_gdbarch_tdep *tdep = gdbarch_tdep_cast<m32c_gdbarch_tdep> (gdbarch);
   
   if (!find_pc_partial_function (pc, &name, &func_addr, &func_end))
     internal_error (__FILE__, __LINE__,
diff --git a/gdb/m68hc11-tdep.c b/gdb/m68hc11-tdep.c
index 9eb18b937be..48d88926018 100644
--- a/gdb/m68hc11-tdep.c
+++ b/gdb/m68hc11-tdep.c
@@ -146,14 +146,14 @@ struct m68gc11_gdbarch_tdep : gdbarch_tdep
 static int
 stack_correction (gdbarch *arch)
 {
-  m68gc11_gdbarch_tdep *tdep = gdbarch_tdep<m68gc11_gdbarch_tdep> (arch);
+  m68gc11_gdbarch_tdep *tdep = gdbarch_tdep_cast<m68gc11_gdbarch_tdep> (arch);
   return tdep->stack_correction;
 }
 
 static int
 use_page_register (gdbarch *arch)
 {
-  m68gc11_gdbarch_tdep *tdep = gdbarch_tdep<m68gc11_gdbarch_tdep> (arch);
+  m68gc11_gdbarch_tdep *tdep = gdbarch_tdep_cast<m68gc11_gdbarch_tdep> (arch);
   return tdep->stack_correction;
 }
 
@@ -642,7 +642,7 @@ m68hc11_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
       return pc;
     }
 
-  m68gc11_gdbarch_tdep *tdep = gdbarch_tdep<m68gc11_gdbarch_tdep> (gdbarch);
+  m68gc11_gdbarch_tdep *tdep = gdbarch_tdep_cast<m68gc11_gdbarch_tdep> (gdbarch);
   seq_table = tdep->prologue;
   
   /* The 68hc11 stack is as follows:
@@ -1020,7 +1020,7 @@ m68hc11_print_register (struct gdbarch *gdbarch, struct ui_file *file,
   else
     {
       m68gc11_gdbarch_tdep *tdep
-	= gdbarch_tdep<m68gc11_gdbarch_tdep> (gdbarch);
+	= gdbarch_tdep_cast<m68gc11_gdbarch_tdep> (gdbarch);
 
       if (regno == HARD_PC_REGNUM && tdep->use_page_register)
 	{
@@ -1125,7 +1125,7 @@ m68hc11_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file,
       gdb_printf (file, " Y=");
       m68hc11_print_register (gdbarch, file, frame, HARD_Y_REGNUM);
   
-      m68gc11_gdbarch_tdep *tdep = gdbarch_tdep<m68gc11_gdbarch_tdep> (gdbarch);
+      m68gc11_gdbarch_tdep *tdep = gdbarch_tdep_cast<m68gc11_gdbarch_tdep> (gdbarch);
 
       if (tdep->use_page_register)
 	{
@@ -1417,7 +1417,7 @@ m68hc11_gdbarch_init (struct gdbarch_info info,
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       m68gc11_gdbarch_tdep *tdep
-	= gdbarch_tdep<m68gc11_gdbarch_tdep> (arches->gdbarch);
+	= gdbarch_tdep_cast<m68gc11_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->elf_flags != elf_flags)
 	continue;
diff --git a/gdb/m68k-bsd-tdep.c b/gdb/m68k-bsd-tdep.c
index 2614c223f8e..6223613457c 100644
--- a/gdb/m68k-bsd-tdep.c
+++ b/gdb/m68k-bsd-tdep.c
@@ -133,7 +133,7 @@ m68kbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 static void
 m68kbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep_cast<m68k_gdbarch_tdep> (gdbarch);
 
   tdep->jb_pc = 5;
   tdep->jb_elt_size = 4;
diff --git a/gdb/m68k-linux-tdep.c b/gdb/m68k-linux-tdep.c
index 28401d3ecc6..4ecd80c3001 100644
--- a/gdb/m68k-linux-tdep.c
+++ b/gdb/m68k-linux-tdep.c
@@ -384,7 +384,7 @@ m68k_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 static void
 m68k_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep_cast<m68k_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/m68k-tdep.c b/gdb/m68k-tdep.c
index 9e59f5904c3..e2b42d86933 100644
--- a/gdb/m68k-tdep.c
+++ b/gdb/m68k-tdep.c
@@ -70,7 +70,7 @@ typedef BP_MANIPULATION (m68k_break_insn) m68k_breakpoint;
 static struct type *
 m68k_ps_type (struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep_cast<m68k_gdbarch_tdep> (gdbarch);
 
   if (!tdep->m68k_ps_type)
     {
@@ -99,7 +99,7 @@ m68k_ps_type (struct gdbarch *gdbarch)
 static struct type *
 m68881_ext_type (struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep_cast<m68k_gdbarch_tdep> (gdbarch);
 
   if (!tdep->m68881_ext_type)
     tdep->m68881_ext_type
@@ -120,7 +120,7 @@ m68881_ext_type (struct gdbarch *gdbarch)
 static struct type *
 m68k_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep_cast<m68k_gdbarch_tdep> (gdbarch);
 
   if (tdep->fpregs_present)
     {
@@ -171,7 +171,7 @@ static const char * const m68k_register_names[] = {
 static const char *
 m68k_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep_cast<m68k_gdbarch_tdep> (gdbarch);
 
   if (regnum < 0 || regnum >= ARRAY_SIZE (m68k_register_names))
     internal_error (__FILE__, __LINE__,
@@ -191,7 +191,7 @@ static int
 m68k_convert_register_p (struct gdbarch *gdbarch,
 			 int regnum, struct type *type)
 {
-  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep_cast<m68k_gdbarch_tdep> (gdbarch);
 
   if (!tdep->fpregs_present)
     return 0;
@@ -300,7 +300,7 @@ m68k_extract_return_value (struct type *type, struct regcache *regcache,
   if (type->code () == TYPE_CODE_PTR && len == 4)
     {
       struct gdbarch *gdbarch = regcache->arch ();
-      m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
+      m68k_gdbarch_tdep *tdep = gdbarch_tdep_cast<m68k_gdbarch_tdep> (gdbarch);
       regcache->raw_read (tdep->pointer_result_regnum, valbuf);
     }
   else if (len <= 4)
@@ -325,7 +325,7 @@ m68k_svr4_extract_return_value (struct type *type, struct regcache *regcache,
 {
   gdb_byte buf[M68K_MAX_REGISTER_SIZE];
   struct gdbarch *gdbarch = regcache->arch ();
-  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep_cast<m68k_gdbarch_tdep> (gdbarch);
 
   if (tdep->float_return && type->code () == TYPE_CODE_FLT)
     {
@@ -348,7 +348,7 @@ m68k_store_return_value (struct type *type, struct regcache *regcache,
   if (type->code () == TYPE_CODE_PTR && len == 4)
     {
       struct gdbarch *gdbarch = regcache->arch ();
-      m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
+      m68k_gdbarch_tdep *tdep = gdbarch_tdep_cast<m68k_gdbarch_tdep> (gdbarch);
       regcache->raw_write (tdep->pointer_result_regnum, valbuf);
       /* gdb historically also set D0 in the SVR4 case.  */
       if (tdep->pointer_result_regnum != M68K_D0_REGNUM)
@@ -371,7 +371,7 @@ m68k_svr4_store_return_value (struct type *type, struct regcache *regcache,
 			      const gdb_byte *valbuf)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep_cast<m68k_gdbarch_tdep> (gdbarch);
 
   if (tdep->float_return && type->code () == TYPE_CODE_FLT)
     {
@@ -391,7 +391,7 @@ m68k_svr4_store_return_value (struct type *type, struct regcache *regcache,
 static int
 m68k_reg_struct_return_p (struct gdbarch *gdbarch, struct type *type)
 {
-  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep_cast<m68k_gdbarch_tdep> (gdbarch);
   enum type_code code = type->code ();
   int len = TYPE_LENGTH (type);
 
@@ -469,7 +469,7 @@ m68k_svr4_return_value (struct gdbarch *gdbarch, struct value *function,
 			gdb_byte *readbuf, const gdb_byte *writebuf)
 {
   enum type_code code = type->code ();
-  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep_cast<m68k_gdbarch_tdep> (gdbarch);
 
   /* Aggregates with a single member are always returned like their
      sole element.  */
@@ -541,7 +541,7 @@ m68k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 		      function_call_return_method return_method,
 		      CORE_ADDR struct_addr)
 {
-  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep_cast<m68k_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   gdb_byte buf[4];
   int i;
@@ -596,7 +596,7 @@ m68k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 static int
 m68k_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int num)
 {
-  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep_cast<m68k_gdbarch_tdep> (gdbarch);
 
   if (num < 8)
     /* d0..7 */
@@ -766,7 +766,7 @@ m68k_analyze_register_saves (struct gdbarch *gdbarch, CORE_ADDR pc,
 			     struct m68k_frame_cache *cache)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep_cast<m68k_gdbarch_tdep> (gdbarch);
 
   if (cache->locals >= 0)
     {
@@ -1058,7 +1058,7 @@ m68k_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
   gdb_byte *buf;
   CORE_ADDR sp, jb_addr;
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep_cast<m68k_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   if (tdep->jb_pc < 0)
@@ -1104,7 +1104,7 @@ m68k_return_in_first_hidden_param_p (struct gdbarch *gdbarch,
 void
 m68k_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep_cast<m68k_gdbarch_tdep> (gdbarch);
 
   /* SVR4 uses a different calling convention.  */
   set_gdbarch_return_value (gdbarch, m68k_svr4_return_value);
@@ -1122,7 +1122,7 @@ m68k_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 static void
 m68k_embedded_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep_cast<m68k_gdbarch_tdep> (gdbarch);
 
   m68k_svr4_init_abi (info, gdbarch);
   tdep->pointer_result_regnum = M68K_D0_REGNUM;
@@ -1237,7 +1237,7 @@ m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
     {
       m68k_gdbarch_tdep *tdep
-	= gdbarch_tdep<m68k_gdbarch_tdep> (best_arch->gdbarch);
+	= gdbarch_tdep_cast<m68k_gdbarch_tdep> (best_arch->gdbarch);
 
       if (flavour != tdep->flavour)
 	continue;
@@ -1339,7 +1339,7 @@ m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 m68k_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
+  m68k_gdbarch_tdep *tdep = gdbarch_tdep_cast<m68k_gdbarch_tdep> (gdbarch);
 
   if (tdep == NULL)
     return;
diff --git a/gdb/mep-tdep.c b/gdb/mep-tdep.c
index d5ba78c6df9..1e6a77af9a8 100644
--- a/gdb/mep-tdep.c
+++ b/gdb/mep-tdep.c
@@ -260,7 +260,7 @@ me_module_register_set (CONFIG_ATTR me_module,
        specifically excluding the generic coprocessor register sets.  */
 
   mep_gdbarch_tdep *tdep
-    = gdbarch_tdep<mep_gdbarch_tdep> (target_gdbarch ());
+    = gdbarch_tdep_cast<mep_gdbarch_tdep> (target_gdbarch ());
   CGEN_CPU_DESC desc = tdep->cpu_desc;
   const CGEN_HW_ENTRY *hw;
 
@@ -856,7 +856,7 @@ current_me_module (void)
   else
     {
       mep_gdbarch_tdep *tdep
-	= gdbarch_tdep<mep_gdbarch_tdep> (target_gdbarch ());
+	= gdbarch_tdep_cast<mep_gdbarch_tdep> (target_gdbarch ());
       return tdep->me_module;
     }
 }
@@ -2391,7 +2391,7 @@ mep_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       mep_gdbarch_tdep *tdep
-	= gdbarch_tdep<mep_gdbarch_tdep> (arches->gdbarch);
+	= gdbarch_tdep_cast<mep_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->me_module == me_module)
 	return arches->gdbarch;
diff --git a/gdb/mips-linux-tdep.c b/gdb/mips-linux-tdep.c
index ca313a28279..b2297f0ab35 100644
--- a/gdb/mips-linux-tdep.c
+++ b/gdb/mips-linux-tdep.c
@@ -1317,7 +1317,7 @@ mips_linux_get_syscall_number (struct gdbarch *gdbarch,
 			       thread_info *thread)
 {
   struct regcache *regcache = get_thread_regcache (thread);
-  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep_cast<mips_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int regsize = register_size (gdbarch, MIPS_V0_REGNUM);
   /* The content of a register */
@@ -1527,7 +1527,7 @@ static void
 mips_linux_init_abi (struct gdbarch_info info,
 		     struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep_cast<mips_gdbarch_tdep> (gdbarch);
   enum mips_abi abi = mips_abi (gdbarch);
   struct tdesc_arch_data *tdesc_data = info.tdesc_data;
 
diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index 98270268584..1fc1a9109f4 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -227,7 +227,7 @@ static const char mips_disassembler_options_n64[] = "gpr-names=64";
 const struct mips_regnum *
 mips_regnum (struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep_cast<mips_gdbarch_tdep> (gdbarch);
   return tdep->regnum;
 }
 
@@ -252,7 +252,7 @@ mips_float_register_p (struct gdbarch *gdbarch, int regnum)
 static bool
 mips_eabi (gdbarch *arch)
 {
-  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (arch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep_cast<mips_gdbarch_tdep> (arch);
   return (tdep->mips_abi == MIPS_ABI_EABI32 \
 	  || tdep->mips_abi == MIPS_ABI_EABI64);
 }
@@ -260,21 +260,21 @@ mips_eabi (gdbarch *arch)
 static int
 mips_last_fp_arg_regnum (gdbarch *arch)
 {
-  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (arch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep_cast<mips_gdbarch_tdep> (arch);
   return tdep->mips_last_fp_arg_regnum;
 }
 
 static int
 mips_last_arg_regnum (gdbarch *arch)
 {
-  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (arch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep_cast<mips_gdbarch_tdep> (arch);
   return tdep->mips_last_arg_regnum;
 }
 
 static enum mips_fpu_type
 mips_get_fpu_type (gdbarch *arch)
 {
-  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (arch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep_cast<mips_gdbarch_tdep> (arch);
   return tdep->mips_fpu_type;
 }
 
@@ -282,14 +282,14 @@ mips_get_fpu_type (gdbarch *arch)
 enum mips_abi
 mips_abi (struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep_cast<mips_gdbarch_tdep> (gdbarch);
   return tdep->mips_abi;
 }
 
 int
 mips_isa_regsize (struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep_cast<mips_gdbarch_tdep> (gdbarch);
 
   /* If we know how big the registers are, use that size.  */
   if (tdep->register_size_valid_p)
@@ -335,7 +335,7 @@ mips_abi_regsize (struct gdbarch *gdbarch)
 static int
 is_mips16_isa (struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep_cast<mips_gdbarch_tdep> (gdbarch);
   return tdep->mips_isa == ISA_MIPS16;
 }
 
@@ -344,7 +344,7 @@ is_mips16_isa (struct gdbarch *gdbarch)
 static int
 is_micromips_isa (struct gdbarch *gdbarch)
 {
-  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep_cast<mips_gdbarch_tdep> (gdbarch);
   return tdep->mips_isa == ISA_MICROMIPS;
 }
 
@@ -636,7 +636,7 @@ static const char * const mips_linux_reg_names[NUM_MIPS_PROCESSOR_REGS] = {
 static const char *
 mips_register_name (struct gdbarch *gdbarch, int regno)
 {
-  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep_cast<mips_gdbarch_tdep> (gdbarch);
   /* GPR names for all ABIs other than n32/n64.  */
   static const char *mips_gpr_names[] = {
     "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
@@ -777,7 +777,7 @@ mips_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
   else if (register_size (gdbarch, rawnum) >
 	   register_size (gdbarch, cookednum))
     {
-      mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
+      mips_gdbarch_tdep *tdep = gdbarch_tdep_cast<mips_gdbarch_tdep> (gdbarch);
 
       if (tdep->mips64_transfers_32bit_regs_p)
 	return regcache->raw_read_part (rawnum, 0, 4, buf);
@@ -810,7 +810,7 @@ mips_pseudo_register_write (struct gdbarch *gdbarch,
   else if (register_size (gdbarch, rawnum) >
 	   register_size (gdbarch, cookednum))
     {
-      mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
+      mips_gdbarch_tdep *tdep = gdbarch_tdep_cast<mips_gdbarch_tdep> (gdbarch);
 
       if (tdep->mips64_transfers_32bit_regs_p)
 	regcache->raw_write_part (rawnum, 0, 4, buf);
@@ -855,7 +855,7 @@ mips_ax_pseudo_register_push_stack (struct gdbarch *gdbarch,
       if (register_size (gdbarch, rawnum) > register_size (gdbarch, reg))
 	{
 	  mips_gdbarch_tdep *tdep
-	    = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
+	    = gdbarch_tdep_cast<mips_gdbarch_tdep> (gdbarch);
 
 	  if (!tdep->mips64_transfers_32bit_regs_p
 	      || gdbarch_byte_order (gdbarch) != BFD_ENDIAN_BIG)
@@ -1059,7 +1059,7 @@ mips_register_type (struct gdbarch *gdbarch, int regnum)
   else
     {
       int rawnum = regnum - gdbarch_num_regs (gdbarch);
-      mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
+      mips_gdbarch_tdep *tdep = gdbarch_tdep_cast<mips_gdbarch_tdep> (gdbarch);
 
       /* The cooked or ABI registers.  These are sized according to
 	 the ABI (with a few complications).  */
@@ -1191,7 +1191,7 @@ show_mask_address (struct ui_file *file, int from_tty,
       else
 	{
 	  mips_gdbarch_tdep *tdep
-	    = gdbarch_tdep<mips_gdbarch_tdep> (target_gdbarch ());
+	    = gdbarch_tdep_cast<mips_gdbarch_tdep> (target_gdbarch ());
 
 	  if (mips_mask_address_p (tdep))
 	    additional_text = _(" (currently \"on\")");
@@ -1727,7 +1727,7 @@ mips32_next_pc (struct regcache *regcache, CORE_ADDR pc)
 	    case 12:            /* SYSCALL */
 	      {
 		mips_gdbarch_tdep *tdep
-		  = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
+		  = gdbarch_tdep_cast<mips_gdbarch_tdep> (gdbarch);
 
 		if (tdep->syscall_next_pc != NULL)
 		  pc = tdep->syscall_next_pc (get_current_frame ());
@@ -1938,7 +1938,7 @@ micromips_next_pc (struct regcache *regcache, CORE_ADDR pc)
 		case 0x22d: /* SYSCALL:  000000 1000101101 111100 */
 		  {
 		    mips_gdbarch_tdep *tdep
-		      = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
+		      = gdbarch_tdep_cast<mips_gdbarch_tdep> (gdbarch);
 
 		    if (tdep->syscall_next_pc != NULL)
 		      pc = tdep->syscall_next_pc (get_current_frame ());
@@ -3901,7 +3901,7 @@ mips_stub_frame_base_sniffer (struct frame_info *this_frame)
 static CORE_ADDR
 mips_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
-  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep_cast<mips_gdbarch_tdep> (gdbarch);
 
   if (mips_mask_address_p (tdep) && (((ULONGEST) addr) >> 32 == 0xffffffffUL))
     /* This hack is a work-around for existing boards using PMON, the
@@ -4804,7 +4804,7 @@ mips_eabi_return_value (struct gdbarch *gdbarch, struct value *function,
 			struct type *type, struct regcache *regcache,
 			gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep_cast<mips_gdbarch_tdep> (gdbarch);
   int fp_return_type = 0;
   int offset, regnum, xfer;
 
@@ -5195,7 +5195,7 @@ mips_n32n64_return_value (struct gdbarch *gdbarch, struct value *function,
 			  struct type *type, struct regcache *regcache,
 			  gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep_cast<mips_gdbarch_tdep> (gdbarch);
 
   /* From MIPSpro N32 ABI Handbook, Document Number: 007-2816-004
 
@@ -5704,7 +5704,7 @@ mips_o32_return_value (struct gdbarch *gdbarch, struct value *function,
 {
   CORE_ADDR func_addr = function ? find_function_addr (function, NULL) : 0;
   int mips16 = mips_pc_is_mips16 (gdbarch, func_addr);
-  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep_cast<mips_gdbarch_tdep> (gdbarch);
   enum mips_fval_reg fval_reg;
 
   fval_reg = readbuf ? mips16 ? mips_fval_gpr : mips_fval_fpr : mips_fval_both;
@@ -8101,7 +8101,7 @@ mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   else if (arches != NULL)
     {
       mips_gdbarch_tdep *tdep
-	= gdbarch_tdep<mips_gdbarch_tdep> (arches->gdbarch);
+	= gdbarch_tdep_cast<mips_gdbarch_tdep> (arches->gdbarch);
       elf_flags = tdep->elf_flags;
     }
   else
@@ -8142,7 +8142,7 @@ mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   if (found_abi == MIPS_ABI_UNKNOWN && info.abfd == NULL && arches != NULL)
     {
       mips_gdbarch_tdep *tdep
-	= gdbarch_tdep<mips_gdbarch_tdep> (arches->gdbarch);
+	= gdbarch_tdep_cast<mips_gdbarch_tdep> (arches->gdbarch);
       found_abi = tdep->found_abi;
     }
 
@@ -8459,7 +8459,7 @@ mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       mips_gdbarch_tdep *tdep
-	= gdbarch_tdep<mips_gdbarch_tdep> (arches->gdbarch);
+	= gdbarch_tdep_cast<mips_gdbarch_tdep> (arches->gdbarch);
 
       /* MIPS needs to be pedantic about which ABI and the compressed
 	 ISA variation the object is using.  */
@@ -8917,7 +8917,7 @@ mips_fpu_type_str (enum mips_fpu_type fpu_type)
 static void
 mips_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  mips_gdbarch_tdep *tdep = gdbarch_tdep<mips_gdbarch_tdep> (gdbarch);
+  mips_gdbarch_tdep *tdep = gdbarch_tdep_cast<mips_gdbarch_tdep> (gdbarch);
   if (tdep != NULL)
     {
       int ef_mips_arch;
diff --git a/gdb/mn10300-tdep.c b/gdb/mn10300-tdep.c
index 22511d894d4..817aba8a278 100644
--- a/gdb/mn10300-tdep.c
+++ b/gdb/mn10300-tdep.c
@@ -1412,7 +1412,7 @@ mn10300_gdbarch_init (struct gdbarch_info info,
 static void
 mn10300_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  mn10300_gdbarch_tdep *tdep = gdbarch_tdep<mn10300_gdbarch_tdep> (gdbarch);
+  mn10300_gdbarch_tdep *tdep = gdbarch_tdep_cast<mn10300_gdbarch_tdep> (gdbarch);
   gdb_printf (file, "mn10300_dump_tdep: am33_mode = %d\n",
 	      tdep->am33_mode);
 }
diff --git a/gdb/mn10300-tdep.h b/gdb/mn10300-tdep.h
index 87b861ead90..3e1a4873150 100644
--- a/gdb/mn10300-tdep.h
+++ b/gdb/mn10300-tdep.h
@@ -84,7 +84,7 @@ struct mn10300_gdbarch_tdep : gdbarch_tdep
 static inline int
 get_am33_mode (gdbarch *arch)
 {
-  mn10300_gdbarch_tdep *tdep = gdbarch_tdep<mn10300_gdbarch_tdep> (arch);
+  mn10300_gdbarch_tdep *tdep = gdbarch_tdep_cast<mn10300_gdbarch_tdep> (arch);
   return tdep->am33_mode;
 }
 
diff --git a/gdb/msp430-tdep.c b/gdb/msp430-tdep.c
index 4ae8b3d5626..4334485db8b 100644
--- a/gdb/msp430-tdep.c
+++ b/gdb/msp430-tdep.c
@@ -341,7 +341,7 @@ msp430_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc,
   int rn;
   pv_t reg[MSP430_NUM_TOTAL_REGS];
   CORE_ADDR after_last_frame_setup_insn = start_pc;
-  msp430_gdbarch_tdep *tdep = gdbarch_tdep<msp430_gdbarch_tdep> (gdbarch);
+  msp430_gdbarch_tdep *tdep = gdbarch_tdep_cast<msp430_gdbarch_tdep> (gdbarch);
   int code_model = tdep->code_model;
   int sz;
 
@@ -570,7 +570,7 @@ msp430_return_value (struct gdbarch *gdbarch,
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   LONGEST valtype_len = TYPE_LENGTH (valtype);
-  msp430_gdbarch_tdep *tdep = gdbarch_tdep<msp430_gdbarch_tdep> (gdbarch);
+  msp430_gdbarch_tdep *tdep = gdbarch_tdep_cast<msp430_gdbarch_tdep> (gdbarch);
   int code_model = tdep->code_model;
 
   if (TYPE_LENGTH (valtype) > 8
@@ -651,7 +651,7 @@ msp430_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   int write_pass;
   int sp_off = 0;
   CORE_ADDR cfa;
-  msp430_gdbarch_tdep *tdep = gdbarch_tdep<msp430_gdbarch_tdep> (gdbarch);
+  msp430_gdbarch_tdep *tdep = gdbarch_tdep_cast<msp430_gdbarch_tdep> (gdbarch);
   int code_model = tdep->code_model;
 
   struct type *func_type = value_type (function);
@@ -814,7 +814,7 @@ msp430_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
 
   stub_name = bms.minsym->linkage_name ();
 
-  msp430_gdbarch_tdep *tdep = gdbarch_tdep<msp430_gdbarch_tdep> (gdbarch);
+  msp430_gdbarch_tdep *tdep = gdbarch_tdep_cast<msp430_gdbarch_tdep> (gdbarch);
   if (tdep->code_model == MSP_SMALL_CODE_MODEL
       && msp430_in_return_stub (gdbarch, pc, stub_name))
     {
@@ -877,7 +877,7 @@ msp430_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 	  if (ca && gdbarch_bfd_arch_info (ca)->arch == bfd_arch_msp430)
 	    {
 	      msp430_gdbarch_tdep *ca_tdep
-		= gdbarch_tdep<msp430_gdbarch_tdep> (ca);
+		= gdbarch_tdep_cast<msp430_gdbarch_tdep> (ca);
 
 	      elf_flags = ca_tdep->elf_flags;
 	      isa = ca_tdep->isa;
@@ -904,7 +904,7 @@ msp430_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       msp430_gdbarch_tdep *candidate_tdep
-	= gdbarch_tdep<msp430_gdbarch_tdep> (arches->gdbarch);
+	= gdbarch_tdep_cast<msp430_gdbarch_tdep> (arches->gdbarch);
 
       if (candidate_tdep->elf_flags != elf_flags
 	  || candidate_tdep->isa != isa
diff --git a/gdb/nds32-tdep.c b/gdb/nds32-tdep.c
index 11bfd2d1f54..0c10ea202e8 100644
--- a/gdb/nds32-tdep.c
+++ b/gdb/nds32-tdep.c
@@ -289,7 +289,7 @@ typedef BP_MANIPULATION (nds32_break_insn) nds32_breakpoint;
 static int
 nds32_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int num)
 {
-  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep_cast<nds32_gdbarch_tdep> (gdbarch);
   const int FSR = 38;
   const int FDR = FSR + 32;
 
@@ -432,7 +432,7 @@ nds32_pseudo_register_read (struct gdbarch *gdbarch,
 			    readable_regcache *regcache, int regnum,
 			    gdb_byte *buf)
 {
-  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep_cast<nds32_gdbarch_tdep> (gdbarch);
   gdb_byte reg_buf[8];
   int offset, fdr_regnum;
   enum register_status status;
@@ -471,7 +471,7 @@ nds32_pseudo_register_write (struct gdbarch *gdbarch,
 			     struct regcache *regcache, int regnum,
 			     const gdb_byte *buf)
 {
-  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep_cast<nds32_gdbarch_tdep> (gdbarch);
   gdb_byte reg_buf[8];
   int offset, fdr_regnum;
 
@@ -608,7 +608,7 @@ static CORE_ADDR
 nds32_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
 			CORE_ADDR limit_pc, struct nds32_frame_cache *cache)
 {
-  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep_cast<nds32_gdbarch_tdep> (gdbarch);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   /* Current scanning status.  */
   int in_prologue_bb = 0;
@@ -1169,7 +1169,7 @@ static int
 nds32_analyze_epilogue (struct gdbarch *gdbarch, CORE_ADDR pc,
 			struct nds32_frame_cache *cache)
 {
-  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep_cast<nds32_gdbarch_tdep> (gdbarch);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   CORE_ADDR limit_pc;
   uint32_t insn, insn_len;
@@ -1220,7 +1220,7 @@ nds32_analyze_epilogue (struct gdbarch *gdbarch, CORE_ADDR pc,
 static int
 nds32_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
-  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep_cast<nds32_gdbarch_tdep> (gdbarch);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   int insn_type = INSN_NORMAL;
   int ret_found = 0;
@@ -1424,7 +1424,7 @@ nds32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   int i;
   ULONGEST regval;
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep_cast<nds32_gdbarch_tdep> (gdbarch);
   struct type *func_type = value_type (function);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   int abi_split = nds32_abi_split (tdep->elf_abi);
@@ -1652,7 +1652,7 @@ nds32_extract_return_value (struct gdbarch *gdbarch, struct type *type,
 			    struct regcache *regcache, gdb_byte *valbuf)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep_cast<nds32_gdbarch_tdep> (gdbarch);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   int calling_use_fpr;
   int len;
@@ -1742,7 +1742,7 @@ nds32_store_return_value (struct gdbarch *gdbarch, struct type *type,
 			  struct regcache *regcache, const gdb_byte *valbuf)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  nds32_gdbarch_tdep *tdep = gdbarch_tdep<nds32_gdbarch_tdep> (gdbarch);
+  nds32_gdbarch_tdep *tdep = gdbarch_tdep_cast<nds32_gdbarch_tdep> (gdbarch);
   int abi_use_fpr = nds32_abi_use_fpr (tdep->elf_abi);
   int calling_use_fpr;
   int len;
@@ -1965,7 +1965,7 @@ nds32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
     {
       nds32_gdbarch_tdep *idep
-	= gdbarch_tdep<nds32_gdbarch_tdep> (best_arch->gdbarch);
+	= gdbarch_tdep_cast<nds32_gdbarch_tdep> (best_arch->gdbarch);
 
       if (idep->elf_abi != elf_abi)
 	continue;
diff --git a/gdb/nios2-linux-tdep.c b/gdb/nios2-linux-tdep.c
index da69638b20b..415a950a1bb 100644
--- a/gdb/nios2-linux-tdep.c
+++ b/gdb/nios2-linux-tdep.c
@@ -217,7 +217,7 @@ nios2_linux_is_kernel_helper (CORE_ADDR pc)
 static void
 nios2_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  nios2_gdbarch_tdep *tdep = gdbarch_tdep<nios2_gdbarch_tdep> (gdbarch);
+  nios2_gdbarch_tdep *tdep = gdbarch_tdep_cast<nios2_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/nios2-tdep.c b/gdb/nios2-tdep.c
index 0bad229b44a..e612c810b8d 100644
--- a/gdb/nios2-tdep.c
+++ b/gdb/nios2-tdep.c
@@ -2098,7 +2098,7 @@ static CORE_ADDR
 nios2_get_next_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  nios2_gdbarch_tdep *tdep = gdbarch_tdep<nios2_gdbarch_tdep> (gdbarch);
+  nios2_gdbarch_tdep *tdep = gdbarch_tdep_cast<nios2_gdbarch_tdep> (gdbarch);
   unsigned long mach = gdbarch_bfd_arch_info (gdbarch)->mach;
   unsigned int insn;
   const struct nios2_opcode *op = nios2_fetch_insn (gdbarch, pc, &insn);
@@ -2221,7 +2221,7 @@ static int
 nios2_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  nios2_gdbarch_tdep *tdep = gdbarch_tdep<nios2_gdbarch_tdep> (gdbarch);
+  nios2_gdbarch_tdep *tdep = gdbarch_tdep_cast<nios2_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR jb_addr = get_frame_register_unsigned (frame, NIOS2_R4_REGNUM);
   gdb_byte buf[4];
diff --git a/gdb/or1k-tdep.c b/gdb/or1k-tdep.c
index 4699b755d42..e40da6560c2 100644
--- a/gdb/or1k-tdep.c
+++ b/gdb/or1k-tdep.c
@@ -248,7 +248,7 @@ or1k_return_value (struct gdbarch *gdbarch, struct value *functype,
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   enum type_code rv_type = valtype->code ();
   unsigned int rv_size = TYPE_LENGTH (valtype);
-  or1k_gdbarch_tdep *tdep = gdbarch_tdep<or1k_gdbarch_tdep> (gdbarch);
+  or1k_gdbarch_tdep *tdep = gdbarch_tdep_cast<or1k_gdbarch_tdep> (gdbarch);
   int bpw = tdep->bytes_per_word;
 
   /* Deal with struct/union as addresses.  If an array won't fit in a
@@ -353,7 +353,7 @@ or1k_delay_slot_p (struct gdbarch *gdbarch, CORE_ADDR pc)
 {
   const CGEN_INSN *insn;
   CGEN_FIELDS tmp_fields;
-  or1k_gdbarch_tdep *tdep = gdbarch_tdep<or1k_gdbarch_tdep> (gdbarch);
+  or1k_gdbarch_tdep *tdep = gdbarch_tdep_cast<or1k_gdbarch_tdep> (gdbarch);
 
   insn = cgen_lookup_insn (tdep->gdb_cgen_cpu_desc,
 			   NULL,
@@ -635,7 +635,7 @@ or1k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   int heap_offset = 0;
   CORE_ADDR heap_sp = sp - 128;
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  or1k_gdbarch_tdep *tdep = gdbarch_tdep<or1k_gdbarch_tdep> (gdbarch);
+  or1k_gdbarch_tdep *tdep = gdbarch_tdep_cast<or1k_gdbarch_tdep> (gdbarch);
   int bpa = tdep->bytes_per_address;
   int bpw = tdep->bytes_per_word;
   struct type *func_type = value_type (function);
@@ -1273,7 +1273,7 @@ or1k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 or1k_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  or1k_gdbarch_tdep *tdep = gdbarch_tdep<or1k_gdbarch_tdep> (gdbarch);
+  or1k_gdbarch_tdep *tdep = gdbarch_tdep_cast<or1k_gdbarch_tdep> (gdbarch);
 
   if (NULL == tdep)
     return; /* Nothing to report */
diff --git a/gdb/ppc-fbsd-nat.c b/gdb/ppc-fbsd-nat.c
index d0a5778e2d3..af0fda43a5a 100644
--- a/gdb/ppc-fbsd-nat.c
+++ b/gdb/ppc-fbsd-nat.c
@@ -100,7 +100,7 @@ fill_fpregset (const struct regcache *regcache,
 static int
 getfpregs_supplies (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
 	 point registers.  Traditionally, GDB's register set has still
@@ -185,7 +185,7 @@ static int
 ppcfbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int i, regnum;
 
   /* The stack pointer shouldn't be zero.  */
diff --git a/gdb/ppc-fbsd-tdep.c b/gdb/ppc-fbsd-tdep.c
index f5b482921a7..56854f4cf7a 100644
--- a/gdb/ppc-fbsd-tdep.c
+++ b/gdb/ppc-fbsd-tdep.c
@@ -126,7 +126,7 @@ ppcfbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				      void *cb_data,
 				      const struct regcache *regcache)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   if (tdep->wordsize == 4)
     cb (".reg", 148, 148, &ppc32_fbsd_gregset, NULL, cb_data);
@@ -200,7 +200,7 @@ static struct trad_frame_cache *
 ppcfbsd_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   struct trad_frame_cache *cache;
   CORE_ADDR addr, base, func;
   gdb_byte buf[PPC_INSN_SIZE];
@@ -287,7 +287,7 @@ static CORE_ADDR
 ppcfbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 				  CORE_ADDR lm_addr, CORE_ADDR offset)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   struct regcache *regcache;
   int tp_offset, tp_regnum;
 
@@ -319,7 +319,7 @@ ppcfbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
 static void
 ppcfbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support. */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c
index de4158c411a..d3bce1c4372 100644
--- a/gdb/ppc-linux-nat.c
+++ b/gdb/ppc-linux-nat.c
@@ -649,7 +649,7 @@ static int
 ppc_register_u_addr (struct gdbarch *gdbarch, int regno)
 {
   int u_addr = -1;
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<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 +802,7 @@ static void
 fetch_spe_register (struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   struct gdb_evrregset_t evrregs;
 
   gdb_assert (sizeof (evrregs.evr[0])
@@ -911,7 +911,7 @@ static void
 fetch_register (struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<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;
@@ -1156,7 +1156,7 @@ static void
 fetch_gp_regs (struct regcache *regcache, int tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   if (have_ptrace_getsetregs)
@@ -1208,7 +1208,7 @@ static void
 fetch_fp_regs (struct regcache *regcache, int tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   if (have_ptrace_getsetfpregs)
@@ -1226,7 +1226,7 @@ static void
 fetch_ppc_registers (struct regcache *regcache, int tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   fetch_gp_regs (regcache, tid);
   if (tdep->ppc_fp0_regnum >= 0)
@@ -1425,7 +1425,7 @@ static void
 store_spe_register (const struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   struct gdb_evrregset_t evrregs;
 
   gdb_assert (sizeof (evrregs.evr[0])
@@ -1477,7 +1477,7 @@ static void
 store_register (const struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<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;
@@ -1718,7 +1718,7 @@ static void
 store_gp_regs (const struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   if (have_ptrace_getsetregs)
@@ -1780,7 +1780,7 @@ static void
 store_fp_regs (const struct regcache *regcache, int tid, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   if (have_ptrace_getsetfpregs)
@@ -1798,7 +1798,7 @@ static void
 store_ppc_registers (const struct regcache *regcache, int tid)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
  
   store_gp_regs (regcache, tid, -1);
   if (tdep->ppc_fp0_regnum >= 0)
diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c
index beef4bd393c..8a368feb6b0 100644
--- a/gdb/ppc-linux-tdep.c
+++ b/gdb/ppc-linux-tdep.c
@@ -332,7 +332,7 @@ ppc_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
 {
   unsigned int insnbuf[POWERPC32_PLT_CHECK_LEN];
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR target = 0;
   int scan_limit, i;
@@ -898,7 +898,7 @@ ppc_linux_vsxregset (void)
 const struct regset *
 ppc_linux_cgprregset (struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   if (tdep->wordsize == 4)
     {
@@ -938,7 +938,7 @@ ppc_linux_collect_core_cpgrregset (const struct regset *regset,
 				   int regnum, void *buf, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   const struct regset *cgprregset = ppc_linux_cgprregset (gdbarch);
 
@@ -985,7 +985,7 @@ ppc_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					void *cb_data,
 					const struct regcache *regcache)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int have_altivec = tdep->ppc_vr0_regnum != -1;
   int have_vsx = tdep->ppc_vsr0_upper_regnum != -1;
   int have_ppr = tdep->ppc_ppr_regnum != -1;
@@ -1170,7 +1170,7 @@ ppc_linux_sigtramp_cache (struct frame_info *this_frame,
   CORE_ADDR fpregs;
   int i;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   base = get_frame_register_unsigned (this_frame,
@@ -1341,7 +1341,7 @@ ppc_linux_get_syscall_number (struct gdbarch *gdbarch,
 			      thread_info *thread)
 {
   struct regcache *regcache = get_thread_regcache (thread);
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   /* Make sure we're in a 32- or 64-bit machine */
@@ -1419,7 +1419,7 @@ static int
 ppc_linux_syscall_record (struct regcache *regcache)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   ULONGEST scnum;
   enum gdb_syscall syscall_gdb;
   int ret;
@@ -1509,7 +1509,7 @@ ppc_linux_record_signal (struct gdbarch *gdbarch, struct regcache *regcache,
   const int SIGNAL_FRAMESIZE = 128;
   const int sizeof_rt_sigframe = 1440 * 2 + 8 * 2 + 4 * 6 + 8 + 8 + 128 + 512;
   ULONGEST sp;
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   for (i = 3; i <= 12; i++)
@@ -2044,7 +2044,7 @@ static void
 ppc_linux_init_abi (struct gdbarch_info info,
 		    struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   struct tdesc_arch_data *tdesc_data = info.tdesc_data;
   static const char *const stap_integer_prefixes[] = { "i", NULL };
   static const char *const stap_register_indirection_prefixes[] = { "(",
diff --git a/gdb/ppc-netbsd-nat.c b/gdb/ppc-netbsd-nat.c
index 91f18fbb83f..fa1df0bc265 100644
--- a/gdb/ppc-netbsd-nat.c
+++ b/gdb/ppc-netbsd-nat.c
@@ -52,7 +52,7 @@ static ppc_nbsd_nat_target the_ppc_nbsd_nat_target;
 static int
 getregs_supplies (struct gdbarch *gdbarch, int regnum)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   return ((regnum >= tdep->ppc_gp0_regnum
 	   && regnum < tdep->ppc_gp0_regnum + ppc_num_gprs)
@@ -68,7 +68,7 @@ getregs_supplies (struct gdbarch *gdbarch, int regnum)
 static int
 getfpregs_supplies (struct gdbarch *gdbarch, int regnum)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
      point registers.  Traditionally, GDB's register set has still
@@ -159,7 +159,7 @@ ppcnbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
   struct switchframe sf;
   struct callframe cf;
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int i;
 
   /* The stack pointer shouldn't be zero.  */
diff --git a/gdb/ppc-netbsd-tdep.c b/gdb/ppc-netbsd-tdep.c
index d8dc494979a..2ff0aef4d33 100644
--- a/gdb/ppc-netbsd-tdep.c
+++ b/gdb/ppc-netbsd-tdep.c
@@ -102,7 +102,7 @@ ppcnbsd_sigtramp_cache_init (const struct tramp_frame *self,
 			     CORE_ADDR func)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   CORE_ADDR addr, base;
   int i;
 
diff --git a/gdb/ppc-obsd-nat.c b/gdb/ppc-obsd-nat.c
index e480f19dc73..176d4245585 100644
--- a/gdb/ppc-obsd-nat.c
+++ b/gdb/ppc-obsd-nat.c
@@ -54,7 +54,7 @@ static ppc_obsd_nat_target the_ppc_obsd_nat_target;
 static int
 getfpregs_supplies (struct gdbarch *gdbarch, int regnum)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
      point registers.  Traditionally, GDB's register set has still
@@ -154,7 +154,7 @@ static int
 ppcobsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   struct switchframe sf;
   struct callframe cf;
   int i, regnum;
diff --git a/gdb/ppc-obsd-tdep.c b/gdb/ppc-obsd-tdep.c
index 90fb5e3a399..39138b5d387 100644
--- a/gdb/ppc-obsd-tdep.c
+++ b/gdb/ppc-obsd-tdep.c
@@ -161,7 +161,7 @@ static struct trad_frame_cache *
 ppcobsd_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct trad_frame_cache *cache;
   CORE_ADDR addr, base, func;
diff --git a/gdb/ppc-sysv-tdep.c b/gdb/ppc-sysv-tdep.c
index 1fe81b95f6c..b0e08adeb64 100644
--- a/gdb/ppc-sysv-tdep.c
+++ b/gdb/ppc-sysv-tdep.c
@@ -65,7 +65,7 @@ ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 			      function_call_return_method return_method,
 			      CORE_ADDR struct_addr)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int opencl_abi = ppc_sysv_use_opencl_abi (value_type (function));
   ULONGEST saved_sp;
@@ -602,7 +602,7 @@ get_decimal_float_return_value (struct gdbarch *gdbarch, struct type *valtype,
 				struct regcache *regcache, gdb_byte *readbuf,
 				const gdb_byte *writebuf)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   gdb_assert (valtype->code () == TYPE_CODE_DECFLOAT);
 
@@ -680,7 +680,7 @@ do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *func_type,
 			  gdb_byte *readbuf, const gdb_byte *writebuf,
 			  int broken_gcc)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int opencl_abi = func_type? ppc_sysv_use_opencl_abi (func_type) : 0;
 
@@ -1267,7 +1267,7 @@ ppc64_sysv_abi_push_val (struct gdbarch *gdbarch,
 			 const bfd_byte *val, int len, int align,
 			 struct ppc64_sysv_argpos *argpos)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int offset = 0;
 
   /* Enforce alignment of stack location, if requested.  */
@@ -1317,7 +1317,7 @@ static void
 ppc64_sysv_abi_push_integer (struct gdbarch *gdbarch, ULONGEST val,
 			     struct ppc64_sysv_argpos *argpos)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   gdb_byte buf[PPC_MAX_REGISTER_SIZE];
 
@@ -1335,7 +1335,7 @@ ppc64_sysv_abi_push_freg (struct gdbarch *gdbarch,
 			  struct type *type, const bfd_byte *val,
 			  struct ppc64_sysv_argpos *argpos)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   if (tdep->soft_float)
     return;
 
@@ -1420,7 +1420,7 @@ static void
 ppc64_sysv_abi_push_vreg (struct gdbarch *gdbarch, const bfd_byte *val,
 			  struct ppc64_sysv_argpos *argpos)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   if (argpos->regcache && argpos->vreg <= 13)
     argpos->regcache->cooked_write (tdep->ppc_vr0_regnum + argpos->vreg, val);
@@ -1436,7 +1436,7 @@ ppc64_sysv_abi_push_param (struct gdbarch *gdbarch,
 			   struct type *type, const bfd_byte *val,
 			   struct ppc64_sysv_argpos *argpos)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   if (type->code () == TYPE_CODE_FLT
       && TYPE_LENGTH (type) == 16
@@ -1589,7 +1589,7 @@ ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch,
 				CORE_ADDR struct_addr)
 {
   CORE_ADDR func_addr = find_function_addr (function, NULL);
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int opencl_abi = ppc_sysv_use_opencl_abi (value_type (function));
   ULONGEST back_chain;
@@ -1783,7 +1783,7 @@ ppc64_sysv_abi_return_value_base (struct gdbarch *gdbarch, struct type *valtype,
 				  struct regcache *regcache, gdb_byte *readbuf,
 				  const gdb_byte *writebuf, int index)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   /* Integers live in GPRs starting at r3.  */
   if ((valtype->code () == TYPE_CODE_INT
@@ -1972,7 +1972,7 @@ ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct value *function,
 			     struct type *valtype, struct regcache *regcache,
 			     gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   struct type *func_type = function ? value_type (function) : NULL;
   int opencl_abi = func_type? ppc_sysv_use_opencl_abi (func_type) : 0;
   struct type *eltype;
diff --git a/gdb/ppc64-tdep.c b/gdb/ppc64-tdep.c
index 0437ca7e3f3..2f7f1a97b1c 100644
--- a/gdb/ppc64-tdep.c
+++ b/gdb/ppc64-tdep.c
@@ -89,7 +89,7 @@ ppc64_plt_entry_point (struct frame_info *frame, CORE_ADDR plt_off)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   CORE_ADDR tocp;
 
   if (execution_direction == EXEC_REVERSE)
diff --git a/gdb/riscv-linux-tdep.c b/gdb/riscv-linux-tdep.c
index 5bda2e5c824..4e5902fdd95 100644
--- a/gdb/riscv-linux-tdep.c
+++ b/gdb/riscv-linux-tdep.c
@@ -179,7 +179,7 @@ riscv_linux_syscall_next_pc (struct frame_info *frame)
 static void
 riscv_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep_cast<riscv_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
index 2d41be96b20..c713724a5bb 100644
--- a/gdb/riscv-tdep.c
+++ b/gdb/riscv-tdep.c
@@ -733,7 +733,7 @@ show_riscv_debug_variable (struct ui_file *file, int from_tty,
 int
 riscv_isa_xlen (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep_cast<riscv_gdbarch_tdep> (gdbarch);
   return tdep->isa_features.xlen;
 }
 
@@ -742,7 +742,7 @@ riscv_isa_xlen (struct gdbarch *gdbarch)
 int
 riscv_abi_xlen (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep_cast<riscv_gdbarch_tdep> (gdbarch);
   return tdep->abi_features.xlen;
 }
 
@@ -751,7 +751,7 @@ riscv_abi_xlen (struct gdbarch *gdbarch)
 int
 riscv_isa_flen (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep_cast<riscv_gdbarch_tdep> (gdbarch);
   return tdep->isa_features.flen;
 }
 
@@ -760,7 +760,7 @@ riscv_isa_flen (struct gdbarch *gdbarch)
 int
 riscv_abi_flen (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep_cast<riscv_gdbarch_tdep> (gdbarch);
   return tdep->abi_features.flen;
 }
 
@@ -769,7 +769,7 @@ riscv_abi_flen (struct gdbarch *gdbarch)
 bool
 riscv_abi_embedded (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep_cast<riscv_gdbarch_tdep> (gdbarch);
   return tdep->abi_features.embedded;
 }
 
@@ -786,7 +786,7 @@ riscv_has_fp_regs (struct gdbarch *gdbarch)
 static bool
 riscv_has_fp_abi (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep_cast<riscv_gdbarch_tdep> (gdbarch);
   return tdep->abi_features.flen > 0;
 }
 
@@ -910,7 +910,7 @@ riscv_register_name (struct gdbarch *gdbarch, int regnum)
      will show up in 'info register all'.  Unless, we identify the
      duplicate copies of these registers (in riscv_tdesc_unknown_reg) and
      then hide the registers here by giving them no name.  */
-  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep_cast<riscv_gdbarch_tdep> (gdbarch);
   if (tdep->duplicate_fflags_regnum == regnum)
     return NULL;
   if (tdep->duplicate_frm_regnum == regnum)
@@ -938,7 +938,7 @@ riscv_register_name (struct gdbarch *gdbarch, int regnum)
 static struct type *
 riscv_fpreg_d_type (struct gdbarch *gdbarch)
 {
-  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep_cast<riscv_gdbarch_tdep> (gdbarch);
 
   if (tdep->riscv_fpreg_d_type == nullptr)
     {
@@ -1260,7 +1260,7 @@ riscv_is_regnum_a_named_csr (int regnum)
 static bool
 riscv_is_unknown_csr (struct gdbarch *gdbarch, int regnum)
 {
-  riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
+  riscv_gdbarch_tdep *tdep = gdbarch_tdep_cast<riscv_gdbarch_tdep> (gdbarch);
   return (regnum >= tdep->unknown_csrs_first_regnum
 	  && regnum < (tdep->unknown_csrs_first_regnum
 		       + tdep->unknown_csrs_count));
@@ -3600,7 +3600,7 @@ riscv_tdesc_unknown_reg (struct gdbarch *gdbarch, tdesc_feature *feature,
      record their register numbers here.  */
   if (strcmp (tdesc_feature_name (feature), riscv_freg_feature.name ()) == 0)
     {
-      riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
+      riscv_gdbarch_tdep *tdep = gdbarch_tdep_cast<riscv_gdbarch_tdep> (gdbarch);
       int *regnum_ptr = nullptr;
 
       if (strcmp (reg_name, "fflags") == 0)
@@ -3631,7 +3631,7 @@ riscv_tdesc_unknown_reg (struct gdbarch *gdbarch, tdesc_feature *feature,
      about register groups in riscv_register_reggroup_p.  */
   if (strcmp (tdesc_feature_name (feature), riscv_csr_feature.name ()) == 0)
     {
-      riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
+      riscv_gdbarch_tdep *tdep = gdbarch_tdep_cast<riscv_gdbarch_tdep> (gdbarch);
       if (tdep->unknown_csrs_first_regnum == -1)
 	tdep->unknown_csrs_first_regnum = possible_regnum;
       gdb_assert (tdep->unknown_csrs_first_regnum
@@ -3733,7 +3733,7 @@ riscv_gdbarch_init (struct gdbarch_info info,
 	 we are looking for.  If it doesn't then we can't reuse this
 	 gdbarch.  */
       riscv_gdbarch_tdep *other_tdep
-	= gdbarch_tdep<riscv_gdbarch_tdep> (arches->gdbarch);
+	= gdbarch_tdep_cast<riscv_gdbarch_tdep> (arches->gdbarch);
 
       if (other_tdep->isa_features != features
 	  || other_tdep->abi_features != abi_features)
@@ -3858,7 +3858,7 @@ riscv_next_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   struct gdbarch *gdbarch = regcache->arch ();
   const riscv_gdbarch_tdep *tdep
-    = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
+    = gdbarch_tdep_cast<riscv_gdbarch_tdep> (gdbarch);
   struct riscv_insn insn;
   CORE_ADDR next_pc;
 
diff --git a/gdb/rl78-tdep.c b/gdb/rl78-tdep.c
index 2462e7a191d..b6c66a34125 100644
--- a/gdb/rl78-tdep.c
+++ b/gdb/rl78-tdep.c
@@ -267,7 +267,7 @@ struct rl78_prologue
 static struct type *
 rl78_psw_type (struct gdbarch *gdbarch)
 {
-  rl78_gdbarch_tdep *tdep = gdbarch_tdep<rl78_gdbarch_tdep> (gdbarch);
+  rl78_gdbarch_tdep *tdep = gdbarch_tdep_cast<rl78_gdbarch_tdep> (gdbarch);
 
   if (tdep->rl78_psw_type == NULL)
     {
@@ -291,7 +291,7 @@ rl78_psw_type (struct gdbarch *gdbarch)
 static struct type *
 rl78_register_type (struct gdbarch *gdbarch, int reg_nr)
 {
-  rl78_gdbarch_tdep *tdep = gdbarch_tdep<rl78_gdbarch_tdep> (gdbarch);
+  rl78_gdbarch_tdep *tdep = gdbarch_tdep_cast<rl78_gdbarch_tdep> (gdbarch);
 
   if (reg_nr == RL78_PC_REGNUM)
     return tdep->rl78_code_pointer;
@@ -1248,7 +1248,7 @@ rl78_return_value (struct gdbarch *gdbarch,
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   ULONGEST valtype_len = TYPE_LENGTH (valtype);
-  rl78_gdbarch_tdep *tdep = gdbarch_tdep<rl78_gdbarch_tdep> (gdbarch);
+  rl78_gdbarch_tdep *tdep = gdbarch_tdep_cast<rl78_gdbarch_tdep> (gdbarch);
   int is_g10 = tdep->elf_flags & E_FLAG_RL78_G10;
 
   if (valtype_len > 8)
@@ -1394,7 +1394,7 @@ rl78_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       rl78_gdbarch_tdep *tdep
-	= gdbarch_tdep<rl78_gdbarch_tdep> (arches->gdbarch);
+	= gdbarch_tdep_cast<rl78_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->elf_flags != elf_flags)
 	continue;
diff --git a/gdb/rs6000-aix-nat.c b/gdb/rs6000-aix-nat.c
index cb141427696..8d6d79d78d0 100644
--- a/gdb/rs6000-aix-nat.c
+++ b/gdb/rs6000-aix-nat.c
@@ -115,7 +115,7 @@ static rs6000_nat_target the_rs6000_nat_target;
 static int
 regmap (struct gdbarch *gdbarch, int regno, int *isfloat)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   *isfloat = 0;
   if (tdep->ppc_gp0_regnum <= regno
@@ -317,7 +317,7 @@ rs6000_nat_target::fetch_registers (struct regcache *regcache, int regno)
 
   else
     {
-      ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+      ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
       /* Read 32 general purpose registers.  */
       for (regno = tdep->ppc_gp0_regnum;
@@ -359,7 +359,7 @@ rs6000_nat_target::store_registers (struct regcache *regcache, int regno)
 
   else
     {
-      ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+      ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
       /* Write general purpose registers first.  */
       for (regno = tdep->ppc_gp0_regnum;
diff --git a/gdb/rs6000-aix-tdep.c b/gdb/rs6000-aix-tdep.c
index 41384993c26..0770e450157 100644
--- a/gdb/rs6000-aix-tdep.c
+++ b/gdb/rs6000-aix-tdep.c
@@ -75,7 +75,7 @@ aix_sighandle_frame_cache (struct frame_info *this_frame,
   LONGEST backchain;
   CORE_ADDR base, base_orig, func;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct trad_frame_cache *this_trad_cache;
 
@@ -261,7 +261,7 @@ rs6000_aix_iterate_over_regset_sections (struct gdbarch *gdbarch,
 					 void *cb_data,
 					 const struct regcache *regcache)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   if (tdep->wordsize == 4)
     cb (".reg", 592, 592, &rs6000_aix32_regset, NULL, cb_data);
   else
@@ -292,7 +292,7 @@ rs6000_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 			function_call_return_method return_method,
 			CORE_ADDR struct_addr)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int ii;
   int len = 0;
@@ -522,7 +522,7 @@ rs6000_return_value (struct gdbarch *gdbarch, struct value *function,
 		     struct type *valtype, struct regcache *regcache,
 		     gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   /* The calling convention this function implements assumes the
@@ -660,7 +660,7 @@ rs6000_convert_from_func_ptr_addr (struct gdbarch *gdbarch,
 				   CORE_ADDR addr,
 				   struct target_ops *targ)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct obj_section *s;
 
@@ -704,7 +704,7 @@ branch_dest (struct regcache *regcache, int opcode, int instr,
 	     CORE_ADDR pc, CORE_ADDR safety)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR dest;
   int immediate;
@@ -972,7 +972,7 @@ static struct ld_info
 rs6000_aix_extract_ld_info (struct gdbarch *gdbarch,
 			    const gdb_byte *ldi_buf)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
   const struct ld_info_desc desc
@@ -1131,7 +1131,7 @@ rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch,
 static void
 rs6000_aix_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   /* RS6000/AIX does not support PT_STEP.  Has to be simulated.  */
   set_gdbarch_software_single_step (gdbarch, rs6000_software_single_step);
diff --git a/gdb/rs6000-lynx178-tdep.c b/gdb/rs6000-lynx178-tdep.c
index dc13dd3fa73..a1ecac632e0 100644
--- a/gdb/rs6000-lynx178-tdep.c
+++ b/gdb/rs6000-lynx178-tdep.c
@@ -36,7 +36,7 @@ rs6000_lynx178_push_dummy_call (struct gdbarch *gdbarch,
 				function_call_return_method return_method,
 				CORE_ADDR struct_addr)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int ii;
   int len = 0;
@@ -265,7 +265,7 @@ rs6000_lynx178_return_value (struct gdbarch *gdbarch, struct value *function,
 			     struct type *valtype, struct regcache *regcache,
 			     gdb_byte *readbuf, const gdb_byte *writebuf)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   /* The calling convention this function implements assumes the
diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
index 640459f1c28..ad706689343 100644
--- a/gdb/rs6000-tdep.c
+++ b/gdb/rs6000-tdep.c
@@ -201,7 +201,7 @@ struct rs6000_framedata
 int
 vsx_register_p (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   if (tdep->ppc_vsr0_regnum < 0)
     return 0;
   else
@@ -213,7 +213,7 @@ vsx_register_p (struct gdbarch *gdbarch, int regno)
 int
 altivec_register_p (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   if (tdep->ppc_vr0_regnum < 0 || tdep->ppc_vrsave_regnum < 0)
     return 0;
   else
@@ -225,7 +225,7 @@ altivec_register_p (struct gdbarch *gdbarch, int regno)
 int
 spe_register_p (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   
   /* Is it a reference to EV0 -- EV31, and do we have those?  */
   if (IS_SPE_PSEUDOREG (tdep, regno))
@@ -257,7 +257,7 @@ spe_register_p (struct gdbarch *gdbarch, int regno)
 int
 ppc_floating_point_unit_p (struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   return (tdep->ppc_fp0_regnum >= 0
 	  && tdep->ppc_fpscr_regnum >= 0);
@@ -268,7 +268,7 @@ ppc_floating_point_unit_p (struct gdbarch *gdbarch)
 int
 ppc_altivec_support_p (struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   return (tdep->ppc_vr0_regnum >= 0
 	  && tdep->ppc_vrsave_regnum >= 0);
@@ -297,7 +297,7 @@ set_sim_regno (int *table, int gdb_regno, int sim_regno)
 static void
 init_sim_regno_table (struct gdbarch *arch)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (arch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (arch);
   int total_regs = gdbarch_num_regs (arch);
   int *sim_regno = GDBARCH_OBSTACK_CALLOC (arch, total_regs, int);
   int i;
@@ -391,7 +391,7 @@ init_sim_regno_table (struct gdbarch *arch)
 static int
 rs6000_register_sim_regno (struct gdbarch *gdbarch, int reg)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int sim_regno;
 
   if (tdep->sim_regno == NULL)
@@ -522,7 +522,7 @@ ppc_supply_gregset (const struct regset *regset, struct regcache *regcache,
 		    int regnum, const void *gregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   const struct ppc_reg_offsets *offsets
     = (const struct ppc_reg_offsets *) regset->regmap;
   size_t offset;
@@ -578,7 +578,7 @@ ppc_supply_fpregset (const struct regset *regset, struct regcache *regcache,
   if (!ppc_floating_point_unit_p (gdbarch))
     return;
 
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   offsets = (const struct ppc_reg_offsets *) regset->regmap;
   if (regnum == -1)
     {
@@ -611,7 +611,7 @@ ppc_collect_gregset (const struct regset *regset,
 		     int regnum, void *gregs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   const struct ppc_reg_offsets *offsets
     = (const struct ppc_reg_offsets *) regset->regmap;
   size_t offset;
@@ -668,7 +668,7 @@ ppc_collect_fpregset (const struct regset *regset,
   if (!ppc_floating_point_unit_p (gdbarch))
     return;
 
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   offsets = (const struct ppc_reg_offsets *) regset->regmap;
   if (regnum == -1)
     {
@@ -746,7 +746,7 @@ static int
 rs6000_in_function_epilogue_frame_p (struct frame_info *curfrm,
 				     struct gdbarch *gdbarch, CORE_ADDR pc)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   bfd_byte insn_buf[PPC_INSN_SIZE];
   CORE_ADDR scan_pc, func_start, func_end, epilogue_start, epilogue_end;
@@ -1042,7 +1042,7 @@ ppc_displaced_step_fixup (struct gdbarch *gdbarch,
       if (insn & 0x1)
 	{
 	  /* Link register needs to be set to the next instruction's PC.  */
-	  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+	  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 	  regcache_cooked_write_unsigned (regs,
 					  tdep->ppc_lr_regnum,
 					  from + PPC_INSN_SIZE);
@@ -1590,7 +1590,7 @@ skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc, CORE_ADDR lim_pc,
   int num_skip_non_prologue_insns = 0;
   int r0_contains_arg = 0;
   const struct bfd_arch_info *arch_info = gdbarch_bfd_arch_info (gdbarch);
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
   memset (fdata, 0, sizeof (struct rs6000_framedata));
@@ -2310,7 +2310,7 @@ static CORE_ADDR
 rs6000_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   unsigned int ii, op;
   int rel;
@@ -2368,7 +2368,7 @@ rs6000_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
 static struct type *
 rs6000_builtin_type_vec64 (struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->ppc_builtin_type_vec64)
     {
@@ -2413,7 +2413,7 @@ rs6000_builtin_type_vec64 (struct gdbarch *gdbarch)
 static struct type *
 rs6000_builtin_type_vec128 (struct gdbarch *gdbarch)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->ppc_builtin_type_vec128)
     {
@@ -2467,7 +2467,7 @@ rs6000_builtin_type_vec128 (struct gdbarch *gdbarch)
 static const char *
 rs6000_register_name (struct gdbarch *gdbarch, int regno)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   /* The upper half "registers" have names in the XML description,
      but we present only the low GPRs and the full 64-bit registers
@@ -2605,7 +2605,7 @@ rs6000_register_name (struct gdbarch *gdbarch, int regno)
 static struct type *
 rs6000_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   /* These are the e500 pseudo-registers.  */
   if (IS_SPE_PSEUDOREG (tdep, regnum))
@@ -2644,7 +2644,7 @@ static int
 rs6000_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 				   const struct reggroup *group)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   if (IS_V_ALIAS_PSEUDOREG (tdep, regnum))
     return 0;
@@ -2659,7 +2659,7 @@ static int
 rs6000_convert_register_p (struct gdbarch *gdbarch, int regnum,
 			   struct type *type)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   return (tdep->ppc_fp0_regnum >= 0
 	  && regnum >= tdep->ppc_fp0_regnum
@@ -2744,7 +2744,7 @@ e500_move_ev_register (move_ev_register_func move,
 		       struct regcache *regcache, int ev_reg, void *buffer)
 {
   struct gdbarch *arch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (arch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (arch);
   int reg_index;
   gdb_byte *byte_buffer = (gdb_byte *) buffer;
   enum register_status status;
@@ -2785,7 +2785,7 @@ e500_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int ev_reg, gdb_byte *buffer)
 {
   struct gdbarch *arch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int reg_index;
   enum register_status status;
 
@@ -2826,7 +2826,7 @@ static enum register_status
 dfp_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int reg_nr, gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, fp0;
   enum register_status status;
 
@@ -2866,7 +2866,7 @@ static void
 dfp_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
 			    int reg_nr, const gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, fp0;
 
   if (IS_DFP_PSEUDOREG (tdep, reg_nr))
@@ -2903,7 +2903,7 @@ v_alias_pseudo_register_read (struct gdbarch *gdbarch,
 			      readable_regcache *regcache, int reg_nr,
 			      gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   gdb_assert (IS_V_ALIAS_PSEUDOREG (tdep, reg_nr));
 
   return regcache->raw_read (tdep->ppc_vr0_regnum
@@ -2918,7 +2918,7 @@ v_alias_pseudo_register_write (struct gdbarch *gdbarch,
 			       struct regcache *regcache,
 			       int reg_nr, const gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   gdb_assert (IS_V_ALIAS_PSEUDOREG (tdep, reg_nr));
 
   regcache->raw_write (tdep->ppc_vr0_regnum
@@ -2930,7 +2930,7 @@ static enum register_status
 vsx_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int reg_nr, gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0, fp0, vsr0_upper;
   enum register_status status;
 
@@ -2978,7 +2978,7 @@ static void
 vsx_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
 			    int reg_nr, const gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0, fp0, vsr0_upper;
 
   if (IS_VSX_PSEUDOREG (tdep, reg_nr))
@@ -3020,7 +3020,7 @@ static enum register_status
 efp_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int reg_nr, gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0;
 
   if (IS_EFP_PSEUDOREG (tdep, reg_nr))
@@ -3049,7 +3049,7 @@ static void
 efp_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
 			    int reg_nr, const gdb_byte *buffer)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0;
   int offset = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG ? 0 : 8;
 
@@ -3085,7 +3085,7 @@ rs6000_pseudo_register_read (struct gdbarch *gdbarch,
 			     int reg_nr, gdb_byte *buffer)
 {
   struct gdbarch *regcache_arch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   gdb_assert (regcache_arch == gdbarch);
 
@@ -3116,7 +3116,7 @@ rs6000_pseudo_register_write (struct gdbarch *gdbarch,
 			      int reg_nr, const gdb_byte *buffer)
 {
   struct gdbarch *regcache_arch = regcache->arch ();
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   gdb_assert (regcache_arch == gdbarch);
 
@@ -3147,7 +3147,7 @@ static void
 dfp_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				struct agent_expr *ax, int reg_nr)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, fp0;
 
   if (IS_DFP_PSEUDOREG (tdep, reg_nr))
@@ -3174,7 +3174,7 @@ static void
 v_alias_pseudo_register_collect (struct gdbarch *gdbarch,
 				 struct agent_expr *ax, int reg_nr)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   gdb_assert (IS_V_ALIAS_PSEUDOREG (tdep, reg_nr));
 
   ax_reg_mask (ax, tdep->ppc_vr0_regnum
@@ -3188,7 +3188,7 @@ static void
 vsx_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				struct agent_expr *ax, int reg_nr)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0, fp0, vsr0_upper;
 
   if (IS_VSX_PSEUDOREG (tdep, reg_nr))
@@ -3226,7 +3226,7 @@ static void
 efp_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				struct agent_expr *ax, int reg_nr)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int reg_index, vr0;
 
   if (IS_EFP_PSEUDOREG (tdep, reg_nr))
@@ -3249,7 +3249,7 @@ static int
 rs6000_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				   struct agent_expr *ax, int reg_nr)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   if (IS_SPE_PSEUDOREG (tdep, reg_nr))
     {
       int reg_index = reg_nr - tdep->ppc_ev0_regnum;
@@ -3289,7 +3289,7 @@ rs6000_gen_return_address (struct gdbarch *gdbarch,
 			   struct agent_expr *ax, struct axs_value *value,
 			   CORE_ADDR scope)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   value->type = register_type (gdbarch, tdep->ppc_lr_regnum);
   value->kind = axs_lvalue_register;
   value->u.reg = tdep->ppc_lr_regnum;
@@ -3300,7 +3300,7 @@ rs6000_gen_return_address (struct gdbarch *gdbarch,
 static int
 rs6000_stab_reg_to_regnum (struct gdbarch *gdbarch, int num)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   if (0 <= num && num <= 31)
     return tdep->ppc_gp0_regnum + num;
@@ -3342,7 +3342,7 @@ rs6000_stab_reg_to_regnum (struct gdbarch *gdbarch, int num)
 static int
 rs6000_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int num)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   if (0 <= num && num <= 31)
     return tdep->ppc_gp0_regnum + num;
@@ -3561,7 +3561,7 @@ rs6000_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct rs6000_frame_cache *cache;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct rs6000_framedata fdata;
   int wordsize = tdep->wordsize;
@@ -3797,7 +3797,7 @@ rs6000_epilogue_frame_cache (struct frame_info *this_frame, void **this_cache)
 {
   struct rs6000_frame_cache *cache;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   if (*this_cache)
     return (struct rs6000_frame_cache *) *this_cache;
@@ -3918,7 +3918,7 @@ ppc_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
 			    struct dwarf2_frame_state_reg *reg,
 			    struct frame_info *this_frame)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   /* PPC32 and PPC64 ABI's are the same regarding volatile and
      non-volatile registers.  We will use the same code for both.  */
@@ -4229,7 +4229,7 @@ static int
 ppc_process_record_op4 (struct gdbarch *gdbarch, struct regcache *regcache,
 			CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_FIELD (insn, 21, 11);
   int vra = PPC_FIELD (insn, 11, 5);
 
@@ -4771,7 +4771,7 @@ static int
 ppc_process_record_op6 (struct gdbarch *gdbarch, struct regcache *regcache,
 			CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int subtype = PPC_FIELD (insn, 28, 4);
   CORE_ADDR ea = 0;
 
@@ -4799,7 +4799,7 @@ static int
 ppc_process_record_op19 (struct gdbarch *gdbarch, struct regcache *regcache,
 			   CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_EXTOP (insn);
 
   switch (ext & 0x01f)
@@ -4855,7 +4855,7 @@ ppc_process_record_op31_177 (struct gdbarch *gdbarch,
 {
   int RA_opcode = PPC_RA(insn);
   int as = PPC_FIELD (insn, 6, 3);
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   switch (RA_opcode)
     {
@@ -4875,7 +4875,7 @@ static int
 ppc_process_record_op31 (struct gdbarch *gdbarch, struct regcache *regcache,
 			   CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_EXTOP (insn);
   int tmp, nr, nb = 0, i;
   CORE_ADDR at_dcsz, ea = 0;
@@ -5536,7 +5536,7 @@ static int
 ppc_process_record_op59 (struct gdbarch *gdbarch, struct regcache *regcache,
 			 CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_EXTOP (insn);
   int at = PPC_FIELD (insn, 6, 3);
 
@@ -5701,7 +5701,7 @@ ppc_process_record_op60_XX2 (struct gdbarch *gdbarch,
 			     struct regcache *regcache,
 			     CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int RA_opcode = PPC_RA(insn);
 
   switch (RA_opcode)
@@ -5742,7 +5742,7 @@ static int
 ppc_process_record_op60 (struct gdbarch *gdbarch, struct regcache *regcache,
 			   CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_EXTOP (insn);
 
   switch (ext >> 2)
@@ -6097,7 +6097,7 @@ static int
 ppc_process_record_op61 (struct gdbarch *gdbarch, struct regcache *regcache,
 			   CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   ULONGEST ea = 0;
   int size;
 
@@ -6156,7 +6156,7 @@ static int
 ppc_process_record_op63 (struct gdbarch *gdbarch, struct regcache *regcache,
 			   CORE_ADDR addr, uint32_t insn)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int ext = PPC_EXTOP (insn);
   int tmp;
 
@@ -6453,7 +6453,7 @@ ppc_process_record_prefix_op42 (struct gdbarch *gdbarch,
 				struct regcache *regcache,
 				uint32_t insn_prefix, uint32_t insn_suffix)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST1 = PPC_FIELD (insn_prefix, 8, 1);
 
@@ -6489,7 +6489,7 @@ ppc_process_record_prefix_op59_XX3 (struct gdbarch *gdbarch,
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST4 = PPC_FIELD (insn_prefix, 8, 4);
   int at = PPC_FIELD (insn_suffix, 6, 3);
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   if (type == 3)
     {
@@ -6603,7 +6603,7 @@ ppc_process_record_prefix_store (struct gdbarch *gdbarch,
 				 CORE_ADDR addr, uint32_t insn_prefix,
 				 uint32_t insn_suffix)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   ULONGEST iaddr = 0;
   int size;
   int R = PPC_BIT (insn_prefix, 11);
@@ -6659,7 +6659,7 @@ ppc_process_record_prefix_op32 (struct gdbarch *gdbarch,
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST1 = PPC_FIELD (insn_prefix, 8, 1);
   int ST4 = PPC_FIELD (insn_prefix, 8, 4);
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   if (type == 1)
     {
@@ -6713,7 +6713,7 @@ ppc_process_record_prefix_op33 (struct gdbarch *gdbarch,
 {
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST4 = PPC_FIELD (insn_prefix, 8, 4);
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   if (type == 1)
     {
@@ -6751,7 +6751,7 @@ ppc_process_record_prefix_op34 (struct gdbarch *gdbarch,
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST1 = PPC_FIELD (insn_prefix, 8, 1);
   int ST4 = PPC_FIELD (insn_prefix, 8, 4);
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   if (type == 1)
     {
@@ -6797,7 +6797,7 @@ ppc_process_record_prefix_store_vsx_ds_form (struct gdbarch *gdbarch,
 					     uint32_t insn_prefix,
 					     uint32_t insn_suffix)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   ULONGEST ea = 0;
   int size;
   int R = PPC_BIT (insn_prefix, 11);
@@ -6850,7 +6850,7 @@ ppc_process_record_prefix_vsx_d_form (struct gdbarch *gdbarch,
 				      uint32_t insn_prefix,
 				      uint32_t insn_suffix)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   ULONGEST ea = 0;
   int size;
   int R = PPC_BIT (insn_prefix, 11);
@@ -6907,7 +6907,7 @@ ppc_process_prefix_instruction (int insn_prefix, int insn_suffix,
 {
   int type = PPC_FIELD (insn_prefix, 6, 2);
   int ST1 = PPC_FIELD (insn_prefix, 8, 1);
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   int op6;
 
   /* D-form has uses a 5-bit opcode in the instruction suffix */
@@ -7086,7 +7086,7 @@ int
 ppc_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
 		      CORE_ADDR addr)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   uint32_t insn, insn_suffix;
   int op6, tmp, i;
@@ -8150,7 +8150,7 @@ rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 	 meaningful, because 64-bit CPUs can run in 32-bit mode.  So, perform
 	 separate word size check.  */
       ppc_gdbarch_tdep *tdep
-	= gdbarch_tdep<ppc_gdbarch_tdep> (arches->gdbarch);
+	= gdbarch_tdep_cast<ppc_gdbarch_tdep> (arches->gdbarch);
       if (tdep && tdep->elf_abi != elf_abi)
 	continue;
       if (tdep && tdep->soft_float != soft_float)
@@ -8452,7 +8452,7 @@ rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 static void
 rs6000_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
 {
-  ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
+  ppc_gdbarch_tdep *tdep = gdbarch_tdep_cast<ppc_gdbarch_tdep> (gdbarch);
 
   if (tdep == NULL)
     return;
diff --git a/gdb/rx-tdep.c b/gdb/rx-tdep.c
index c67d4057195..4fd0717d788 100644
--- a/gdb/rx-tdep.c
+++ b/gdb/rx-tdep.c
@@ -964,7 +964,7 @@ rx_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       rx_gdbarch_tdep *tdep
-	= gdbarch_tdep<rx_gdbarch_tdep> (arches->gdbarch);
+	= gdbarch_tdep_cast<rx_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->elf_flags != elf_flags)
 	continue;
diff --git a/gdb/s390-linux-tdep.c b/gdb/s390-linux-tdep.c
index 05bf03973fc..6ff45e40c5b 100644
--- a/gdb/s390-linux-tdep.c
+++ b/gdb/s390-linux-tdep.c
@@ -79,7 +79,7 @@ static void
 s390_write_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
 
   regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
 
@@ -269,7 +269,7 @@ s390_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				   void *cb_data,
 				   const struct regcache *regcache)
 {
-  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
   const int gregset_size = (tdep->abi == ABI_LINUX_S390 ?
 			    s390_sizeof_gregset : s390x_sizeof_gregset);
 
@@ -390,7 +390,7 @@ s390_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
 				  void **this_prologue_cache)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
   int word_size = gdbarch_ptr_bit (gdbarch) / 8;
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   struct s390_sigtramp_unwind_cache *info;
@@ -561,7 +561,7 @@ s390_linux_get_syscall_number (struct gdbarch *gdbarch,
 			       thread_info *thread)
 {
   struct regcache *regs = get_thread_regcache (thread);
-  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   ULONGEST pc;
   ULONGEST svc_number = -1;
@@ -594,7 +594,7 @@ static int
 s390_all_but_pc_registers_record (struct regcache *regcache)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
   int i;
 
   for (i = 0; i < 16; i++)
@@ -804,7 +804,7 @@ static int
 s390_linux_syscall_record (struct regcache *regcache, LONGEST syscall_native)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
   int ret;
   enum gdb_syscall syscall_gdb;
 
@@ -855,7 +855,7 @@ static int
 s390_linux_record_signal (struct gdbarch *gdbarch, struct regcache *regcache,
 			  enum gdb_signal signal)
 {
-  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
   /* There are two kinds of signal frames on s390. rt_sigframe is always
      the larger one, so don't even bother with sigframe.  */
   const int sizeof_rt_sigframe = (tdep->abi == ABI_LINUX_ZSERIES ?
@@ -1119,7 +1119,7 @@ s390_init_linux_record_tdep (struct linux_record_tdep *record_tdep,
 static void
 s390_linux_init_abi_any (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
 
   tdep->s390_syscall_record = s390_linux_syscall_record;
 
@@ -1154,7 +1154,7 @@ s390_linux_init_abi_any (struct gdbarch_info info, struct gdbarch *gdbarch)
 static void
 s390_linux_init_abi_31 (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
 
   tdep->abi = ABI_LINUX_S390;
 
@@ -1170,7 +1170,7 @@ s390_linux_init_abi_31 (struct gdbarch_info info, struct gdbarch *gdbarch)
 static void
 s390_linux_init_abi_64 (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
 
   tdep->abi = ABI_LINUX_ZSERIES;
 
diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c
index 2aeb3a14637..856908bb8f5 100644
--- a/gdb/s390-tdep.c
+++ b/gdb/s390-tdep.c
@@ -1045,7 +1045,7 @@ s390_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
 static int
 s390_register_call_saved (struct gdbarch *gdbarch, int regnum)
 {
-  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
 
   switch (tdep->abi)
     {
@@ -1076,7 +1076,7 @@ s390_guess_tracepoint_registers (struct gdbarch *gdbarch,
 				 struct regcache *regcache,
 				 CORE_ADDR addr)
 {
-  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
   int sz = register_size (gdbarch, S390_PSWA_REGNUM);
   gdb_byte *reg = (gdb_byte *) alloca (sz);
   ULONGEST pswm, pswa;
@@ -1172,7 +1172,7 @@ enum { s390_dwarf_reg_r0l = ARRAY_SIZE (s390_dwarf_regmap) - 16 };
 static int
 s390_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 {
-  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
   int gdb_reg = -1;
 
   /* In a 32-on-64 debug scenario, debug info refers to the full
@@ -1231,7 +1231,7 @@ static struct value *
 s390_value_from_register (struct gdbarch *gdbarch, struct type *type,
 			  int regnum, struct frame_id frame_id)
 {
-  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
   struct value *value = default_value_from_register (gdbarch, type,
 						     regnum, frame_id);
   check_typedef (type);
@@ -1250,7 +1250,7 @@ s390_value_from_register (struct gdbarch *gdbarch, struct type *type,
 static const char *
 s390_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
 
   if (regnum == tdep->pc_regnum)
     return "pc";
@@ -1284,7 +1284,7 @@ s390_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
 static struct type *
 s390_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
 
   if (regnum == tdep->pc_regnum)
     return builtin_type (gdbarch)->builtin_func_ptr;
@@ -1308,7 +1308,7 @@ static enum register_status
 s390_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
 			   int regnum, gdb_byte *buf)
 {
-  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int regsize = register_size (gdbarch, regnum);
   ULONGEST val;
@@ -1383,7 +1383,7 @@ static void
 s390_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
 			    int regnum, const gdb_byte *buf)
 {
-  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int regsize = register_size (gdbarch, regnum);
   ULONGEST val, psw;
@@ -1442,7 +1442,7 @@ static int
 s390_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 				 const struct reggroup *group)
 {
-  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
 
   /* We usually save/restore the whole PSW, which includes PC and CC.
      However, some older gdbservers may not support saving/restoring
@@ -1470,7 +1470,7 @@ static int
 s390_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 				 struct agent_expr *ax, int regnum)
 {
-  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
   if (regnum == tdep->pc_regnum)
     {
       ax_reg_mask (ax, S390_PSWA_REGNUM);
@@ -1504,7 +1504,7 @@ static int
 s390_ax_pseudo_register_push_stack (struct gdbarch *gdbarch,
 				    struct agent_expr *ax, int regnum)
 {
-  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
   if (regnum == tdep->pc_regnum)
     {
       ax_reg (ax, S390_PSWA_REGNUM);
@@ -1905,7 +1905,7 @@ s390_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 		      function_call_return_method return_method,
 		      CORE_ADDR struct_addr)
 {
-  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
   int word_size = gdbarch_ptr_bit (gdbarch) / 8;
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int i;
@@ -2084,7 +2084,7 @@ s390_return_value (struct gdbarch *gdbarch, struct value *function,
       break;
     case TYPE_CODE_ARRAY:
       {
-	s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+	s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
 	rvc = (tdep->vector_abi == S390_VECTOR_ABI_128
 	       && TYPE_LENGTH (type) <= 16 && type->is_vector ())
 	  ? RETURN_VALUE_REGISTER_CONVENTION
@@ -2168,7 +2168,7 @@ s390_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
 static CORE_ADDR
 s390_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
 {
-  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
   ULONGEST pc;
   pc = frame_unwind_register_unsigned (next_frame, tdep->pc_regnum);
   return gdbarch_addr_bits_remove (gdbarch, pc);
@@ -2190,7 +2190,7 @@ static struct value *
 s390_unwind_pseudo_register (struct frame_info *this_frame, int regnum)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
   struct type *type = register_type (gdbarch, regnum);
 
   /* Unwind PC via PSW address.  */
@@ -2775,7 +2775,7 @@ static CORE_ADDR
 s390_record_address_mask (struct gdbarch *gdbarch, struct regcache *regcache,
 			  CORE_ADDR val)
 {
-  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
   ULONGEST pswm, pswa;
   int am;
   if (tdep->abi == ABI_LINUX_S390)
@@ -2842,7 +2842,7 @@ s390_record_calc_disp_vsce (struct gdbarch *gdbarch, struct regcache *regcache,
 			    uint8_t vx, uint8_t el, uint8_t es, uint16_t bd,
 			    int8_t dh, CORE_ADDR *res)
 {
-  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   ULONGEST x;
   gdb_byte buf[16];
@@ -2885,7 +2885,7 @@ static int s390_popcnt (unsigned int x) {
 static int
 s390_record_gpr_g (struct gdbarch *gdbarch, struct regcache *regcache, int i)
 {
-  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
   if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + i))
     return -1;
   if (tdep->abi == ABI_LINUX_S390)
@@ -2899,7 +2899,7 @@ s390_record_gpr_g (struct gdbarch *gdbarch, struct regcache *regcache, int i)
 static int
 s390_record_gpr_h (struct gdbarch *gdbarch, struct regcache *regcache, int i)
 {
-  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
   if (tdep->abi == ABI_LINUX_S390)
     {
       if (record_full_arch_list_add_reg (regcache, S390_R0_UPPER_REGNUM + i))
@@ -2939,7 +2939,7 @@ static int
 s390_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
 		     CORE_ADDR addr)
 {
-  s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
+  s390_gdbarch_tdep *tdep = gdbarch_tdep_cast<s390_gdbarch_tdep> (gdbarch);
   uint16_t insn[3] = {0};
   /* Instruction as bytes.  */
   uint8_t ibyte[6];
@@ -7178,7 +7178,7 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       s390_gdbarch_tdep *tmp
-	= gdbarch_tdep<s390_gdbarch_tdep> (arches->gdbarch);
+	= gdbarch_tdep_cast<s390_gdbarch_tdep> (arches->gdbarch);
 
       if (!tmp)
 	continue;
diff --git a/gdb/sh-linux-tdep.c b/gdb/sh-linux-tdep.c
index f146f023add..3e9c3c3027b 100644
--- a/gdb/sh-linux-tdep.c
+++ b/gdb/sh-linux-tdep.c
@@ -195,7 +195,7 @@ sh_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   set_gdbarch_fetch_tls_load_module_address (gdbarch,
 					     svr4_fetch_objfile_link_map);
 
-  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep_cast<sh_gdbarch_tdep> (gdbarch);
 
   /* Remember regset characteristics.  The sizes should match
      elf_gregset_t and elf_fpregset_t from Linux.  */
diff --git a/gdb/sh-netbsd-tdep.c b/gdb/sh-netbsd-tdep.c
index 49760337c4b..a051736fc71 100644
--- a/gdb/sh-netbsd-tdep.c
+++ b/gdb/sh-netbsd-tdep.c
@@ -63,7 +63,7 @@ static void
 shnbsd_init_abi (struct gdbarch_info info,
 		  struct gdbarch *gdbarch)
 {
-  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep_cast<sh_gdbarch_tdep> (gdbarch);
   nbsd_init_abi (info, gdbarch);
 
   tdep->core_gregmap = (struct sh_corefile_regmap *)regmap;
diff --git a/gdb/sh-tdep.c b/gdb/sh-tdep.c
index 062df860c81..b4161764bb5 100644
--- a/gdb/sh-tdep.c
+++ b/gdb/sh-tdep.c
@@ -1554,7 +1554,7 @@ sh_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 static struct type *
 sh_littlebyte_bigword_type (struct gdbarch *gdbarch)
 {
-  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep_cast<sh_gdbarch_tdep> (gdbarch);
 
   if (tdep->sh_littlebyte_bigword_type == NULL)
     tdep->sh_littlebyte_bigword_type
@@ -2146,7 +2146,7 @@ sh_corefile_supply_regset (const struct regset *regset,
 			   int regnum, const void *regs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep_cast<sh_gdbarch_tdep> (gdbarch);
   const struct sh_corefile_regmap *regmap = (regset == &sh_corefile_gregset
 					     ? tdep->core_gregmap
 					     : tdep->core_fpregmap);
@@ -2172,7 +2172,7 @@ sh_corefile_collect_regset (const struct regset *regset,
 			    int regnum, void *regs, size_t len)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep_cast<sh_gdbarch_tdep> (gdbarch);
   const struct sh_corefile_regmap *regmap = (regset == &sh_corefile_gregset
 					     ? tdep->core_gregmap
 					     : tdep->core_fpregmap);
@@ -2210,7 +2210,7 @@ sh_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				 void *cb_data,
 				 const struct regcache *regcache)
 {
-  sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
+  sh_gdbarch_tdep *tdep = gdbarch_tdep_cast<sh_gdbarch_tdep> (gdbarch);
 
   if (tdep->core_gregmap != NULL)
     cb (".reg", tdep->sizeof_gregset, tdep->sizeof_gregset,
diff --git a/gdb/sparc-linux-tdep.c b/gdb/sparc-linux-tdep.c
index 66481ea7b8a..068c8a64af5 100644
--- a/gdb/sparc-linux-tdep.c
+++ b/gdb/sparc-linux-tdep.c
@@ -254,7 +254,7 @@ static void
 sparc_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   gdbarch *arch = regcache->arch ();
-  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep_cast<sparc_gdbarch_tdep> (arch);
   ULONGEST psr;
 
   regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
@@ -421,7 +421,7 @@ static const struct regset sparc32_linux_fpregset =
 static void
 sparc32_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep_cast<sparc_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/sparc-netbsd-tdep.c b/gdb/sparc-netbsd-tdep.c
index 57c178511fa..62a207ea924 100644
--- a/gdb/sparc-netbsd-tdep.c
+++ b/gdb/sparc-netbsd-tdep.c
@@ -295,7 +295,7 @@ static const struct regset sparc32nbsd_fpregset =
 void
 sparc32nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep_cast<sparc_gdbarch_tdep> (gdbarch);
 
   nbsd_init_abi (info, gdbarch);
 
diff --git a/gdb/sparc-sol2-tdep.c b/gdb/sparc-sol2-tdep.c
index a92e95ce71b..e35a190e630 100644
--- a/gdb/sparc-sol2-tdep.c
+++ b/gdb/sparc-sol2-tdep.c
@@ -196,7 +196,7 @@ static const struct frame_unwind sparc32_sol2_sigtramp_frame_unwind =
 static void
 sparc32_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep_cast<sparc_gdbarch_tdep> (gdbarch);
 
   tdep->gregset = &sparc32_sol2_gregset;
   tdep->sizeof_gregset = 152;
diff --git a/gdb/sparc-tdep.c b/gdb/sparc-tdep.c
index 397f5489550..65051bdb2aa 100644
--- a/gdb/sparc-tdep.c
+++ b/gdb/sparc-tdep.c
@@ -425,7 +425,7 @@ sparc32_register_name (struct gdbarch *gdbarch, int regnum)
 static struct type *
 sparc_psr_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep_cast<sparc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->sparc_psr_type)
     {
@@ -447,7 +447,7 @@ sparc_psr_type (struct gdbarch *gdbarch)
 static struct type *
 sparc_fsr_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep_cast<sparc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->sparc_fsr_type)
     {
@@ -988,7 +988,7 @@ CORE_ADDR
 sparc_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
 			CORE_ADDR current_pc, struct sparc_frame_cache *cache)
 {
-  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep_cast<sparc_gdbarch_tdep> (gdbarch);
   unsigned long insn;
   int offset = 0;
   int dest = -1;
@@ -1680,7 +1680,7 @@ sparc_analyze_control_transfer (struct regcache *regcache,
 
       /* Trap instruction (TRAP).  */
       gdbarch *arch = regcache->arch ();
-      sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
+      sparc_gdbarch_tdep *tdep = gdbarch_tdep_cast<sparc_gdbarch_tdep> (arch);
       return tdep->step_trap (frame, insn);
     }
 
@@ -1731,7 +1731,7 @@ static std::vector<CORE_ADDR>
 sparc_software_single_step (struct regcache *regcache)
 {
   struct gdbarch *arch = regcache->arch ();
-  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep_cast<sparc_gdbarch_tdep> (arch);
   CORE_ADDR npc, nnpc;
 
   CORE_ADDR pc, orig_npc;
@@ -1761,7 +1761,7 @@ static void
 sparc_write_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   gdbarch *arch = regcache->arch ();
-  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep_cast<sparc_gdbarch_tdep> (arch);
 
   regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
   regcache_cooked_write_unsigned (regcache, tdep->npc_regnum, pc + 4);
@@ -1776,7 +1776,7 @@ sparc_iterate_over_regset_sections (struct gdbarch *gdbarch,
 				    void *cb_data,
 				    const struct regcache *regcache)
 {
-  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep_cast<sparc_gdbarch_tdep> (gdbarch);
 
   cb (".reg", tdep->sizeof_gregset, tdep->sizeof_gregset, tdep->gregset, NULL,
       cb_data);
diff --git a/gdb/sparc64-fbsd-tdep.c b/gdb/sparc64-fbsd-tdep.c
index 76c682fd521..d9cfffb14c2 100644
--- a/gdb/sparc64-fbsd-tdep.c
+++ b/gdb/sparc64-fbsd-tdep.c
@@ -222,7 +222,7 @@ static const struct regset sparc64fbsd_fpregset =
 static void
 sparc64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep_cast<sparc_gdbarch_tdep> (gdbarch);
 
   /* Generic FreeBSD support. */
   fbsd_init_abi (info, gdbarch);
diff --git a/gdb/sparc64-linux-tdep.c b/gdb/sparc64-linux-tdep.c
index f5940cfcdee..63c39475d95 100644
--- a/gdb/sparc64-linux-tdep.c
+++ b/gdb/sparc64-linux-tdep.c
@@ -262,7 +262,7 @@ static void
 sparc64_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
 {
   gdbarch *arch = regcache->arch ();
-  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep_cast<sparc_gdbarch_tdep> (arch);
   ULONGEST state;
 
   regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
@@ -364,7 +364,7 @@ static const struct regset sparc64_linux_fpregset =
 static void
 sparc64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep_cast<sparc_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/sparc64-netbsd-tdep.c b/gdb/sparc64-netbsd-tdep.c
index db368118f23..e2c7238de3b 100644
--- a/gdb/sparc64-netbsd-tdep.c
+++ b/gdb/sparc64-netbsd-tdep.c
@@ -248,7 +248,7 @@ static const struct regset sparc64nbsd_fpregset =
 static void
 sparc64nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep_cast<sparc_gdbarch_tdep> (gdbarch);
 
   nbsd_init_abi (info, gdbarch);
 
diff --git a/gdb/sparc64-obsd-tdep.c b/gdb/sparc64-obsd-tdep.c
index d6470a51b65..5e0a33b6dc4 100644
--- a/gdb/sparc64-obsd-tdep.c
+++ b/gdb/sparc64-obsd-tdep.c
@@ -423,7 +423,7 @@ static const struct regset sparc64obsd_fpregset =
 static void
 sparc64obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep_cast<sparc_gdbarch_tdep> (gdbarch);
 
   tdep->gregset = &sparc64obsd_gregset;
   tdep->sizeof_gregset = 288;
diff --git a/gdb/sparc64-sol2-tdep.c b/gdb/sparc64-sol2-tdep.c
index e656c359efa..4f90a044e8c 100644
--- a/gdb/sparc64-sol2-tdep.c
+++ b/gdb/sparc64-sol2-tdep.c
@@ -199,7 +199,7 @@ static const struct frame_unwind sparc64_sol2_sigtramp_frame_unwind =
 static void
 sparc64_sol2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep_cast<sparc_gdbarch_tdep> (gdbarch);
 
   tdep->gregset = &sparc64_sol2_gregset;
   tdep->sizeof_gregset = 304;
diff --git a/gdb/sparc64-tdep.c b/gdb/sparc64-tdep.c
index 5ca5f2dca8c..45777f6494b 100644
--- a/gdb/sparc64-tdep.c
+++ b/gdb/sparc64-tdep.c
@@ -648,7 +648,7 @@ sparc64_structure_or_union_p (const struct type *type)
 static struct type *
 sparc64_pstate_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep_cast<sparc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->sparc64_pstate_type)
     {
@@ -675,7 +675,7 @@ sparc64_pstate_type (struct gdbarch *gdbarch)
 static struct type *
 sparc64_ccr_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep_cast<sparc_gdbarch_tdep> (gdbarch);
 
   if (tdep->sparc64_ccr_type == NULL)
     {
@@ -700,7 +700,7 @@ sparc64_ccr_type (struct gdbarch *gdbarch)
 static struct type *
 sparc64_fsr_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep_cast<sparc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->sparc64_fsr_type)
     {
@@ -733,7 +733,7 @@ sparc64_fsr_type (struct gdbarch *gdbarch)
 static struct type *
 sparc64_fprs_type (struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep_cast<sparc_gdbarch_tdep> (gdbarch);
 
   if (!tdep->sparc64_fprs_type)
     {
@@ -1806,7 +1806,7 @@ sparc64_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr)
 void
 sparc64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
+  sparc_gdbarch_tdep *tdep = gdbarch_tdep_cast<sparc_gdbarch_tdep> (gdbarch);
 
   tdep->pc_regnum = SPARC64_PC_REGNUM;
   tdep->npc_regnum = SPARC64_NPC_REGNUM;
diff --git a/gdb/tic6x-linux-tdep.c b/gdb/tic6x-linux-tdep.c
index b2422d1ccc0..dc862f2ca83 100644
--- a/gdb/tic6x-linux-tdep.c
+++ b/gdb/tic6x-linux-tdep.c
@@ -45,7 +45,7 @@ static const gdb_byte tic6x_bkpt_bnop_le[] = { 0x22, 0xa1, 0x00, 0x00 };
 static unsigned int
 tic6x_register_sigcontext_offset (unsigned int regnum, struct gdbarch *gdbarch)
 {
-  tic6x_gdbarch_tdep *tdep = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
+  tic6x_gdbarch_tdep *tdep = gdbarch_tdep_cast<tic6x_gdbarch_tdep> (gdbarch);
 
   if (regnum == TIC6X_A4_REGNUM || regnum == TIC6X_A4_REGNUM + 2
       || regnum == TIC6X_A4_REGNUM + 4)
@@ -92,7 +92,7 @@ tic6x_linux_rt_sigreturn_init (const struct tramp_frame *self,
 		    + TIC6X_SIGINFO_SIZE
 		    + 4 + 4 /* uc_flags and *uc_link in struct ucontext.  */
 		    + TIC6X_STACK_T_SIZE);
-  tic6x_gdbarch_tdep *tdep = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
+  tic6x_gdbarch_tdep *tdep = gdbarch_tdep_cast<tic6x_gdbarch_tdep> (gdbarch);
   unsigned int reg_offset;
   unsigned int i;
 
@@ -165,7 +165,7 @@ extern struct target_so_ops dsbt_so_ops;
 static void
 tic6x_uclinux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  tic6x_gdbarch_tdep *tdep = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
+  tic6x_gdbarch_tdep *tdep = gdbarch_tdep_cast<tic6x_gdbarch_tdep> (gdbarch);
 
   linux_init_abi (info, gdbarch, 0);
 
diff --git a/gdb/tic6x-tdep.c b/gdb/tic6x-tdep.c
index b7efcf18576..e0554417e0b 100644
--- a/gdb/tic6x-tdep.c
+++ b/gdb/tic6x-tdep.c
@@ -325,7 +325,7 @@ tic6x_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 static const gdb_byte *
 tic6x_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
 {
-  tic6x_gdbarch_tdep *tdep = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
+  tic6x_gdbarch_tdep *tdep = gdbarch_tdep_cast<tic6x_gdbarch_tdep> (gdbarch);
 
   *size = kind;
 
@@ -599,7 +599,7 @@ tic6x_get_next_pc (struct regcache *regcache, CORE_ADDR pc)
       if (inst == TIC6X_INST_SWE)
 	{
 	  tic6x_gdbarch_tdep *tdep
-	    = gdbarch_tdep<tic6x_gdbarch_tdep> (gdbarch);
+	    = gdbarch_tdep_cast<tic6x_gdbarch_tdep> (gdbarch);
 
 	  if (tdep->syscall_next_pc != NULL)
 	    return tdep->syscall_next_pc (get_current_frame ());
@@ -1217,7 +1217,7 @@ tic6x_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       tic6x_gdbarch_tdep *tdep
-	= gdbarch_tdep<tic6x_gdbarch_tdep> (arches->gdbarch);
+	= gdbarch_tdep_cast<tic6x_gdbarch_tdep> (arches->gdbarch);
 
       if (has_gp != tdep->has_gp)
 	continue;
diff --git a/gdb/v850-tdep.c b/gdb/v850-tdep.c
index 4de5faa6a47..67e8e350470 100644
--- a/gdb/v850-tdep.c
+++ b/gdb/v850-tdep.c
@@ -511,7 +511,7 @@ v850_use_struct_convention (struct gdbarch *gdbarch, struct type *type)
 {
   int i;
   struct type *fld_type, *tgt_type;
-  v850_gdbarch_tdep *tdep = gdbarch_tdep<v850_gdbarch_tdep> (gdbarch);
+  v850_gdbarch_tdep *tdep = gdbarch_tdep_cast<v850_gdbarch_tdep> (gdbarch);
 
   if (tdep->abi == V850_ABI_RH850)
     {
@@ -1023,7 +1023,7 @@ v850_push_dummy_call (struct gdbarch *gdbarch,
   int argnum;
   int arg_space = 0;
   int stack_offset;
-  v850_gdbarch_tdep *tdep = gdbarch_tdep<v850_gdbarch_tdep> (gdbarch);
+  v850_gdbarch_tdep *tdep = gdbarch_tdep_cast<v850_gdbarch_tdep> (gdbarch);
 
   if (tdep->abi == V850_ABI_RH850)
     stack_offset = 0;
@@ -1374,7 +1374,7 @@ v850_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        arches = gdbarch_list_lookup_by_info (arches->next, &info))
     {
       v850_gdbarch_tdep *tdep
-	= gdbarch_tdep<v850_gdbarch_tdep> (arches->gdbarch);
+	= gdbarch_tdep_cast<v850_gdbarch_tdep> (arches->gdbarch);
 
       if (tdep->e_flags != e_flags || tdep->e_machine != e_machine)
 	continue;
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 43a2c112db5..830144fa2c4 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -486,7 +486,7 @@ windows_fetch_one_register (struct regcache *regcache,
 
   char *context_offset = context_ptr + windows_process.mappings[r];
   struct gdbarch *gdbarch = regcache->arch ();
-  i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
+  i386_gdbarch_tdep *tdep = gdbarch_tdep_cast<i386_gdbarch_tdep> (gdbarch);
 
   gdb_assert (!gdbarch_read_pc_p (gdbarch));
   gdb_assert (gdbarch_pc_regnum (gdbarch) >= 0);
diff --git a/gdb/xtensa-linux-nat.c b/gdb/xtensa-linux-nat.c
index d005c9d8f78..9e9e9081406 100644
--- a/gdb/xtensa-linux-nat.c
+++ b/gdb/xtensa-linux-nat.c
@@ -62,7 +62,7 @@ fill_gregset (const struct regcache *regcache,
   int i;
   xtensa_elf_gregset_t *regs = (xtensa_elf_gregset_t *) gregsetp;
   struct gdbarch *gdbarch = regcache->arch ();
-  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
 
   if (regnum == gdbarch_pc_regnum (gdbarch) || regnum == -1)
     regcache->raw_collect (gdbarch_pc_regnum (gdbarch), &regs->pc);
@@ -124,7 +124,7 @@ supply_gregset_reg (struct regcache *regcache,
   xtensa_elf_gregset_t *regs = (xtensa_elf_gregset_t *) gregsetp;
 
   struct gdbarch *gdbarch = regcache->arch ();
-  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
 
   if (regnum == gdbarch_pc_regnum (gdbarch) || regnum == -1)
     regcache->raw_supply (gdbarch_pc_regnum (gdbarch), &regs->pc);
diff --git a/gdb/xtensa-linux-tdep.c b/gdb/xtensa-linux-tdep.c
index 600b59b8894..9602dccc0b0 100644
--- a/gdb/xtensa-linux-tdep.c
+++ b/gdb/xtensa-linux-tdep.c
@@ -99,7 +99,7 @@ xtensa_linux_gdb_signal_to_target (struct gdbarch *gdbarch,
 static void
 xtensa_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
-  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
 
   if (tdep->num_nopriv_regs < tdep->num_regs)
     {
diff --git a/gdb/xtensa-tdep.c b/gdb/xtensa-tdep.c
index f881870e244..ce990958d6d 100644
--- a/gdb/xtensa-tdep.c
+++ b/gdb/xtensa-tdep.c
@@ -116,7 +116,7 @@ static unsigned int xtensa_debug_level = 0;
 static int
 windowing_enabled (struct gdbarch *gdbarch, unsigned int ps)
 {
-  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
 
   /* If we know CALL0 ABI is set explicitly,  say it is Call0.  */
   if (tdep->call_abi == CallAbiCall0Only)
@@ -130,7 +130,7 @@ windowing_enabled (struct gdbarch *gdbarch, unsigned int ps)
 static int
 arreg_number (struct gdbarch *gdbarch, int a_regnum, ULONGEST wb)
 {
-  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
   int arreg;
 
   arreg = a_regnum - tdep->a0_base;
@@ -145,7 +145,7 @@ arreg_number (struct gdbarch *gdbarch, int a_regnum, ULONGEST wb)
 static int
 areg_number (struct gdbarch *gdbarch, int ar_regnum, unsigned int wb)
 {
-  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
   int areg;
 
   areg = ar_regnum - tdep->ar_base;
@@ -226,7 +226,7 @@ static int
 xtensa_find_register_by_name (struct gdbarch *gdbarch, const char *name)
 {
   int i;
-  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
 
   for (i = 0; i < gdbarch_num_cooked_regs (gdbarch); i++)
     if (strcasecmp (tdep->regmap[i].name, name) == 0)
@@ -239,7 +239,7 @@ xtensa_find_register_by_name (struct gdbarch *gdbarch, const char *name)
 static const char *
 xtensa_register_name (struct gdbarch *gdbarch, int regnum)
 {
-  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
 
   /* Return the name stored in the register map.  */
   if (regnum >= 0 && regnum < gdbarch_num_cooked_regs (gdbarch))
@@ -254,7 +254,7 @@ xtensa_register_name (struct gdbarch *gdbarch, int regnum)
 static struct type *
 xtensa_register_type (struct gdbarch *gdbarch, int regnum)
 {
-  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
 
   /* Return signed integer for ARx and Ax registers.  */
   if ((regnum >= tdep->ar_base
@@ -339,7 +339,7 @@ static int
 xtensa_reg_to_regnum (struct gdbarch *gdbarch, int regnum)
 {
   int i;
-  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
 
   if (regnum >= 0 && regnum < 16)
     return tdep->a0_base + regnum;
@@ -542,7 +542,7 @@ xtensa_pseudo_register_read (struct gdbarch *gdbarch,
 {
   DEBUGTRACE ("xtensa_pseudo_register_read (... regnum = %d (%s) ...)\n",
 	      regnum, xtensa_register_name (gdbarch, regnum));
-  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
 
   /* Read aliases a0..a15, if this is a Windowed ABI.  */
   if (tdep->isa_use_windowed_registers
@@ -634,7 +634,7 @@ xtensa_pseudo_register_write (struct gdbarch *gdbarch,
 {
   DEBUGTRACE ("xtensa_pseudo_register_write (... regnum = %d (%s) ...)\n",
 	      regnum, xtensa_register_name (gdbarch, regnum));
-  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
 
   /* Renumber register, if aliases a0..a15 on Windowed ABI.  */
   if (tdep->isa_use_windowed_registers
@@ -767,7 +767,7 @@ xtensa_register_reggroup_p (struct gdbarch *gdbarch,
 			    int regnum,
 			    const struct reggroup *group)
 {
-  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
   xtensa_register_t* reg = &tdep->regmap[regnum];
   xtensa_register_type_t type = reg->type;
   xtensa_register_group_t rg = reg->group;
@@ -821,7 +821,7 @@ xtensa_supply_gregset (const struct regset *regset,
 {
   const xtensa_elf_gregset_t *regs = (const xtensa_elf_gregset_t *) gregs;
   struct gdbarch *gdbarch = rc->arch ();
-  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
   int i;
 
   DEBUGTRACE ("xtensa_supply_gregset (..., regnum==%d, ...)\n", regnum);
@@ -1050,7 +1050,7 @@ static struct frame_id
 xtensa_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
 {
   CORE_ADDR pc, fp;
-  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
 
   /* THIS-FRAME is a dummy frame.  Return a frame ID of that frame.  */
 
@@ -1105,7 +1105,7 @@ xtensa_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR current_pc)
 {
 #define RETURN_FP goto done
 
-  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
   unsigned int fp_regnum = tdep->a0_base + 1;
   CORE_ADDR start_addr;
   xtensa_isa isa;
@@ -1255,7 +1255,7 @@ xtensa_frame_cache (struct frame_info *this_frame, void **this_cache)
   if (windowed)
     {
       LONGEST op1;
-      xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+      xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
 
       /* Get WINDOWBASE, WINDOWSTART, and PS registers.  */
       wb = get_frame_register_unsigned (this_frame, 
@@ -1417,7 +1417,7 @@ xtensa_frame_prev_register (struct frame_info *this_frame,
   struct xtensa_frame_cache *cache;
   ULONGEST saved_reg = 0;
   int done = 1;
-  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
 
   if (*this_cache == NULL)
     *this_cache = xtensa_frame_cache (this_frame, this_cache);
@@ -1546,7 +1546,7 @@ xtensa_extract_return_value (struct type *type,
 
   gdb_assert(len > 0);
 
-  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
   if (tdep->call_abi != CallAbiCall0Only)
     {
       /* First, we have to find the caller window in the register file.  */
@@ -1602,7 +1602,7 @@ xtensa_store_return_value (struct type *type,
 
   DEBUGTRACE ("xtensa_store_return_value (...)\n");
 
-  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
   if (tdep->call_abi != CallAbiCall0Only)
     {
       regcache_raw_read_unsigned 
@@ -1686,7 +1686,7 @@ xtensa_push_dummy_call (struct gdbarch *gdbarch,
 			CORE_ADDR struct_addr)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
   int size, onstack_size;
   gdb_byte *buf = (gdb_byte *) alloca (16);
   CORE_ADDR ra, ps;
@@ -1935,7 +1935,7 @@ xtensa_push_dummy_call (struct gdbarch *gdbarch,
 static int
 xtensa_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
 {
-  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
 
   if (tdep->isa_use_density_instructions)
     return 2;
@@ -2182,7 +2182,7 @@ call0_track_op (struct gdbarch *gdbarch, xtensa_c0reg_t dst[], xtensa_c0reg_t sr
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   unsigned litbase, litaddr, litval;
-  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
 
   switch (opclass)
     {
@@ -2557,7 +2557,7 @@ call0_frame_cache (struct frame_info *this_frame,
   CORE_ADDR body_pc=UINT_MAX;	/* PC, where prologue analysis stopped.  */
   CORE_ADDR sp, fp, ra;
   int fp_regnum = C0_SP, c0_hasfp = 0, c0_frmsz = 0, prev_sp = 0, to_stk;
-  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
  
   sp = get_frame_register_unsigned
     (this_frame, tdep->a0_base + 1);
@@ -2710,7 +2710,7 @@ static int a11_was_saved;
 static void
 execute_l32e (struct gdbarch *gdbarch, int at, int as, int offset, CORE_ADDR wb)
 {
-  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
   int atreg = arreg_number (gdbarch, tdep->a0_base + at, wb);
   int asreg = arreg_number (gdbarch, tdep->a0_base + as, wb);
   CORE_ADDR addr = xtensa_read_register (asreg) + offset;
@@ -2740,7 +2740,7 @@ execute_l32e (struct gdbarch *gdbarch, int at, int as, int offset, CORE_ADDR wb)
 static void
 execute_s32e (struct gdbarch *gdbarch, int at, int as, int offset, CORE_ADDR wb)
 {
-  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
   int atreg = arreg_number (gdbarch, tdep->a0_base + at, wb);
   int asreg = arreg_number (gdbarch, tdep->a0_base + as, wb);
   CORE_ADDR addr = xtensa_read_register (asreg) + offset;
@@ -2774,7 +2774,7 @@ execute_code (struct gdbarch *gdbarch, CORE_ADDR current_pc, CORE_ADDR wb)
   xtensa_opcode opc;
   int insn_num = 0;
   void (*func) (struct gdbarch *, int, int, int, CORE_ADDR);
-  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
 
   uint32_t at, as, offset;
 
@@ -2905,7 +2905,7 @@ xtensa_window_interrupt_frame_cache (struct frame_info *this_frame,
   CORE_ADDR ps, wb, ws, ra;
   int epc1_regnum, i, regnum;
   xtensa_exception_handler_t eh_type;
-  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
 
   /* Read PS, WB, and WS from the hardware. Note that PS register
      must be present, if Windowed ABI is supported.  */
@@ -3019,7 +3019,7 @@ xtensa_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
 
       CORE_ADDR end_func;
 
-      xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+      xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
       if ((tdep->call_abi == CallAbiCall0Only)
 	  && call0_ret (start_pc, prologue_sal.end))
 	return start_pc;
@@ -3041,7 +3041,7 @@ xtensa_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
 static void
 xtensa_verify_config (struct gdbarch *gdbarch)
 {
-  xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
+  xtensa_gdbarch_tdep *tdep = gdbarch_tdep_cast<xtensa_gdbarch_tdep> (gdbarch);
   string_file log;
 
   /* Verify that we got a reasonable number of AREGS.  */
diff --git a/gdb/z80-tdep.c b/gdb/z80-tdep.c
index 6a11883e7b4..d7f4625fbf3 100644
--- a/gdb/z80-tdep.c
+++ b/gdb/z80-tdep.c
@@ -308,7 +308,7 @@ z80_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR pc_beg, CORE_ADDR pc_end,
 		   struct z80_unwind_cache *info)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  z80_gdbarch_tdep *tdep = gdbarch_tdep<z80_gdbarch_tdep> (gdbarch);
+  z80_gdbarch_tdep *tdep = gdbarch_tdep_cast<z80_gdbarch_tdep> (gdbarch);
   int addr_len = tdep->addr_length;
   gdb_byte prologue[32]; /* max prologue is 24 bytes: __interrupt with local array */
   int pos = 0;
@@ -564,7 +564,7 @@ z80_frame_unwind_cache (struct frame_info *this_frame,
   gdb_byte buf[sizeof(void*)];
   struct z80_unwind_cache *info;
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
-  z80_gdbarch_tdep *tdep = gdbarch_tdep<z80_gdbarch_tdep> (gdbarch);
+  z80_gdbarch_tdep *tdep = gdbarch_tdep_cast<z80_gdbarch_tdep> (gdbarch);
   int addr_len = tdep->addr_length;
 
   if (*this_prologue_cache)
@@ -697,7 +697,7 @@ z80_frame_prev_register (struct frame_info *this_frame,
 	  ULONGEST pc;
 	  gdb_byte buf[3];
 	  struct gdbarch *gdbarch = get_frame_arch (this_frame);
-	  z80_gdbarch_tdep *tdep = gdbarch_tdep<z80_gdbarch_tdep> (gdbarch);
+	  z80_gdbarch_tdep *tdep = gdbarch_tdep_cast<z80_gdbarch_tdep> (gdbarch);
 	  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
 	  read_memory (info->saved_regs[Z80_PC_REGNUM].addr (),
@@ -750,7 +750,7 @@ z80_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
     }
   else /* kind is non-RST address, use CALL instead, but it is dungerous */
     {
-      z80_gdbarch_tdep *tdep = gdbarch_tdep<z80_gdbarch_tdep> (gdbarch);
+      z80_gdbarch_tdep *tdep = gdbarch_tdep_cast<z80_gdbarch_tdep> (gdbarch);
       gdb_byte *p = break_insn;
       *p++ = 0xcd;
       *p++ = (kind >> 0) & 0xff;
-- 
2.30.2


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH] Rename gdbarch_tdep template function to gdbarch_tdep_cast for g++ 4.8
  2022-07-23  0:02             ` [PATCH] Rename gdbarch_tdep template function to gdbarch_tdep_cast for g++ 4.8 Mark Wielaard
@ 2022-07-25 11:19               ` Andrew Burgess
  2022-07-25 11:27                 ` Mark Wielaard
  0 siblings, 1 reply; 83+ messages in thread
From: Andrew Burgess @ 2022-07-25 11:19 UTC (permalink / raw)
  To: Mark Wielaard, gdb-patches; +Cc: Mark Wielaard

Mark Wielaard <mark@klomp.org> writes:

> commit 08106042d "gdb: move the type cast into gdbarch_tdep" created
> a template function with the same name as a struct gdbarch_tdep. This
> confused g++ 4.8 believing the struct gdbarch_tdep was an incomplete
> type. Fix this by renaming the template function to gdbarch_tdep_cast.

Honestly, I'm not a fan of the proposed new name.  Using names that end
in _cast should, I think, be reserved for functions that exhibit casting
like behaviour, i.e. take an object, or pointer, and return the same
object, or pointer, converted to some alternative type, which isn't what
we're doing here.

Instead of renaming the function, I'd like to propose that we rename the
structure instead, so 'struct gdbarch_tdep' to 'struct
gdbarch_tdep_base'.

Given the structure is only ever used as a base class, I think the new
name is good, and this allows the function name to be left unchanged.

I tested this on a CentOS VM using g++ 4.8.5, and it seems to build
fine.

Thoughts?

Thanks,
Andrew

---

commit faff6041468dd13b26c5380862752f1039a92dc9
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Mon Jul 25 12:07:11 2022 +0100

    gdb: rename gdbarch_tdep struct to fix g++ 4.8 build
    
    After this commit:
    
      commit 08106042d9f5fdff60c129bf33190639f1a98b2a
      Date:   Thu May 19 13:20:17 2022 +0100
    
          gdb: move the type cast into gdbarch_tdep
    
    GDB would no longer build using g++ 4.8.  The issue appears to be some
    confusion as we have 'struct gdbarch_tdep', but also a templated
    function called 'gdbarch_tdep'.  Prior to the above commit the
    gdbarch_tdep function was not templated, and this compiled just fine.
    
    To resolve this confusion I propose renaming 'struct gdbarch_tdep' to
    'struct gdbarch_tdep_base'.  This rename better represents that the
    struct is only ever used as a base class, and removes the overloading
    of the name, which allows GDB to build with g++ 4.8.

diff --git a/gdb/aarch64-tdep.h b/gdb/aarch64-tdep.h
index b85a3d33cc9..5bdd733dce3 100644
--- a/gdb/aarch64-tdep.h
+++ b/gdb/aarch64-tdep.h
@@ -60,7 +60,7 @@ struct regset;
 #define AARCH64_DISPLACED_MODIFIED_INSNS 1
 
 /* Target-dependent structure in gdbarch.  */
-struct aarch64_gdbarch_tdep : gdbarch_tdep
+struct aarch64_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Lowest address at which instructions will appear.  */
   CORE_ADDR lowest_pc = 0;
diff --git a/gdb/alpha-tdep.h b/gdb/alpha-tdep.h
index 420ea1adc9c..bc4a8407249 100644
--- a/gdb/alpha-tdep.h
+++ b/gdb/alpha-tdep.h
@@ -70,7 +70,7 @@ struct regcache;
 #define ALPHA_NUM_ARG_REGS   6
 
 /* Target-dependent structure in gdbarch.  */
-struct alpha_gdbarch_tdep : gdbarch_tdep
+struct alpha_gdbarch_tdep : gdbarch_tdep_base
 {
   CORE_ADDR vm_min_address = 0;	/* Used by alpha_heuristic_proc_start.  */
 
diff --git a/gdb/arc-tdep.h b/gdb/arc-tdep.h
index 53e5d8476fc..eba435f62f0 100644
--- a/gdb/arc-tdep.h
+++ b/gdb/arc-tdep.h
@@ -121,7 +121,7 @@ extern bool arc_debug;
 
 /* Target-dependent information.  */
 
-struct arc_gdbarch_tdep : gdbarch_tdep
+struct arc_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Offset to PC value in jump buffer.  If this is negative, longjmp
      support will be disabled.  */
diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index 360b8d694be..4e55b2797b9 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -1200,7 +1200,7 @@ gdbarch_free (struct gdbarch *arch)
 
 /* See gdbarch.h.  */
 
-struct gdbarch_tdep *
+struct gdbarch_tdep_base *
 gdbarch_tdep_1 (struct gdbarch *gdbarch)
 {
   if (gdbarch_debug >= 2)
diff --git a/gdb/arm-tdep.h b/gdb/arm-tdep.h
index 0fc4774a20c..67dd1151da4 100644
--- a/gdb/arm-tdep.h
+++ b/gdb/arm-tdep.h
@@ -87,7 +87,7 @@ enum struct_return
 };
 
 /* Target-dependent structure in gdbarch.  */
-struct arm_gdbarch_tdep : gdbarch_tdep
+struct arm_gdbarch_tdep : gdbarch_tdep_base
 {
   /* The ABI for this architecture.  It should never be set to
      ARM_ABI_AUTO.  */
diff --git a/gdb/avr-tdep.c b/gdb/avr-tdep.c
index 4722f7ee748..357f5bb8f2d 100644
--- a/gdb/avr-tdep.c
+++ b/gdb/avr-tdep.c
@@ -189,7 +189,7 @@ struct avr_unwind_cache
   trad_frame_saved_reg *saved_regs;
 };
 
-struct avr_gdbarch_tdep : gdbarch_tdep
+struct avr_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Number of bytes stored to the stack by call instructions.
      2 bytes for avr1-5 and avrxmega1-5, 3 bytes for avr6 and avrxmega6-7.  */
diff --git a/gdb/bfin-tdep.h b/gdb/bfin-tdep.h
index b7e3b9b327c..267149684e0 100644
--- a/gdb/bfin-tdep.h
+++ b/gdb/bfin-tdep.h
@@ -96,7 +96,7 @@ enum bfin_abi
 };
 
 /* Target-dependent structure in gdbarch.  */
-struct bfin_gdbarch_tdep : gdbarch_tdep
+struct bfin_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Which ABI is in use?  */
   enum bfin_abi bfin_abi {};
diff --git a/gdb/bpf-tdep.c b/gdb/bpf-tdep.c
index 09030cf8fa1..a5df478063c 100644
--- a/gdb/bpf-tdep.c
+++ b/gdb/bpf-tdep.c
@@ -58,7 +58,7 @@ enum bpf_regnum
 #define BPF_NUM_REGS	(BPF_PC_REGNUM + 1)
 
 /* Target-dependent structure in gdbarch.  */
-struct bpf_gdbarch_tdep : gdbarch_tdep
+struct bpf_gdbarch_tdep : gdbarch_tdep_base
 {
 };
 
diff --git a/gdb/cris-tdep.h b/gdb/cris-tdep.h
index 0b1801afa04..981515a4e9f 100644
--- a/gdb/cris-tdep.h
+++ b/gdb/cris-tdep.h
@@ -26,7 +26,7 @@
 #include "gdbarch.h"
 
 /* CRIS architecture specific information.  */
-struct cris_gdbarch_tdep : gdbarch_tdep
+struct cris_gdbarch_tdep : gdbarch_tdep_base
 {
   unsigned int cris_version = 0;
   const char *cris_mode = nullptr;
diff --git a/gdb/csky-tdep.h b/gdb/csky-tdep.h
index 4cfc0a5d086..54000ab8287 100644
--- a/gdb/csky-tdep.h
+++ b/gdb/csky-tdep.h
@@ -31,7 +31,7 @@ enum lr_type_t
 };
 
 /* Target-dependent structure in gdbarch.  */
-struct csky_gdbarch_tdep : gdbarch_tdep
+struct csky_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Save FPU, VDSP ABI.  */
   unsigned int fpu_abi;
diff --git a/gdb/frv-tdep.c b/gdb/frv-tdep.c
index 34f437764a9..55a6cfd9618 100644
--- a/gdb/frv-tdep.c
+++ b/gdb/frv-tdep.c
@@ -68,7 +68,7 @@ struct frv_unwind_cache		/* was struct frame_extra_info */
    of structures, each of which gives all the necessary info for one
    register.  Don't stick parallel arrays in here --- that's so
    Fortran.  */
-struct frv_gdbarch_tdep : gdbarch_tdep
+struct frv_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Which ABI is in use?  */
   enum frv_abi frv_abi {};
diff --git a/gdb/ft32-tdep.h b/gdb/ft32-tdep.h
index e66a417198e..e9befaba9d4 100644
--- a/gdb/ft32-tdep.h
+++ b/gdb/ft32-tdep.h
@@ -22,7 +22,7 @@
 
 #include "gdbarch.h"
 
-struct ft32_gdbarch_tdep : gdbarch_tdep
+struct ft32_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Type for a pointer to a function.  Used for the type of PC.  */
   struct type *pc_type = nullptr;
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index 5d14aec1455..d4ea5d33c9c 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -43,7 +43,7 @@ struct gdbarch
   const struct target_desc * target_desc;
 
   /* target specific vector.  */
-  struct gdbarch_tdep *tdep;
+  struct gdbarch_tdep_base *tdep;
   gdbarch_dump_tdep_ftype *dump_tdep;
 
   /* per-architecture data-pointers.  */
@@ -258,7 +258,7 @@ struct gdbarch
 
 struct gdbarch *
 gdbarch_alloc (const struct gdbarch_info *info,
-	       struct gdbarch_tdep *tdep)
+	       struct gdbarch_tdep_base *tdep)
 {
   struct gdbarch *gdbarch;
 
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index 16c73915c64..c439ac1dc47 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -63,9 +63,9 @@ struct inferior;
    destructor ensures the class has RTTI information, which allows
    gdb::checked_static_cast to be used, the gdbarch_tdep the function.  */
 
-struct gdbarch_tdep
+struct gdbarch_tdep_base
 {
-  virtual ~gdbarch_tdep() = default;
+  virtual ~gdbarch_tdep_base() = default;
 };
 
 /* The architecture associated with the inferior through the
@@ -153,7 +153,7 @@ using read_core_file_mappings_loop_ftype =
 /* An internal function that should _only_ be called from gdbarch_tdep.
    Returns the gdbarch_tdep field held within GDBARCH.  */
 
-extern struct gdbarch_tdep *gdbarch_tdep_1 (struct gdbarch *gdbarch);
+extern struct gdbarch_tdep_base *gdbarch_tdep_1 (struct gdbarch *gdbarch);
 
 /* Return the gdbarch_tdep object held within GDBARCH cast to the type
    TDepType, which should be a sub-class of gdbarch_tdep.  There is no
@@ -164,7 +164,7 @@ template<typename TDepType>
 static inline TDepType *
 gdbarch_tdep (struct gdbarch *gdbarch)
 {
-  struct gdbarch_tdep *tdep = gdbarch_tdep_1 (gdbarch);
+  struct gdbarch_tdep_base *tdep = gdbarch_tdep_1 (gdbarch);
   return gdb::checked_static_cast<TDepType *> (tdep);
 }
 
@@ -293,7 +293,7 @@ extern struct gdbarch_list *gdbarch_list_lookup_by_info (struct gdbarch_list *ar
    parameters.  set_gdbarch_*() functions are called to complete the
    initialization of the object.  */
 
-extern struct gdbarch *gdbarch_alloc (const struct gdbarch_info *info, struct gdbarch_tdep *tdep);
+extern struct gdbarch *gdbarch_alloc (const struct gdbarch_info *info, struct gdbarch_tdep_base *tdep);
 
 
 /* Helper function.  Free a partially-constructed ``struct gdbarch''.
diff --git a/gdb/gdbarch.py b/gdb/gdbarch.py
index 8956a9c38aa..bb08081af5a 100755
--- a/gdb/gdbarch.py
+++ b/gdb/gdbarch.py
@@ -267,7 +267,7 @@ with open("gdbarch.c", "w") as f:
         print(f"  {c.type} {c.name};", file=f)
     print(file=f)
     print("  /* target specific vector.  */", file=f)
-    print("  struct gdbarch_tdep *tdep;", file=f)
+    print("  struct gdbarch_tdep_base *tdep;", file=f)
     print("  gdbarch_dump_tdep_ftype *dump_tdep;", file=f)
     print(file=f)
     print("  /* per-architecture data-pointers.  */", file=f)
@@ -290,7 +290,7 @@ with open("gdbarch.c", "w") as f:
     print(file=f)
     print("struct gdbarch *", file=f)
     print("gdbarch_alloc (const struct gdbarch_info *info,", file=f)
-    print("	       struct gdbarch_tdep *tdep)", file=f)
+    print("	       struct gdbarch_tdep_base *tdep)", file=f)
     print("{", file=f)
     print("  struct gdbarch *gdbarch;", file=f)
     print("", file=f)
diff --git a/gdb/hppa-tdep.h b/gdb/hppa-tdep.h
index f1e24a272c4..c2c9e0e0b5e 100644
--- a/gdb/hppa-tdep.h
+++ b/gdb/hppa-tdep.h
@@ -84,7 +84,7 @@ enum hppa_regnum
 #define HPPA_INSN_SIZE 4
 
 /* Target-dependent structure in gdbarch.  */
-struct hppa_gdbarch_tdep : gdbarch_tdep
+struct hppa_gdbarch_tdep : gdbarch_tdep_base
 {
   /* The number of bytes in an address.  For now, this field is designed
      to allow us to differentiate hppa32 from hppa64 targets.  */
diff --git a/gdb/i386-tdep.h b/gdb/i386-tdep.h
index a8067cf6b6c..cd77e0308e0 100644
--- a/gdb/i386-tdep.h
+++ b/gdb/i386-tdep.h
@@ -57,7 +57,7 @@ enum struct_return
 };
 
 /* i386 architecture specific information.  */
-struct i386_gdbarch_tdep : gdbarch_tdep
+struct i386_gdbarch_tdep : gdbarch_tdep_base
 {
   /* General-purpose registers.  */
   int *gregset_reg_offset = 0;
diff --git a/gdb/ia64-tdep.h b/gdb/ia64-tdep.h
index 675d0d871b2..f06974fd296 100644
--- a/gdb/ia64-tdep.h
+++ b/gdb/ia64-tdep.h
@@ -229,7 +229,7 @@ struct ia64_infcall_ops
   void (*set_function_addr) (struct regcache *regcache, CORE_ADDR func_addr);
 };
 
-struct ia64_gdbarch_tdep : gdbarch_tdep
+struct ia64_gdbarch_tdep : gdbarch_tdep_base
 {
   CORE_ADDR (*sigcontext_register_address) (struct gdbarch *, CORE_ADDR, int)
     = nullptr;
diff --git a/gdb/lm32-tdep.c b/gdb/lm32-tdep.c
index 4a781c394e9..4cbff537fab 100644
--- a/gdb/lm32-tdep.c
+++ b/gdb/lm32-tdep.c
@@ -43,7 +43,7 @@
 #define LM32_REG2(insn)         ((insn >> 11) & 0x1f)
 #define LM32_IMM16(insn)        ((((long)insn & 0xffff) << 16) >> 16)
 
-struct lm32_gdbarch_tdep : gdbarch_tdep
+struct lm32_gdbarch_tdep : gdbarch_tdep_base
 {
   /* gdbarch target dependent data here.  Currently unused for LM32.  */
 };
diff --git a/gdb/loongarch-tdep.h b/gdb/loongarch-tdep.h
index e35b6cf4c7a..c5527f7d148 100644
--- a/gdb/loongarch-tdep.h
+++ b/gdb/loongarch-tdep.h
@@ -32,7 +32,7 @@ extern const struct regset loongarch_gregset;
 extern const struct regset loongarch_fpregset;
 
 /* Target-dependent structure in gdbarch.  */
-struct loongarch_gdbarch_tdep : gdbarch_tdep
+struct loongarch_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Features about the abi that impact how the gdbarch is configured.  */
   struct loongarch_gdbarch_features abi_features;
diff --git a/gdb/m32c-tdep.c b/gdb/m32c-tdep.c
index 37456d16cb3..30f716b6969 100644
--- a/gdb/m32c-tdep.c
+++ b/gdb/m32c-tdep.c
@@ -96,7 +96,7 @@ struct m32c_reg
 #define M32C_MAX_DWARF_REGNUM (40)
 
 
-struct m32c_gdbarch_tdep : gdbarch_tdep
+struct m32c_gdbarch_tdep : gdbarch_tdep_base
 {
   /* All the registers for this variant, indexed by GDB register
      number, and the number of registers present.  */
diff --git a/gdb/m32r-tdep.h b/gdb/m32r-tdep.h
index 1fa143adc74..09d5b245770 100644
--- a/gdb/m32r-tdep.h
+++ b/gdb/m32r-tdep.h
@@ -22,7 +22,7 @@
 
 #include "gdbarch.h"
 
-struct m32r_gdbarch_tdep : gdbarch_tdep
+struct m32r_gdbarch_tdep : gdbarch_tdep_base
 {
   /* gdbarch target dependent data here.  Currently unused for M32R.  */
 };
diff --git a/gdb/m68hc11-tdep.c b/gdb/m68hc11-tdep.c
index 9eb18b937be..7ea1f9a5b91 100644
--- a/gdb/m68hc11-tdep.c
+++ b/gdb/m68hc11-tdep.c
@@ -124,7 +124,7 @@ enum insn_return_kind {
 #define M68HC12_HARD_PC_REGNUM  (SOFT_D32_REGNUM+1)
 
 struct insn_sequence;
-struct m68gc11_gdbarch_tdep : gdbarch_tdep
+struct m68gc11_gdbarch_tdep : gdbarch_tdep_base
   {
     /* Stack pointer correction value.  For 68hc11, the stack pointer points
        to the next push location.  An offset of 1 must be applied to obtain
diff --git a/gdb/m68k-tdep.h b/gdb/m68k-tdep.h
index c70a26e8554..785e3fdb84f 100644
--- a/gdb/m68k-tdep.h
+++ b/gdb/m68k-tdep.h
@@ -69,7 +69,7 @@ enum m68k_flavour
 
 /* Target-dependent structure in gdbarch.  */
 
-struct m68k_gdbarch_tdep : gdbarch_tdep
+struct m68k_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Offset to PC value in the jump buffer.  If this is negative,
      longjmp support will be disabled.  */
diff --git a/gdb/mep-tdep.c b/gdb/mep-tdep.c
index d5ba78c6df9..170b4b07460 100644
--- a/gdb/mep-tdep.c
+++ b/gdb/mep-tdep.c
@@ -116,7 +116,7 @@
      options are present on the current processor.  */
 
 
-struct mep_gdbarch_tdep : gdbarch_tdep
+struct mep_gdbarch_tdep : gdbarch_tdep_base
 {
   /* A CGEN cpu descriptor for this BFD architecture and machine.
 
diff --git a/gdb/microblaze-tdep.h b/gdb/microblaze-tdep.h
index 4d90e8785dc..48b2581fcc7 100644
--- a/gdb/microblaze-tdep.h
+++ b/gdb/microblaze-tdep.h
@@ -23,7 +23,7 @@
 #include "gdbarch.h"
 
 /* Microblaze architecture-specific information.  */
-struct microblaze_gdbarch_tdep : gdbarch_tdep
+struct microblaze_gdbarch_tdep : gdbarch_tdep_base
 {
 };
 
diff --git a/gdb/mips-tdep.h b/gdb/mips-tdep.h
index 4d2664d4273..24ed678a521 100644
--- a/gdb/mips-tdep.h
+++ b/gdb/mips-tdep.h
@@ -93,7 +93,7 @@ enum mips_fpu_type
 };
 
 /* MIPS specific per-architecture information.  */
-struct mips_gdbarch_tdep : gdbarch_tdep
+struct mips_gdbarch_tdep : gdbarch_tdep_base
 {
   /* from the elf header */
   int elf_flags = 0;
diff --git a/gdb/mn10300-tdep.h b/gdb/mn10300-tdep.h
index 87b861ead90..dacfb9d2948 100644
--- a/gdb/mn10300-tdep.h
+++ b/gdb/mn10300-tdep.h
@@ -76,7 +76,7 @@ enum frame_kind {
 };
 
 /* mn10300 private data.  */
-struct mn10300_gdbarch_tdep : gdbarch_tdep
+struct mn10300_gdbarch_tdep : gdbarch_tdep_base
 {
   int am33_mode;
 };
diff --git a/gdb/moxie-tdep.h b/gdb/moxie-tdep.h
index 91d007fd723..69bb5d0fa3a 100644
--- a/gdb/moxie-tdep.h
+++ b/gdb/moxie-tdep.h
@@ -22,7 +22,7 @@
 
 #include "gdbarch.h"
 
-struct moxie_gdbarch_tdep : gdbarch_tdep
+struct moxie_gdbarch_tdep : gdbarch_tdep_base
 {
   /* gdbarch target dependent data here.  Currently unused for MOXIE.  */
 };
diff --git a/gdb/msp430-tdep.c b/gdb/msp430-tdep.c
index 4ae8b3d5626..cf4106d1a34 100644
--- a/gdb/msp430-tdep.c
+++ b/gdb/msp430-tdep.c
@@ -105,7 +105,7 @@ enum
 
 /* Architecture specific data.  */
 
-struct msp430_gdbarch_tdep : gdbarch_tdep
+struct msp430_gdbarch_tdep : gdbarch_tdep_base
 {
   /* The ELF header flags specify the multilib used.  */
   int elf_flags = 0;
diff --git a/gdb/nds32-tdep.h b/gdb/nds32-tdep.h
index 2cabd6a173f..e68017b4667 100644
--- a/gdb/nds32-tdep.h
+++ b/gdb/nds32-tdep.h
@@ -42,7 +42,7 @@ enum nds32_regnum
   NDS32_FD0_REGNUM = NDS32_NUM_REGS,
 };
 
-struct nds32_gdbarch_tdep : gdbarch_tdep
+struct nds32_gdbarch_tdep : gdbarch_tdep_base
 {
   /* The guessed FPU configuration.  */
   int fpu_freg = 0;
diff --git a/gdb/nios2-tdep.h b/gdb/nios2-tdep.h
index b8913ed1baa..cbf2599f5c0 100644
--- a/gdb/nios2-tdep.h
+++ b/gdb/nios2-tdep.h
@@ -69,7 +69,7 @@
 #define NIOS2_CDX_OPCODE_SIZE 2
 
 /* Target-dependent structure in gdbarch.  */
-struct nios2_gdbarch_tdep : gdbarch_tdep
+struct nios2_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Assumes FRAME is stopped at a syscall (trap) instruction; returns
      the expected next PC.  */
diff --git a/gdb/or1k-tdep.c b/gdb/or1k-tdep.c
index 4699b755d42..360a7cb36c1 100644
--- a/gdb/or1k-tdep.c
+++ b/gdb/or1k-tdep.c
@@ -63,7 +63,7 @@ show_or1k_debug (struct ui_file *file, int from_tty,
 
 /* The target-dependent structure for gdbarch.  */
 
-struct or1k_gdbarch_tdep : gdbarch_tdep
+struct or1k_gdbarch_tdep : gdbarch_tdep_base
 {
   int bytes_per_word = 0;
   int bytes_per_address = 0;
diff --git a/gdb/ppc-tdep.h b/gdb/ppc-tdep.h
index 80a7dd080a2..44f63b145c6 100644
--- a/gdb/ppc-tdep.h
+++ b/gdb/ppc-tdep.h
@@ -205,7 +205,7 @@ enum powerpc_long_double_abi
   POWERPC_LONG_DOUBLE_LAST
 };
 
-struct ppc_gdbarch_tdep : gdbarch_tdep
+struct ppc_gdbarch_tdep : gdbarch_tdep_base
   {
     int wordsize = 0;		/* Size in bytes of fixed-point word.  */
     int soft_float = 0;		/* Avoid FP registers for arguments?  */
diff --git a/gdb/riscv-tdep.h b/gdb/riscv-tdep.h
index ac4b4b7144d..826a002ef92 100644
--- a/gdb/riscv-tdep.h
+++ b/gdb/riscv-tdep.h
@@ -76,7 +76,7 @@ enum
 };
 
 /* RISC-V specific per-architecture information.  */
-struct riscv_gdbarch_tdep : gdbarch_tdep
+struct riscv_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Features about the target hardware that impact how the gdbarch is
      configured.  Two gdbarch instances are compatible only if this field
diff --git a/gdb/rl78-tdep.c b/gdb/rl78-tdep.c
index 2462e7a191d..be668bfa6fe 100644
--- a/gdb/rl78-tdep.c
+++ b/gdb/rl78-tdep.c
@@ -210,7 +210,7 @@ enum
 
 /* Architecture specific data.  */
 
-struct rl78_gdbarch_tdep : gdbarch_tdep
+struct rl78_gdbarch_tdep : gdbarch_tdep_base
 {
   /* The ELF header flags specify the multilib used.  */
   int elf_flags = 0;
diff --git a/gdb/rx-tdep.c b/gdb/rx-tdep.c
index c67d4057195..989d90096bd 100644
--- a/gdb/rx-tdep.c
+++ b/gdb/rx-tdep.c
@@ -69,7 +69,7 @@ enum rx_frame_type {
 };
 
 /* Architecture specific data.  */
-struct rx_gdbarch_tdep : gdbarch_tdep
+struct rx_gdbarch_tdep : gdbarch_tdep_base
 {
   /* The ELF header flags specify the multilib used.  */
   int elf_flags = 0;
diff --git a/gdb/s12z-tdep.c b/gdb/s12z-tdep.c
index 4e33faaea9a..5e49c615f1b 100644
--- a/gdb/s12z-tdep.c
+++ b/gdb/s12z-tdep.c
@@ -458,7 +458,7 @@ constexpr gdb_byte s12z_break_insn[] = {0x00};
 
 typedef BP_MANIPULATION (s12z_break_insn) s12z_breakpoint;
 
-struct s12z_gdbarch_tdep : gdbarch_tdep
+struct s12z_gdbarch_tdep : gdbarch_tdep_base
 {
 };
 
diff --git a/gdb/s390-tdep.h b/gdb/s390-tdep.h
index ac08da1c7c8..f51423cb018 100644
--- a/gdb/s390-tdep.h
+++ b/gdb/s390-tdep.h
@@ -38,7 +38,7 @@ enum s390_vector_abi_kind
 
 /* The tdep structure.  */
 
-struct s390_gdbarch_tdep : gdbarch_tdep
+struct s390_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Target description.  */
   const struct target_desc *tdesc = nullptr;
diff --git a/gdb/sh-tdep.h b/gdb/sh-tdep.h
index bc0383fb075..54aa7ff828f 100644
--- a/gdb/sh-tdep.h
+++ b/gdb/sh-tdep.h
@@ -91,7 +91,7 @@ struct sh_corefile_regmap
   unsigned int offset;
 };
 
-struct sh_gdbarch_tdep : gdbarch_tdep
+struct sh_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Non-NULL when debugging from a core file.  Provides the offset
      where each general-purpose register is stored inside the associated
diff --git a/gdb/sparc-tdep.h b/gdb/sparc-tdep.h
index 36ff5349a0a..f2070f10e12 100644
--- a/gdb/sparc-tdep.h
+++ b/gdb/sparc-tdep.h
@@ -57,7 +57,7 @@ struct sparc_fpregmap
 
 /* SPARC architecture-specific information.  */
 
-struct sparc_gdbarch_tdep : gdbarch_tdep
+struct sparc_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Register numbers for the PN and nPC registers.  The definitions
      for (64-bit) UltraSPARC differ from the (32-bit) SPARC
diff --git a/gdb/tic6x-tdep.h b/gdb/tic6x-tdep.h
index d9b9644f8df..ebfd6e686fa 100644
--- a/gdb/tic6x-tdep.h
+++ b/gdb/tic6x-tdep.h
@@ -46,7 +46,7 @@ extern const gdb_byte tic6x_bkpt_illegal_opcode_be[];
 extern const gdb_byte tic6x_bkpt_illegal_opcode_le[];
 
 /* Target-dependent structure in gdbarch.  */
-struct tic6x_gdbarch_tdep : gdbarch_tdep
+struct tic6x_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Return the expected next PC if FRAME is stopped at a syscall
      instruction.  */
diff --git a/gdb/v850-tdep.c b/gdb/v850-tdep.c
index 4de5faa6a47..f7094e37a92 100644
--- a/gdb/v850-tdep.c
+++ b/gdb/v850-tdep.c
@@ -265,7 +265,7 @@ enum v850_abi
 
 /* Architecture specific data.  */
 
-struct v850_gdbarch_tdep : gdbarch_tdep
+struct v850_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Fields from the ELF header.  */
   int e_flags = 0;
diff --git a/gdb/xtensa-tdep.h b/gdb/xtensa-tdep.h
index 1840ef98b49..da7a7080afd 100644
--- a/gdb/xtensa-tdep.h
+++ b/gdb/xtensa-tdep.h
@@ -167,7 +167,7 @@ struct ctype_cache
 
 /*  Xtensa-specific target dependencies.  */
 
-struct xtensa_gdbarch_tdep : gdbarch_tdep
+struct xtensa_gdbarch_tdep : gdbarch_tdep_base
 {
   xtensa_gdbarch_tdep (xtensa_register_t *regmap)
     : regmap (regmap)
diff --git a/gdb/z80-tdep.c b/gdb/z80-tdep.c
index 6a11883e7b4..1ab375c5014 100644
--- a/gdb/z80-tdep.c
+++ b/gdb/z80-tdep.c
@@ -55,7 +55,7 @@
      next frame - frame of caller, which has called current function
 */
 
-struct z80_gdbarch_tdep : gdbarch_tdep
+struct z80_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Number of bytes used for address:
       2 bytes for all Z80 family


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH] Rename gdbarch_tdep template function to gdbarch_tdep_cast for g++ 4.8
  2022-07-25 11:19               ` Andrew Burgess
@ 2022-07-25 11:27                 ` Mark Wielaard
  2022-07-26 11:05                   ` Andrew Burgess
  0 siblings, 1 reply; 83+ messages in thread
From: Mark Wielaard @ 2022-07-25 11:27 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

Hi Andrew,

On Mon, 2022-07-25 at 12:19 +0100, Andrew Burgess wrote:
> Mark Wielaard <mark@klomp.org> writes:
> 
> > commit 08106042d "gdb: move the type cast into gdbarch_tdep" created
> > a template function with the same name as a struct gdbarch_tdep. This
> > confused g++ 4.8 believing the struct gdbarch_tdep was an incomplete
> > type. Fix this by renaming the template function to gdbarch_tdep_cast.
> 
> Honestly, I'm not a fan of the proposed new name.  Using names that end
> in _cast should, I think, be reserved for functions that exhibit casting
> like behaviour, i.e. take an object, or pointer, and return the same
> object, or pointer, converted to some alternative type, which isn't what
> we're doing here.
> 
> Instead of renaming the function, I'd like to propose that we rename the
> structure instead, so 'struct gdbarch_tdep' to 'struct
> gdbarch_tdep_base'.
> 
> Given the structure is only ever used as a base class, I think the new
> name is good, and this allows the function name to be left unchanged.
> 
> I tested this on a CentOS VM using g++ 4.8.5, and it seems to build
> fine.
> 
> Thoughts?

I agree with your reasoning. And now that you mention it I don't know
why I did rename the "cast" function instead of the base struct name. I
like your patch better.

Thanks,

Mark


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH] Rename gdbarch_tdep template function to gdbarch_tdep_cast for g++ 4.8
  2022-07-25 11:27                 ` Mark Wielaard
@ 2022-07-26 11:05                   ` Andrew Burgess
  0 siblings, 0 replies; 83+ messages in thread
From: Andrew Burgess @ 2022-07-26 11:05 UTC (permalink / raw)
  To: Mark Wielaard, gdb-patches

Mark Wielaard <mark@klomp.org> writes:

> Hi Andrew,
>
> On Mon, 2022-07-25 at 12:19 +0100, Andrew Burgess wrote:
>> Mark Wielaard <mark@klomp.org> writes:
>> 
>> > commit 08106042d "gdb: move the type cast into gdbarch_tdep" created
>> > a template function with the same name as a struct gdbarch_tdep. This
>> > confused g++ 4.8 believing the struct gdbarch_tdep was an incomplete
>> > type. Fix this by renaming the template function to gdbarch_tdep_cast.
>> 
>> Honestly, I'm not a fan of the proposed new name.  Using names that end
>> in _cast should, I think, be reserved for functions that exhibit casting
>> like behaviour, i.e. take an object, or pointer, and return the same
>> object, or pointer, converted to some alternative type, which isn't what
>> we're doing here.
>> 
>> Instead of renaming the function, I'd like to propose that we rename the
>> structure instead, so 'struct gdbarch_tdep' to 'struct
>> gdbarch_tdep_base'.
>> 
>> Given the structure is only ever used as a base class, I think the new
>> name is good, and this allows the function name to be left unchanged.
>> 
>> I tested this on a CentOS VM using g++ 4.8.5, and it seems to build
>> fine.
>> 
>> Thoughts?
>
> I agree with your reasoning. And now that you mention it I don't know
> why I did rename the "cast" function instead of the base struct name. I
> like your patch better.

Thanks.  I pushed the patch below, which also updates a couple of
related comments.

Thanks,
Andrew

---

commit ab25d9bbe4a04aefb47d2514b4b02e6035ff769e
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Mon Jul 25 12:07:11 2022 +0100

    gdb: rename gdbarch_tdep struct to fix g++ 4.8 build
    
    After the commit:
    
      commit 08106042d9f5fdff60c129bf33190639f1a98b2a
      Date:   Thu May 19 13:20:17 2022 +0100
    
          gdb: move the type cast into gdbarch_tdep
    
    GDB would no longer build using g++ 4.8.  The issue appears to be some
    confusion caused by GDB having 'struct gdbarch_tdep', but also a
    templated function called 'gdbarch_tdep'.  Prior to the above commit
    the gdbarch_tdep function was not templated, and this compiled just
    fine.  Note that the above commit compiles just fine with later
    versions of g++, so this issue was clearly fixed at some point, though
    I've not tried to track down exactly when.
    
    In this commit I propose to fix the g++ 4.8 build problem by renaming
    'struct gdbarch_tdep' to 'struct gdbarch_tdep_base'.  This rename
    better represents that the struct is only ever used as a base class,
    and removes the overloading of the name, which allows GDB to build
    with g++ 4.8.
    
    I've also updated the comment on 'struct gdbarch_tdep_base' to fix a
    typo, and the comment on the 'gdbarch_tdep' function, to mention that
    in maintainer mode a run-time type check is performed.

diff --git a/gdb/aarch64-tdep.h b/gdb/aarch64-tdep.h
index b85a3d33cc9..5bdd733dce3 100644
--- a/gdb/aarch64-tdep.h
+++ b/gdb/aarch64-tdep.h
@@ -60,7 +60,7 @@ struct regset;
 #define AARCH64_DISPLACED_MODIFIED_INSNS 1
 
 /* Target-dependent structure in gdbarch.  */
-struct aarch64_gdbarch_tdep : gdbarch_tdep
+struct aarch64_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Lowest address at which instructions will appear.  */
   CORE_ADDR lowest_pc = 0;
diff --git a/gdb/alpha-tdep.h b/gdb/alpha-tdep.h
index 420ea1adc9c..bc4a8407249 100644
--- a/gdb/alpha-tdep.h
+++ b/gdb/alpha-tdep.h
@@ -70,7 +70,7 @@ struct regcache;
 #define ALPHA_NUM_ARG_REGS   6
 
 /* Target-dependent structure in gdbarch.  */
-struct alpha_gdbarch_tdep : gdbarch_tdep
+struct alpha_gdbarch_tdep : gdbarch_tdep_base
 {
   CORE_ADDR vm_min_address = 0;	/* Used by alpha_heuristic_proc_start.  */
 
diff --git a/gdb/arc-tdep.h b/gdb/arc-tdep.h
index 53e5d8476fc..eba435f62f0 100644
--- a/gdb/arc-tdep.h
+++ b/gdb/arc-tdep.h
@@ -121,7 +121,7 @@ extern bool arc_debug;
 
 /* Target-dependent information.  */
 
-struct arc_gdbarch_tdep : gdbarch_tdep
+struct arc_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Offset to PC value in jump buffer.  If this is negative, longjmp
      support will be disabled.  */
diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index 360b8d694be..4e55b2797b9 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -1200,7 +1200,7 @@ gdbarch_free (struct gdbarch *arch)
 
 /* See gdbarch.h.  */
 
-struct gdbarch_tdep *
+struct gdbarch_tdep_base *
 gdbarch_tdep_1 (struct gdbarch *gdbarch)
 {
   if (gdbarch_debug >= 2)
diff --git a/gdb/arm-tdep.h b/gdb/arm-tdep.h
index 0fc4774a20c..67dd1151da4 100644
--- a/gdb/arm-tdep.h
+++ b/gdb/arm-tdep.h
@@ -87,7 +87,7 @@ enum struct_return
 };
 
 /* Target-dependent structure in gdbarch.  */
-struct arm_gdbarch_tdep : gdbarch_tdep
+struct arm_gdbarch_tdep : gdbarch_tdep_base
 {
   /* The ABI for this architecture.  It should never be set to
      ARM_ABI_AUTO.  */
diff --git a/gdb/avr-tdep.c b/gdb/avr-tdep.c
index 4722f7ee748..357f5bb8f2d 100644
--- a/gdb/avr-tdep.c
+++ b/gdb/avr-tdep.c
@@ -189,7 +189,7 @@ struct avr_unwind_cache
   trad_frame_saved_reg *saved_regs;
 };
 
-struct avr_gdbarch_tdep : gdbarch_tdep
+struct avr_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Number of bytes stored to the stack by call instructions.
      2 bytes for avr1-5 and avrxmega1-5, 3 bytes for avr6 and avrxmega6-7.  */
diff --git a/gdb/bfin-tdep.h b/gdb/bfin-tdep.h
index b7e3b9b327c..267149684e0 100644
--- a/gdb/bfin-tdep.h
+++ b/gdb/bfin-tdep.h
@@ -96,7 +96,7 @@ enum bfin_abi
 };
 
 /* Target-dependent structure in gdbarch.  */
-struct bfin_gdbarch_tdep : gdbarch_tdep
+struct bfin_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Which ABI is in use?  */
   enum bfin_abi bfin_abi {};
diff --git a/gdb/bpf-tdep.c b/gdb/bpf-tdep.c
index 09030cf8fa1..a5df478063c 100644
--- a/gdb/bpf-tdep.c
+++ b/gdb/bpf-tdep.c
@@ -58,7 +58,7 @@ enum bpf_regnum
 #define BPF_NUM_REGS	(BPF_PC_REGNUM + 1)
 
 /* Target-dependent structure in gdbarch.  */
-struct bpf_gdbarch_tdep : gdbarch_tdep
+struct bpf_gdbarch_tdep : gdbarch_tdep_base
 {
 };
 
diff --git a/gdb/cris-tdep.h b/gdb/cris-tdep.h
index 0b1801afa04..981515a4e9f 100644
--- a/gdb/cris-tdep.h
+++ b/gdb/cris-tdep.h
@@ -26,7 +26,7 @@
 #include "gdbarch.h"
 
 /* CRIS architecture specific information.  */
-struct cris_gdbarch_tdep : gdbarch_tdep
+struct cris_gdbarch_tdep : gdbarch_tdep_base
 {
   unsigned int cris_version = 0;
   const char *cris_mode = nullptr;
diff --git a/gdb/csky-tdep.h b/gdb/csky-tdep.h
index 4cfc0a5d086..54000ab8287 100644
--- a/gdb/csky-tdep.h
+++ b/gdb/csky-tdep.h
@@ -31,7 +31,7 @@ enum lr_type_t
 };
 
 /* Target-dependent structure in gdbarch.  */
-struct csky_gdbarch_tdep : gdbarch_tdep
+struct csky_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Save FPU, VDSP ABI.  */
   unsigned int fpu_abi;
diff --git a/gdb/frv-tdep.c b/gdb/frv-tdep.c
index 34f437764a9..55a6cfd9618 100644
--- a/gdb/frv-tdep.c
+++ b/gdb/frv-tdep.c
@@ -68,7 +68,7 @@ struct frv_unwind_cache		/* was struct frame_extra_info */
    of structures, each of which gives all the necessary info for one
    register.  Don't stick parallel arrays in here --- that's so
    Fortran.  */
-struct frv_gdbarch_tdep : gdbarch_tdep
+struct frv_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Which ABI is in use?  */
   enum frv_abi frv_abi {};
diff --git a/gdb/ft32-tdep.h b/gdb/ft32-tdep.h
index e66a417198e..e9befaba9d4 100644
--- a/gdb/ft32-tdep.h
+++ b/gdb/ft32-tdep.h
@@ -22,7 +22,7 @@
 
 #include "gdbarch.h"
 
-struct ft32_gdbarch_tdep : gdbarch_tdep
+struct ft32_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Type for a pointer to a function.  Used for the type of PC.  */
   struct type *pc_type = nullptr;
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index 5d14aec1455..d4ea5d33c9c 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -43,7 +43,7 @@ struct gdbarch
   const struct target_desc * target_desc;
 
   /* target specific vector.  */
-  struct gdbarch_tdep *tdep;
+  struct gdbarch_tdep_base *tdep;
   gdbarch_dump_tdep_ftype *dump_tdep;
 
   /* per-architecture data-pointers.  */
@@ -258,7 +258,7 @@ struct gdbarch
 
 struct gdbarch *
 gdbarch_alloc (const struct gdbarch_info *info,
-	       struct gdbarch_tdep *tdep)
+	       struct gdbarch_tdep_base *tdep)
 {
   struct gdbarch *gdbarch;
 
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index 16c73915c64..324958469a7 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -61,11 +61,11 @@ struct inferior;
 
 /* The base class for every architecture's tdep sub-class.  The virtual
    destructor ensures the class has RTTI information, which allows
-   gdb::checked_static_cast to be used, the gdbarch_tdep the function.  */
+   gdb::checked_static_cast to be used in the gdbarch_tdep function.  */
 
-struct gdbarch_tdep
+struct gdbarch_tdep_base
 {
-  virtual ~gdbarch_tdep() = default;
+  virtual ~gdbarch_tdep_base() = default;
 };
 
 /* The architecture associated with the inferior through the
@@ -151,20 +151,23 @@ using read_core_file_mappings_loop_ftype =
 #include "gdbarch-gen.h"
 
 /* An internal function that should _only_ be called from gdbarch_tdep.
-   Returns the gdbarch_tdep field held within GDBARCH.  */
+   Returns the gdbarch_tdep_base field held within GDBARCH.  */
 
-extern struct gdbarch_tdep *gdbarch_tdep_1 (struct gdbarch *gdbarch);
+extern struct gdbarch_tdep_base *gdbarch_tdep_1 (struct gdbarch *gdbarch);
 
-/* Return the gdbarch_tdep object held within GDBARCH cast to the type
-   TDepType, which should be a sub-class of gdbarch_tdep.  There is no
-   checking done that the gdbarch_tdep within GDBARCH actually is of the
-   type TDepType, we just assume the caller knows what they are doing.  */
+/* Return the gdbarch_tdep_base object held within GDBARCH cast to the type
+   TDepType, which should be a sub-class of gdbarch_tdep_base.
+
+   When GDB is compiled in maintainer mode a run-time check is performed
+   that the gdbarch_tdep_base within GDBARCH really is of type TDepType.
+   When GDB is compiled in release mode the run-time check is not
+   performed, and we assume the caller knows what they are doing.  */
 
 template<typename TDepType>
 static inline TDepType *
 gdbarch_tdep (struct gdbarch *gdbarch)
 {
-  struct gdbarch_tdep *tdep = gdbarch_tdep_1 (gdbarch);
+  struct gdbarch_tdep_base *tdep = gdbarch_tdep_1 (gdbarch);
   return gdb::checked_static_cast<TDepType *> (tdep);
 }
 
@@ -293,7 +296,7 @@ extern struct gdbarch_list *gdbarch_list_lookup_by_info (struct gdbarch_list *ar
    parameters.  set_gdbarch_*() functions are called to complete the
    initialization of the object.  */
 
-extern struct gdbarch *gdbarch_alloc (const struct gdbarch_info *info, struct gdbarch_tdep *tdep);
+extern struct gdbarch *gdbarch_alloc (const struct gdbarch_info *info, struct gdbarch_tdep_base *tdep);
 
 
 /* Helper function.  Free a partially-constructed ``struct gdbarch''.
diff --git a/gdb/gdbarch.py b/gdb/gdbarch.py
index 8956a9c38aa..bb08081af5a 100755
--- a/gdb/gdbarch.py
+++ b/gdb/gdbarch.py
@@ -267,7 +267,7 @@ with open("gdbarch.c", "w") as f:
         print(f"  {c.type} {c.name};", file=f)
     print(file=f)
     print("  /* target specific vector.  */", file=f)
-    print("  struct gdbarch_tdep *tdep;", file=f)
+    print("  struct gdbarch_tdep_base *tdep;", file=f)
     print("  gdbarch_dump_tdep_ftype *dump_tdep;", file=f)
     print(file=f)
     print("  /* per-architecture data-pointers.  */", file=f)
@@ -290,7 +290,7 @@ with open("gdbarch.c", "w") as f:
     print(file=f)
     print("struct gdbarch *", file=f)
     print("gdbarch_alloc (const struct gdbarch_info *info,", file=f)
-    print("	       struct gdbarch_tdep *tdep)", file=f)
+    print("	       struct gdbarch_tdep_base *tdep)", file=f)
     print("{", file=f)
     print("  struct gdbarch *gdbarch;", file=f)
     print("", file=f)
diff --git a/gdb/hppa-tdep.h b/gdb/hppa-tdep.h
index f1e24a272c4..c2c9e0e0b5e 100644
--- a/gdb/hppa-tdep.h
+++ b/gdb/hppa-tdep.h
@@ -84,7 +84,7 @@ enum hppa_regnum
 #define HPPA_INSN_SIZE 4
 
 /* Target-dependent structure in gdbarch.  */
-struct hppa_gdbarch_tdep : gdbarch_tdep
+struct hppa_gdbarch_tdep : gdbarch_tdep_base
 {
   /* The number of bytes in an address.  For now, this field is designed
      to allow us to differentiate hppa32 from hppa64 targets.  */
diff --git a/gdb/i386-tdep.h b/gdb/i386-tdep.h
index a8067cf6b6c..cd77e0308e0 100644
--- a/gdb/i386-tdep.h
+++ b/gdb/i386-tdep.h
@@ -57,7 +57,7 @@ enum struct_return
 };
 
 /* i386 architecture specific information.  */
-struct i386_gdbarch_tdep : gdbarch_tdep
+struct i386_gdbarch_tdep : gdbarch_tdep_base
 {
   /* General-purpose registers.  */
   int *gregset_reg_offset = 0;
diff --git a/gdb/ia64-tdep.h b/gdb/ia64-tdep.h
index 675d0d871b2..f06974fd296 100644
--- a/gdb/ia64-tdep.h
+++ b/gdb/ia64-tdep.h
@@ -229,7 +229,7 @@ struct ia64_infcall_ops
   void (*set_function_addr) (struct regcache *regcache, CORE_ADDR func_addr);
 };
 
-struct ia64_gdbarch_tdep : gdbarch_tdep
+struct ia64_gdbarch_tdep : gdbarch_tdep_base
 {
   CORE_ADDR (*sigcontext_register_address) (struct gdbarch *, CORE_ADDR, int)
     = nullptr;
diff --git a/gdb/lm32-tdep.c b/gdb/lm32-tdep.c
index 4a781c394e9..4cbff537fab 100644
--- a/gdb/lm32-tdep.c
+++ b/gdb/lm32-tdep.c
@@ -43,7 +43,7 @@
 #define LM32_REG2(insn)         ((insn >> 11) & 0x1f)
 #define LM32_IMM16(insn)        ((((long)insn & 0xffff) << 16) >> 16)
 
-struct lm32_gdbarch_tdep : gdbarch_tdep
+struct lm32_gdbarch_tdep : gdbarch_tdep_base
 {
   /* gdbarch target dependent data here.  Currently unused for LM32.  */
 };
diff --git a/gdb/loongarch-tdep.h b/gdb/loongarch-tdep.h
index e35b6cf4c7a..c5527f7d148 100644
--- a/gdb/loongarch-tdep.h
+++ b/gdb/loongarch-tdep.h
@@ -32,7 +32,7 @@ extern const struct regset loongarch_gregset;
 extern const struct regset loongarch_fpregset;
 
 /* Target-dependent structure in gdbarch.  */
-struct loongarch_gdbarch_tdep : gdbarch_tdep
+struct loongarch_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Features about the abi that impact how the gdbarch is configured.  */
   struct loongarch_gdbarch_features abi_features;
diff --git a/gdb/m32c-tdep.c b/gdb/m32c-tdep.c
index 37456d16cb3..30f716b6969 100644
--- a/gdb/m32c-tdep.c
+++ b/gdb/m32c-tdep.c
@@ -96,7 +96,7 @@ struct m32c_reg
 #define M32C_MAX_DWARF_REGNUM (40)
 
 
-struct m32c_gdbarch_tdep : gdbarch_tdep
+struct m32c_gdbarch_tdep : gdbarch_tdep_base
 {
   /* All the registers for this variant, indexed by GDB register
      number, and the number of registers present.  */
diff --git a/gdb/m32r-tdep.h b/gdb/m32r-tdep.h
index 1fa143adc74..09d5b245770 100644
--- a/gdb/m32r-tdep.h
+++ b/gdb/m32r-tdep.h
@@ -22,7 +22,7 @@
 
 #include "gdbarch.h"
 
-struct m32r_gdbarch_tdep : gdbarch_tdep
+struct m32r_gdbarch_tdep : gdbarch_tdep_base
 {
   /* gdbarch target dependent data here.  Currently unused for M32R.  */
 };
diff --git a/gdb/m68hc11-tdep.c b/gdb/m68hc11-tdep.c
index 9eb18b937be..7ea1f9a5b91 100644
--- a/gdb/m68hc11-tdep.c
+++ b/gdb/m68hc11-tdep.c
@@ -124,7 +124,7 @@ enum insn_return_kind {
 #define M68HC12_HARD_PC_REGNUM  (SOFT_D32_REGNUM+1)
 
 struct insn_sequence;
-struct m68gc11_gdbarch_tdep : gdbarch_tdep
+struct m68gc11_gdbarch_tdep : gdbarch_tdep_base
   {
     /* Stack pointer correction value.  For 68hc11, the stack pointer points
        to the next push location.  An offset of 1 must be applied to obtain
diff --git a/gdb/m68k-tdep.h b/gdb/m68k-tdep.h
index c70a26e8554..785e3fdb84f 100644
--- a/gdb/m68k-tdep.h
+++ b/gdb/m68k-tdep.h
@@ -69,7 +69,7 @@ enum m68k_flavour
 
 /* Target-dependent structure in gdbarch.  */
 
-struct m68k_gdbarch_tdep : gdbarch_tdep
+struct m68k_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Offset to PC value in the jump buffer.  If this is negative,
      longjmp support will be disabled.  */
diff --git a/gdb/mep-tdep.c b/gdb/mep-tdep.c
index d5ba78c6df9..170b4b07460 100644
--- a/gdb/mep-tdep.c
+++ b/gdb/mep-tdep.c
@@ -116,7 +116,7 @@
      options are present on the current processor.  */
 
 
-struct mep_gdbarch_tdep : gdbarch_tdep
+struct mep_gdbarch_tdep : gdbarch_tdep_base
 {
   /* A CGEN cpu descriptor for this BFD architecture and machine.
 
diff --git a/gdb/microblaze-tdep.h b/gdb/microblaze-tdep.h
index 4d90e8785dc..48b2581fcc7 100644
--- a/gdb/microblaze-tdep.h
+++ b/gdb/microblaze-tdep.h
@@ -23,7 +23,7 @@
 #include "gdbarch.h"
 
 /* Microblaze architecture-specific information.  */
-struct microblaze_gdbarch_tdep : gdbarch_tdep
+struct microblaze_gdbarch_tdep : gdbarch_tdep_base
 {
 };
 
diff --git a/gdb/mips-tdep.h b/gdb/mips-tdep.h
index 4d2664d4273..24ed678a521 100644
--- a/gdb/mips-tdep.h
+++ b/gdb/mips-tdep.h
@@ -93,7 +93,7 @@ enum mips_fpu_type
 };
 
 /* MIPS specific per-architecture information.  */
-struct mips_gdbarch_tdep : gdbarch_tdep
+struct mips_gdbarch_tdep : gdbarch_tdep_base
 {
   /* from the elf header */
   int elf_flags = 0;
diff --git a/gdb/mn10300-tdep.h b/gdb/mn10300-tdep.h
index 87b861ead90..dacfb9d2948 100644
--- a/gdb/mn10300-tdep.h
+++ b/gdb/mn10300-tdep.h
@@ -76,7 +76,7 @@ enum frame_kind {
 };
 
 /* mn10300 private data.  */
-struct mn10300_gdbarch_tdep : gdbarch_tdep
+struct mn10300_gdbarch_tdep : gdbarch_tdep_base
 {
   int am33_mode;
 };
diff --git a/gdb/moxie-tdep.h b/gdb/moxie-tdep.h
index 91d007fd723..69bb5d0fa3a 100644
--- a/gdb/moxie-tdep.h
+++ b/gdb/moxie-tdep.h
@@ -22,7 +22,7 @@
 
 #include "gdbarch.h"
 
-struct moxie_gdbarch_tdep : gdbarch_tdep
+struct moxie_gdbarch_tdep : gdbarch_tdep_base
 {
   /* gdbarch target dependent data here.  Currently unused for MOXIE.  */
 };
diff --git a/gdb/msp430-tdep.c b/gdb/msp430-tdep.c
index 4ae8b3d5626..cf4106d1a34 100644
--- a/gdb/msp430-tdep.c
+++ b/gdb/msp430-tdep.c
@@ -105,7 +105,7 @@ enum
 
 /* Architecture specific data.  */
 
-struct msp430_gdbarch_tdep : gdbarch_tdep
+struct msp430_gdbarch_tdep : gdbarch_tdep_base
 {
   /* The ELF header flags specify the multilib used.  */
   int elf_flags = 0;
diff --git a/gdb/nds32-tdep.h b/gdb/nds32-tdep.h
index 2cabd6a173f..e68017b4667 100644
--- a/gdb/nds32-tdep.h
+++ b/gdb/nds32-tdep.h
@@ -42,7 +42,7 @@ enum nds32_regnum
   NDS32_FD0_REGNUM = NDS32_NUM_REGS,
 };
 
-struct nds32_gdbarch_tdep : gdbarch_tdep
+struct nds32_gdbarch_tdep : gdbarch_tdep_base
 {
   /* The guessed FPU configuration.  */
   int fpu_freg = 0;
diff --git a/gdb/nios2-tdep.h b/gdb/nios2-tdep.h
index b8913ed1baa..cbf2599f5c0 100644
--- a/gdb/nios2-tdep.h
+++ b/gdb/nios2-tdep.h
@@ -69,7 +69,7 @@
 #define NIOS2_CDX_OPCODE_SIZE 2
 
 /* Target-dependent structure in gdbarch.  */
-struct nios2_gdbarch_tdep : gdbarch_tdep
+struct nios2_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Assumes FRAME is stopped at a syscall (trap) instruction; returns
      the expected next PC.  */
diff --git a/gdb/or1k-tdep.c b/gdb/or1k-tdep.c
index 4699b755d42..360a7cb36c1 100644
--- a/gdb/or1k-tdep.c
+++ b/gdb/or1k-tdep.c
@@ -63,7 +63,7 @@ show_or1k_debug (struct ui_file *file, int from_tty,
 
 /* The target-dependent structure for gdbarch.  */
 
-struct or1k_gdbarch_tdep : gdbarch_tdep
+struct or1k_gdbarch_tdep : gdbarch_tdep_base
 {
   int bytes_per_word = 0;
   int bytes_per_address = 0;
diff --git a/gdb/ppc-tdep.h b/gdb/ppc-tdep.h
index 80a7dd080a2..44f63b145c6 100644
--- a/gdb/ppc-tdep.h
+++ b/gdb/ppc-tdep.h
@@ -205,7 +205,7 @@ enum powerpc_long_double_abi
   POWERPC_LONG_DOUBLE_LAST
 };
 
-struct ppc_gdbarch_tdep : gdbarch_tdep
+struct ppc_gdbarch_tdep : gdbarch_tdep_base
   {
     int wordsize = 0;		/* Size in bytes of fixed-point word.  */
     int soft_float = 0;		/* Avoid FP registers for arguments?  */
diff --git a/gdb/riscv-tdep.h b/gdb/riscv-tdep.h
index ac4b4b7144d..826a002ef92 100644
--- a/gdb/riscv-tdep.h
+++ b/gdb/riscv-tdep.h
@@ -76,7 +76,7 @@ enum
 };
 
 /* RISC-V specific per-architecture information.  */
-struct riscv_gdbarch_tdep : gdbarch_tdep
+struct riscv_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Features about the target hardware that impact how the gdbarch is
      configured.  Two gdbarch instances are compatible only if this field
diff --git a/gdb/rl78-tdep.c b/gdb/rl78-tdep.c
index 2462e7a191d..be668bfa6fe 100644
--- a/gdb/rl78-tdep.c
+++ b/gdb/rl78-tdep.c
@@ -210,7 +210,7 @@ enum
 
 /* Architecture specific data.  */
 
-struct rl78_gdbarch_tdep : gdbarch_tdep
+struct rl78_gdbarch_tdep : gdbarch_tdep_base
 {
   /* The ELF header flags specify the multilib used.  */
   int elf_flags = 0;
diff --git a/gdb/rx-tdep.c b/gdb/rx-tdep.c
index c67d4057195..989d90096bd 100644
--- a/gdb/rx-tdep.c
+++ b/gdb/rx-tdep.c
@@ -69,7 +69,7 @@ enum rx_frame_type {
 };
 
 /* Architecture specific data.  */
-struct rx_gdbarch_tdep : gdbarch_tdep
+struct rx_gdbarch_tdep : gdbarch_tdep_base
 {
   /* The ELF header flags specify the multilib used.  */
   int elf_flags = 0;
diff --git a/gdb/s12z-tdep.c b/gdb/s12z-tdep.c
index 4e33faaea9a..5e49c615f1b 100644
--- a/gdb/s12z-tdep.c
+++ b/gdb/s12z-tdep.c
@@ -458,7 +458,7 @@ constexpr gdb_byte s12z_break_insn[] = {0x00};
 
 typedef BP_MANIPULATION (s12z_break_insn) s12z_breakpoint;
 
-struct s12z_gdbarch_tdep : gdbarch_tdep
+struct s12z_gdbarch_tdep : gdbarch_tdep_base
 {
 };
 
diff --git a/gdb/s390-tdep.h b/gdb/s390-tdep.h
index ac08da1c7c8..f51423cb018 100644
--- a/gdb/s390-tdep.h
+++ b/gdb/s390-tdep.h
@@ -38,7 +38,7 @@ enum s390_vector_abi_kind
 
 /* The tdep structure.  */
 
-struct s390_gdbarch_tdep : gdbarch_tdep
+struct s390_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Target description.  */
   const struct target_desc *tdesc = nullptr;
diff --git a/gdb/sh-tdep.h b/gdb/sh-tdep.h
index bc0383fb075..54aa7ff828f 100644
--- a/gdb/sh-tdep.h
+++ b/gdb/sh-tdep.h
@@ -91,7 +91,7 @@ struct sh_corefile_regmap
   unsigned int offset;
 };
 
-struct sh_gdbarch_tdep : gdbarch_tdep
+struct sh_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Non-NULL when debugging from a core file.  Provides the offset
      where each general-purpose register is stored inside the associated
diff --git a/gdb/sparc-tdep.h b/gdb/sparc-tdep.h
index 36ff5349a0a..f2070f10e12 100644
--- a/gdb/sparc-tdep.h
+++ b/gdb/sparc-tdep.h
@@ -57,7 +57,7 @@ struct sparc_fpregmap
 
 /* SPARC architecture-specific information.  */
 
-struct sparc_gdbarch_tdep : gdbarch_tdep
+struct sparc_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Register numbers for the PN and nPC registers.  The definitions
      for (64-bit) UltraSPARC differ from the (32-bit) SPARC
diff --git a/gdb/tic6x-tdep.h b/gdb/tic6x-tdep.h
index d9b9644f8df..ebfd6e686fa 100644
--- a/gdb/tic6x-tdep.h
+++ b/gdb/tic6x-tdep.h
@@ -46,7 +46,7 @@ extern const gdb_byte tic6x_bkpt_illegal_opcode_be[];
 extern const gdb_byte tic6x_bkpt_illegal_opcode_le[];
 
 /* Target-dependent structure in gdbarch.  */
-struct tic6x_gdbarch_tdep : gdbarch_tdep
+struct tic6x_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Return the expected next PC if FRAME is stopped at a syscall
      instruction.  */
diff --git a/gdb/v850-tdep.c b/gdb/v850-tdep.c
index 4de5faa6a47..f7094e37a92 100644
--- a/gdb/v850-tdep.c
+++ b/gdb/v850-tdep.c
@@ -265,7 +265,7 @@ enum v850_abi
 
 /* Architecture specific data.  */
 
-struct v850_gdbarch_tdep : gdbarch_tdep
+struct v850_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Fields from the ELF header.  */
   int e_flags = 0;
diff --git a/gdb/xtensa-tdep.h b/gdb/xtensa-tdep.h
index 1840ef98b49..da7a7080afd 100644
--- a/gdb/xtensa-tdep.h
+++ b/gdb/xtensa-tdep.h
@@ -167,7 +167,7 @@ struct ctype_cache
 
 /*  Xtensa-specific target dependencies.  */
 
-struct xtensa_gdbarch_tdep : gdbarch_tdep
+struct xtensa_gdbarch_tdep : gdbarch_tdep_base
 {
   xtensa_gdbarch_tdep (xtensa_register_t *regmap)
     : regmap (regmap)
diff --git a/gdb/z80-tdep.c b/gdb/z80-tdep.c
index 6a11883e7b4..1ab375c5014 100644
--- a/gdb/z80-tdep.c
+++ b/gdb/z80-tdep.c
@@ -55,7 +55,7 @@
      next frame - frame of caller, which has called current function
 */
 
-struct z80_gdbarch_tdep : gdbarch_tdep
+struct z80_gdbarch_tdep : gdbarch_tdep_base
 {
   /* Number of bytes used for address:
       2 bytes for all Z80 family


^ permalink raw reply	[flat|nested] 83+ messages in thread

end of thread, other threads:[~2022-07-26 11:05 UTC | newest]

Thread overview: 83+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-31 14:30 [PATCH 0/5] Handle trying to use a native target with the wrong binary Andrew Burgess
2022-05-31 14:30 ` [PATCH 1/5] gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope Andrew Burgess
2022-06-01  7:58   ` Luis Machado
2022-05-31 14:30 ` [PATCH 2/5] gdb/mips: rewrite show_mask_address Andrew Burgess
2022-05-31 14:30 ` [PATCH 3/5] gdb: move the type cast into gdbarch_tdep Andrew Burgess
2022-06-01  8:01   ` Luis Machado
2022-05-31 14:30 ` [PATCH 4/5] gdb: ensure the cast in gdbarch_tdep is valid Andrew Burgess
2022-05-31 16:04   ` John Baldwin
2022-05-31 17:22     ` Andrew Burgess
2022-05-31 14:30 ` [PATCH 5/5] gdb: native target invalid architecture detection Andrew Burgess
2022-05-31 16:08   ` John Baldwin
2022-05-31 16:51     ` Andrew Burgess
2022-06-01  8:25       ` Luis Machado
2022-06-01 21:06         ` John Baldwin
2022-06-01 21:21           ` Christophe Lyon
2022-06-02 14:56             ` John Baldwin
2022-06-06 14:38         ` Andrew Burgess
2022-06-06 17:48           ` Andrew Burgess
2022-06-07 11:03             ` Luis Machado
2022-06-07 18:42               ` Pedro Alves
2022-06-07 20:15                 ` Pedro Alves
2022-06-08  8:18                   ` Luis Machado
2022-06-08 10:17                     ` Pedro Alves
2022-06-08  7:54                 ` Luis Machado
2022-06-08 10:12                   ` Pedro Alves
2022-06-08 11:20                     ` [PATCH v2] aarch64: Add fallback if ARM_CC_FOR_TARGET not set (was: Re: [PATCH 5/5] gdb: native target invalid architecture detection) Pedro Alves
2022-06-08 12:50                       ` Luis Machado
2022-06-08 13:23                         ` Pedro Alves
2022-06-08 13:38                       ` Andrew Burgess
2022-06-08 19:01                       ` John Baldwin
2022-06-08 21:48                         ` Pedro Alves
2022-06-09 16:31                           ` John Baldwin
2022-06-10 13:08 ` [PATCHv2 0/6] Handle trying to use a native target with the wrong binary Andrew Burgess
2022-06-10 13:08   ` [PATCHv2 1/6] gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope Andrew Burgess
2022-06-10 13:08   ` [PATCHv2 2/6] gdb/mips: rewrite show_mask_address Andrew Burgess
2022-06-10 13:08   ` [PATCHv2 3/6] gdb/arm: avoid undefined behaviour in arm_frame_is_thumb Andrew Burgess
2022-06-10 15:21     ` Luis Machado
2022-06-10 15:49       ` Andrew Burgess
2022-06-10 16:29         ` Luis Machado
2022-06-10 13:08   ` [PATCHv2 4/6] gdb: move the type cast into gdbarch_tdep Andrew Burgess
2022-06-10 16:35     ` Luis Machado
2022-06-10 13:08   ` [PATCHv2 5/6] gdb: ensure the cast in gdbarch_tdep is valid Andrew Burgess
2022-06-10 13:08   ` [PATCHv2 6/6] gdb: native target invalid architecture detection Andrew Burgess
2022-06-10 16:20     ` John Baldwin
2022-06-10 16:31     ` Luis Machado
2022-06-13 16:15   ` [PATCHv3 0/6] Handle trying to use a native target with the wrong binary Andrew Burgess
2022-06-13 16:15     ` [PATCHv3 1/6] gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope Andrew Burgess
2022-06-13 16:15     ` [PATCHv3 2/6] gdb/mips: rewrite show_mask_address Andrew Burgess
2022-06-13 16:15     ` [PATCHv3 3/6] gdb: select suitable thread for gdbarch_adjust_breakpoint_address Andrew Burgess
2022-06-14  9:45       ` Luis Machado
2022-06-14 14:05         ` Andrew Burgess
2022-06-24 16:58       ` Pedro Alves
2022-06-13 16:15     ` [PATCHv3 4/6] gdb: move the type cast into gdbarch_tdep Andrew Burgess
2022-06-13 16:15     ` [PATCHv3 5/6] gdb: ensure the cast in gdbarch_tdep is valid Andrew Burgess
2022-06-24 18:15       ` Pedro Alves
2022-06-13 16:15     ` [PATCHv3 6/6] gdb: native target invalid architecture detection Andrew Burgess
2022-06-24 19:23       ` Pedro Alves
2022-06-27 16:27         ` Andrew Burgess
2022-06-27 21:38           ` Pedro Alves
2022-06-28 10:37             ` Andrew Burgess
2022-06-28 12:42               ` [PATCH v2] gdb+gdbserver/Linux: avoid reading registers while going through shell (was: Re: [PATCHv3 6/6] gdb: native target invalid architecture detection) Pedro Alves
2022-06-28 14:21                 ` Andrew Burgess
2022-06-29 15:17                 ` Simon Marchi
2022-06-29 16:22                   ` [PATCH] Fix GDBserver regression due to change to avoid reading shell registers Pedro Alves
2022-06-29 16:38                     ` Simon Marchi
2022-06-30  9:33             ` [PATCHv3 6/6] gdb: native target invalid architecture detection Andrew Burgess
2022-06-30 11:44               ` Pedro Alves
2022-07-11 10:47                 ` Andrew Burgess
2022-06-24 10:15     ` [PATCHv3 0/6] Handle trying to use a native target with the wrong binary Andrew Burgess
2022-06-28 14:28     ` [PATCHv4 0/6] Detect invalid casts of gdbarch_tdep structures Andrew Burgess
2022-06-28 14:28       ` [PATCHv4 1/6] gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope Andrew Burgess
2022-06-28 14:28       ` [PATCHv4 2/6] gdb/mips: rewrite show_mask_address Andrew Burgess
2022-06-28 14:28       ` [PATCHv4 3/6] gdb: select suitable thread for gdbarch_adjust_breakpoint_address Andrew Burgess
2022-06-28 14:28       ` [PATCHv4 4/6] gdb: move the type cast into gdbarch_tdep Andrew Burgess
2022-06-28 14:28       ` [PATCHv4 5/6] gdbsupport: add checked_static_cast Andrew Burgess
2022-06-28 14:28       ` [PATCHv4 6/6] gdb: ensure the cast in gdbarch_tdep is valid Andrew Burgess
2022-07-11 10:46       ` [PATCHv4 0/6] Detect invalid casts of gdbarch_tdep structures Andrew Burgess
2022-07-21 18:21         ` Andrew Burgess
2022-07-22  0:50           ` Luis Machado
2022-07-23  0:02             ` [PATCH] Rename gdbarch_tdep template function to gdbarch_tdep_cast for g++ 4.8 Mark Wielaard
2022-07-25 11:19               ` Andrew Burgess
2022-07-25 11:27                 ` Mark Wielaard
2022-07-26 11:05                   ` Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).