aboutsummaryrefslogtreecommitdiff
path: root/gdb/gdbarch.c
diff options
context:
space:
mode:
authorLuis Machado <luis.machado@arm.com>2023-09-07 16:20:15 +0100
committerLuis Machado <luis.machado@arm.com>2023-10-04 16:23:40 +0100
commitb93d537fba70f46eae96edaea6010314c047f7ec (patch)
treef4b0acb209a3858cf21b30367e3a245cb3b51612 /gdb/gdbarch.c
parent7070423f17ff4756aec92aab15a88681a4f9df11 (diff)
downloadgdb-b93d537fba70f46eae96edaea6010314c047f7ec.zip
gdb-b93d537fba70f46eae96edaea6010314c047f7ec.tar.gz
gdb-b93d537fba70f46eae96edaea6010314c047f7ec.tar.bz2
corefile/bug: Add hook to control the use of target description notes from corefiles
Due to the nature of the AArch64 SVE/SME extensions in GDB, each thread can potentially have distinct target descriptions/gdbarches. When loading a gcore-generated core file, at the moment GDB gives priority to the target description dumped to NT_GDB_TDESC. Though technically correct for most targets, it doesn't work correctly for AArch64 with SVE or SME support. The correct approach for AArch64/Linux is to either have per-thread target description notes in the corefiles or to rely on the gdbarch_core_read_description hook, so it can figure out the proper target description for a given thread based on the various available register notes. The former, although more correct, doesn't address the case of existing gdb's that only output a single target description note. This patch goes for the latter, and adds a new gdbarch hook to conditionalize the use of the corefile target description note. The hook is called use_target_description_from_corefile_notes. The hook defaults to returning true, meaning targets will use the corefile target description note. AArch64 Linux overrides the hook to return false when it detects any of the SVE or SME register notes in the corefile. Otherwise it should be fine for AArch64 Linux to use the corefile target description note. When we support per-thread target description notes, then we can augment the AArch64 Linux hook to rely on those notes. Regression-tested on aarch64-linux Ubuntu 22.04/20.04. Approved-By: Simon Marchi <simon.marchi@efficios.com> Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Diffstat (limited to 'gdb/gdbarch.c')
-rw-r--r--gdb/gdbarch.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index 1fc254d..ea6e4c6 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -256,6 +256,7 @@ struct gdbarch
gdbarch_type_align_ftype *type_align = default_type_align;
gdbarch_get_pc_address_flags_ftype *get_pc_address_flags = default_get_pc_address_flags;
gdbarch_read_core_file_mappings_ftype *read_core_file_mappings = default_read_core_file_mappings;
+ gdbarch_use_target_description_from_corefile_notes_ftype *use_target_description_from_corefile_notes = default_use_target_description_from_corefile_notes;
};
/* Create a new ``struct gdbarch'' based on information provided by
@@ -523,6 +524,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
/* Skip verify of type_align, invalid_p == 0 */
/* Skip verify of get_pc_address_flags, invalid_p == 0 */
/* Skip verify of read_core_file_mappings, invalid_p == 0 */
+ /* Skip verify of use_target_description_from_corefile_notes, invalid_p == 0 */
if (!log.empty ())
internal_error (_("verify_gdbarch: the following are invalid ...%s"),
log.c_str ());
@@ -1373,6 +1375,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
gdb_printf (file,
"gdbarch_dump: read_core_file_mappings = <%s>\n",
host_address_to_string (gdbarch->read_core_file_mappings));
+ gdb_printf (file,
+ "gdbarch_dump: use_target_description_from_corefile_notes = <%s>\n",
+ host_address_to_string (gdbarch->use_target_description_from_corefile_notes));
if (gdbarch->dump_tdep != NULL)
gdbarch->dump_tdep (gdbarch, file);
}
@@ -5409,3 +5414,20 @@ set_gdbarch_read_core_file_mappings (struct gdbarch *gdbarch,
{
gdbarch->read_core_file_mappings = read_core_file_mappings;
}
+
+bool
+gdbarch_use_target_description_from_corefile_notes (struct gdbarch *gdbarch, struct bfd *corefile_bfd)
+{
+ gdb_assert (gdbarch != NULL);
+ gdb_assert (gdbarch->use_target_description_from_corefile_notes != NULL);
+ if (gdbarch_debug >= 2)
+ gdb_printf (gdb_stdlog, "gdbarch_use_target_description_from_corefile_notes called\n");
+ return gdbarch->use_target_description_from_corefile_notes (gdbarch, corefile_bfd);
+}
+
+void
+set_gdbarch_use_target_description_from_corefile_notes (struct gdbarch *gdbarch,
+ gdbarch_use_target_description_from_corefile_notes_ftype use_target_description_from_corefile_notes)
+{
+ gdbarch->use_target_description_from_corefile_notes = use_target_description_from_corefile_notes;
+}