public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope
Date: Thu, 21 Jul 2022 18:20:06 +0000 (GMT)	[thread overview]
Message-ID: <20220721182006.A71E2384D16F@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6dff2a6ffed01ec1db55d06cfdd747bb2d83aeea

commit 6dff2a6ffed01ec1db55d06cfdd747bb2d83aeea
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Thu May 19 16:04:26 2022 +0100

    gdb/arm: move fetch of arm_gdbarch_tdep to a more inner scope
    
    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.

Diff:
---
 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 89c2779bbb5..ac49054c074 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -9162,14 +9162,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"),
@@ -9200,14 +9202,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);


                 reply	other threads:[~2022-07-21 18:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220721182006.A71E2384D16F@sourceware.org \
    --to=aburgess@sourceware.org \
    --cc=gdb-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).