Skip to content

Commit 4b2f71e

Browse files
committed
gdb: replace architecture_changed with new_architecture observer
This commit replaces the architecture_changed observer with a new_architecture observer. Currently the only user of the architecture_changed observer is the Python code, which uses this observer to register the Python unwinder with the architecture. The problem is that the architecture_changed observer is triggered from inferior::set_arch(), which only sees the inferior-wide gdbarch value. For targets that use thread-specific architectures, these never trigger the architecture_changed observer, and so never have the Python unwinder registered with them. When it comes to unwinding GDB makes use of the frame's gdbarch, which is based on the thread's regcache gdbarch, which is set in get_thread_regcache to the value returned from target_thread_architecture, which is not always the inferiors gdbarch value, it might be a thread-specific gdbarch which has not passed through inferior::set_arch(). The new_architecture observer will be triggered from gdbarch_find_by_info, whenever a new gdbarch is created and initialised. As GDB caches and reuses gdbarch values, we should expect to see each new architecture trigger the new_architecture observer just once. After this commit, targets that make use of thread-specific architectures should be able to make use of Python unwinders. As I don't have access to a machine that makes use of thread-specific architectures right now, I asked Luis to confirm that an AArch64 target that uses SVE/SME can't use the Python unwinders in threads that are using a thread-specific architectures, and he confirmed that this is indeed the case, see this discussion: https://inbox.sourceware.org/gdb/[email protected] Tested-By: Lancelot Six <[email protected]> Tested-By: Luis Machado <[email protected]> Reviewed-By: Luis Machado <[email protected]> Approved-By: Simon Marchi <[email protected]>
1 parent 9f9073e commit 4b2f71e

File tree

5 files changed

+8
-9
lines changed

5 files changed

+8
-9
lines changed

gdb/arch-utils.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,8 @@ gdbarch_find_by_info (struct gdbarch_info info)
14791479
if (gdbarch_debug)
14801480
gdbarch_dump (new_gdbarch, gdb_stdlog);
14811481

1482+
gdb::observers::new_architecture.notify (new_gdbarch);
1483+
14821484
return new_gdbarch;
14831485
}
14841486

gdb/inferior.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ inferior::set_arch (gdbarch *arch)
179179
gdb_assert (arch != nullptr);
180180
gdb_assert (gdbarch_initialized_p (arch));
181181
m_gdbarch = arch;
182-
gdb::observers::architecture_changed.notify (this, arch);
183182

184183
process_stratum_target *proc_target = this->process_target ();
185184
if (proc_target != nullptr)

gdb/observable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ DEFINE_OBSERVABLE (about_to_proceed);
5252
DEFINE_OBSERVABLE (breakpoint_created);
5353
DEFINE_OBSERVABLE (breakpoint_deleted);
5454
DEFINE_OBSERVABLE (breakpoint_modified);
55-
DEFINE_OBSERVABLE (architecture_changed);
55+
DEFINE_OBSERVABLE (new_architecture);
5656
DEFINE_OBSERVABLE (thread_ptid_changed);
5757
DEFINE_OBSERVABLE (inferior_added);
5858
DEFINE_OBSERVABLE (inferior_appeared);

gdb/observable.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,9 @@ extern observable<struct breakpoint */* b */> breakpoint_deleted;
153153
is the modified breakpoint. */
154154
extern observable<struct breakpoint */* b */> breakpoint_modified;
155155

156-
/* INF's architecture has changed. The argument NEWARCH is a
157-
pointer to the new architecture. */
158-
extern observable<inferior */* inf */, struct gdbarch */* newarch */>
159-
architecture_changed;
156+
/* GDB has instantiated a new architecture, NEWARCH is a pointer to the new
157+
architecture. */
158+
extern observable<struct gdbarch */* newarch */> new_architecture;
160159

161160
/* The thread's ptid has changed. The OLD_PTID parameter specifies
162161
the old value, and NEW_PTID specifies the new value. */

gdb/python/py-unwind.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ static const registry<gdbarch>::key<pyuw_gdbarch_data_type> pyuw_gdbarch_data;
945945
intermediary. */
946946

947947
static void
948-
pyuw_on_new_gdbarch (inferior *inf, gdbarch *newarch)
948+
pyuw_on_new_gdbarch (gdbarch *newarch)
949949
{
950950
struct pyuw_gdbarch_data_type *data = pyuw_gdbarch_data.get (newarch);
951951
if (data == nullptr)
@@ -974,8 +974,7 @@ pyuw_on_new_gdbarch (inferior *inf, gdbarch *newarch)
974974
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
975975
gdbpy_initialize_unwind (void)
976976
{
977-
gdb::observers::architecture_changed.attach (pyuw_on_new_gdbarch,
978-
"py-unwind");
977+
gdb::observers::new_architecture.attach (pyuw_on_new_gdbarch, "py-unwind");
979978

980979
if (PyType_Ready (&pending_frame_object_type) < 0)
981980
return -1;

0 commit comments

Comments
 (0)