diff options
author | Simon Marchi <simon.marchi@efficios.com> | 2023-09-29 14:24:37 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@efficios.com> | 2023-10-10 10:44:35 -0400 |
commit | 72c4529c85907a5e1e04960ff1362a5a185553a0 (patch) | |
tree | b7828d3aa544952ed62c4ec8833e1d7de1f0de94 | |
parent | 97153a2bbfc59d33c1031526e63b06725862ba6b (diff) | |
download | gdb-72c4529c85907a5e1e04960ff1362a5a185553a0.zip gdb-72c4529c85907a5e1e04960ff1362a5a185553a0.tar.gz gdb-72c4529c85907a5e1e04960ff1362a5a185553a0.tar.bz2 |
gdb: move set_target_gdbarch to inferior::set_arch
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
Reviewed-By: John Baldwin <jhb@FreeBSD.org>
Approved-By: Andrew Burgess <aburgess@redhat.com>
-rw-r--r-- | gdb/arch-utils.c | 20 | ||||
-rw-r--r-- | gdb/gdbarch.h | 9 | ||||
-rw-r--r-- | gdb/inferior.c | 10 | ||||
-rw-r--r-- | gdb/inferior.h | 3 |
4 files changed, 22 insertions, 20 deletions
diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c index b2b265a..5768259 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 @@ -1222,7 +1224,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 @@ -1481,17 +1482,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 a9d6a4b..5285f29 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 12419da..21795a0 100644 --- a/gdb/inferior.c +++ b/gdb/inferior.c @@ -174,6 +174,16 @@ inferior::set_args (gdb::array_view<char * const> 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) { m_continuations.emplace_front (std::move (cont)); diff --git a/gdb/inferior.h b/gdb/inferior.h index 29e26a5..33eff7a 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -554,8 +554,7 @@ public: } /* 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 () |