forked from Imagelibrary/binutils-gdb
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>
This commit is contained in:
@@ -2199,6 +2199,33 @@ aarch64_linux_decode_memtag_section (struct gdbarch *gdbarch,
|
||||
return tags;
|
||||
}
|
||||
|
||||
/* AArch64 Linux implementation of the
|
||||
gdbarch_use_target_description_from_corefile_notes hook. */
|
||||
|
||||
static bool
|
||||
aarch64_use_target_description_from_corefile_notes (gdbarch *gdbarch,
|
||||
bfd *obfd)
|
||||
{
|
||||
/* Sanity check. */
|
||||
gdb_assert (obfd != nullptr);
|
||||
|
||||
/* If the corefile contains any SVE or SME register data, we don't want to
|
||||
use the target description note, as it may be incorrect.
|
||||
|
||||
Currently the target description note contains a potentially incorrect
|
||||
target description if the originating program changed the SVE or SME
|
||||
vector lengths mid-execution.
|
||||
|
||||
Once we support per-thread target description notes in the corefiles, we
|
||||
can always trust those notes whenever they are available. */
|
||||
if (bfd_get_section_by_name (obfd, ".reg-aarch-sve") != nullptr
|
||||
|| bfd_get_section_by_name (obfd, ".reg-aarch-za") != nullptr
|
||||
|| bfd_get_section_by_name (obfd, ".reg-aarch-zt") != nullptr)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void
|
||||
aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
|
||||
{
|
||||
@@ -2469,6 +2496,12 @@ aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
|
||||
aarch64_displaced_step_hw_singlestep);
|
||||
|
||||
set_gdbarch_gcc_target_options (gdbarch, aarch64_linux_gcc_target_options);
|
||||
|
||||
/* Hook to decide if the target description should be obtained from
|
||||
corefile target description note(s) or inferred from the corefile
|
||||
sections. */
|
||||
set_gdbarch_use_target_description_from_corefile_notes (gdbarch,
|
||||
aarch64_use_target_description_from_corefile_notes);
|
||||
}
|
||||
|
||||
#if GDB_SELF_TEST
|
||||
|
||||
Reference in New Issue
Block a user