public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 3/5] gdb: move set_target_gdbarch to inferior::set_arch
Date: Fri, 29 Sep 2023 14:24:37 -0400	[thread overview]
Message-ID: <20230929182541.138320-4-simon.marchi@efficios.com> (raw)
In-Reply-To: <20230929182541.138320-1-simon.marchi@efficios.com>

set_target_gdbarch is basically a setter for the current inferior's
arch, that notifies other parts of GDB of the architecture change.  Move
the code of set_target_gdbarch to the inferior::set_arch method.

Add gdbarch_initialized_p, so we can keep the assertion.

Change-Id: I276e28eafd4740c94bc5233c81a86c01b4a6ae90
---
 gdb/arch-utils.c | 20 ++++++++------------
 gdb/gdbarch.h    |  9 +++------
 gdb/inferior.c   | 10 ++++++++++
 gdb/inferior.h   |  3 +--
 4 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index 91bd540dd9a9..312aa0f61d81 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -625,7 +625,8 @@ gdbarch_update_p (struct gdbarch_info info)
 		"New architecture %s (%s) selected\n",
 		host_address_to_string (new_gdbarch),
 		gdbarch_bfd_arch_info (new_gdbarch)->printable_name);
-  set_target_gdbarch (new_gdbarch);
+
+  current_inferior ()->set_arch (new_gdbarch);
 
   return 1;
 }
@@ -657,7 +658,8 @@ set_gdbarch_from_file (bfd *abfd)
 
   if (gdbarch == NULL)
     error (_("Architecture of file not recognized."));
-  set_target_gdbarch (gdbarch);
+
+  current_inferior ()->set_arch (gdbarch);
 }
 
 /* Initialize the current architecture.  Update the ``set
@@ -1212,7 +1214,6 @@ gdbarch_obstack_strdup (struct gdbarch *arch, const char *string)
   return obstack_strdup (&arch->obstack, string);
 }
 
-
 /* Free a gdbarch struct.  This should never happen in normal
    operation --- once you've created a gdbarch, you keep it around.
    However, if an architecture's init function encounters an error
@@ -1471,17 +1472,12 @@ gdbarch_find_by_info (struct gdbarch_info info)
   return new_gdbarch;
 }
 
-/* Make the specified architecture current.  */
+/* See gdbarch.h.  */
 
-void
-set_target_gdbarch (struct gdbarch *new_gdbarch)
+bool
+gdbarch_initialized_p (gdbarch *arch)
 {
-  gdb_assert (new_gdbarch != NULL);
-  gdb_assert (new_gdbarch->initialized_p);
-  current_inferior ()->set_arch (new_gdbarch);
-  gdb::observers::architecture_changed.notify (current_inferior (),
-					       new_gdbarch);
-  registers_changed ();
+  return arch->initialized_p;
 }
 
 /* Return the current inferior's arch.  */
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index a9d6a4b175c5..5285f29b18b8 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -278,6 +278,9 @@ extern void gdbarch_register (enum bfd_architecture architecture,
 			      gdbarch_dump_tdep_ftype *dump_tdep = nullptr,
 			      gdbarch_supports_arch_info_ftype *supports_arch_info = nullptr);
 
+/* Return true if ARCH is initialized.  */
+
+bool gdbarch_initialized_p (gdbarch *arch);
 
 /* Return a vector of the valid architecture names.  Since architectures are
    registered during the _initialize phase this function only returns useful
@@ -355,12 +358,6 @@ extern int gdbarch_update_p (struct gdbarch_info info);
 
 extern struct gdbarch *gdbarch_find_by_info (struct gdbarch_info info);
 
-
-/* Helper function.  Set the target gdbarch to "gdbarch".  */
-
-extern void set_target_gdbarch (struct gdbarch *gdbarch);
-
-
 /* A registry adaptor for gdbarch.  This arranges to store the
    registry in the gdbarch.  */
 template<>
diff --git a/gdb/inferior.c b/gdb/inferior.c
index 12419da2c3a9..21795a0d8a42 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -173,6 +173,16 @@ inferior::set_args (gdb::array_view<char * const> args)
   set_args (construct_inferior_arguments (args));
 }
 
+void
+inferior::set_arch (gdbarch *arch)
+{
+  gdb_assert (arch != nullptr);
+  gdb_assert (gdbarch_initialized_p (arch));
+  m_gdbarch = arch;
+  gdb::observers::architecture_changed.notify (this, arch);
+  registers_changed ();
+}
+
 void
 inferior::add_continuation (std::function<void ()> &&cont)
 {
diff --git a/gdb/inferior.h b/gdb/inferior.h
index 29e26a5846b4..33eff7a91418 100644
--- a/gdb/inferior.h
+++ b/gdb/inferior.h
@@ -554,8 +554,7 @@ class inferior : public refcounted_object,
   }
 
   /* Set this inferior's arch.  */
-  void set_arch (gdbarch *arch)
-  { m_gdbarch = arch; }
+  void set_arch (gdbarch *arch);
 
   /* Get this inferior's arch.  */
   gdbarch *arch ()
-- 
2.42.0


  parent reply	other threads:[~2023-09-29 18:25 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-29 18:24 [PATCH 0/5] Various inferior / arch cleanups Simon Marchi
2023-09-29 18:24 ` [PATCH 1/5] gdb: add inferior::{arch, set_arch} Simon Marchi
2023-09-29 18:24 ` [PATCH 2/5] gdb: add inferior parameter to architecture_changed observable Simon Marchi
2023-09-29 18:24 ` Simon Marchi [this message]
2023-09-29 18:24 ` [PATCH 4/5] gdb: remove target_gdbarch Simon Marchi
2023-09-29 18:24 ` [PATCH 5/5] gdb: scope down registers_changed call in inferior::set_arch Simon Marchi
2023-10-06 22:05 ` [PATCH 0/5] Various inferior / arch cleanups John Baldwin
2023-10-10 14:43   ` Simon Marchi
2023-10-10 14:55     ` Guinevere Larsen
2023-10-10 15:05       ` Simon Marchi
2023-10-09  9:42 ` Andrew Burgess
2023-10-10 14:48   ` Simon Marchi

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=20230929182541.138320-4-simon.marchi@efficios.com \
    --to=simon.marchi@efficios.com \
    --cc=gdb-patches@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).