From: Luis Machado Date: Tue, 31 Jan 2023 17:17:09 +0000 (+0000) Subject: corefile/bug: Use thread-specific gdbarch when dumping register state to core files X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7070423f17ff4756aec92aab15a88681a4f9df11;p=binutils-gdb.git corefile/bug: Use thread-specific gdbarch when dumping register state to core files When we have a core file generated by gdb (via the gcore command), gdb dumps the target description to a note. During loading of that core file, gdb will first try to load that saved target description. This works fine for almost all architectures. But AArch64 has a few dynamically-generated target descriptions/gdbarch depending on the vector length that was in use at the time the core file was generated. The target description gdb dumps to the core file note is the one generated at the time of attachment/startup. If, for example, the SVE vector length changed during execution, this would not reflect on the core file, as gdb would still dump the initial target description. Another issue is that the gdbarch potentially doesn't match the thread's real gdbarch, and so things like the register cache may have different formats and sizes. To address this, fetch the thread's architecture before dumping its register state. That way we will always use the correct target description/gdbarch. Approved-By: Simon Marchi Approved-By: Tom Tromey Reviewed-by: Thiago Jung Bauermann --- diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index 33f84c8e5f8..f03a5b95332 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -2078,15 +2078,30 @@ linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size) stop_signal = GDB_SIGNAL_0; if (signalled_thr != nullptr) - linux_corefile_thread (signalled_thr, gdbarch, obfd, note_data, note_size, - stop_signal); + { + /* On some architectures, like AArch64, each thread can have a distinct + gdbarch (due to scalable extensions), and using the inferior gdbarch + is incorrect. + + Fetch each thread's gdbarch and pass it down to the lower layers so + we can dump the right set of registers. */ + linux_corefile_thread (signalled_thr, + target_thread_architecture (signalled_thr->ptid), + obfd, note_data, note_size, stop_signal); + } for (thread_info *thr : current_inferior ()->non_exited_threads ()) { if (thr == signalled_thr) continue; - linux_corefile_thread (thr, gdbarch, obfd, note_data, note_size, - stop_signal); + /* On some architectures, like AArch64, each thread can have a distinct + gdbarch (due to scalable extensions), and using the inferior gdbarch + is incorrect. + + Fetch each thread's gdbarch and pass it down to the lower layers so + we can dump the right set of registers. */ + linux_corefile_thread (thr, target_thread_architecture (thr->ptid), + obfd, note_data, note_size, stop_signal); } if (!note_data)