From: Luis Machado Date: Mon, 15 Jun 2020 18:11:07 +0000 (-0300) Subject: AArch64: Add unit testing for logical tag set/get operations X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b4a7d4fcfef4e0ca3c5de52efbaf33c1c98295eb;p=binutils-gdb.git AArch64: Add unit testing for logical tag set/get operations Add some unit testing to exercise setting/getting logical tags in the AArch64 implementation. gdb/ChangeLog: 2021-03-24 Luis Machado * aarch64-linux-tdep.c: Include gdbsupport/selftest.h. (aarch64_linux_ltag_tests): New function. (_initialize_aarch64_linux_tdep): Register aarch64_linux_ltag_tests. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 03cbd5cf0e1..ce3373ba9d0 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2021-03-24 Luis Machado + + * aarch64-linux-tdep.c: Include gdbsupport/selftest.h. + (aarch64_linux_ltag_tests): New function. + (_initialize_aarch64_linux_tdep): Register aarch64_linux_ltag_tests. + 2021-03-24 Luis Machado * aarch64-linux-tdep.c: Include target.h, arch-utils.h, value.h. diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c index d573f06436a..e71f062e25d 100644 --- a/gdb/aarch64-linux-tdep.c +++ b/gdb/aarch64-linux-tdep.c @@ -51,6 +51,8 @@ #include "arch-utils.h" #include "value.h" +#include "gdbsupport/selftest.h" + /* Signal frame handling. +------------+ ^ @@ -1940,10 +1942,39 @@ aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) set_gdbarch_gcc_target_options (gdbarch, aarch64_linux_gcc_target_options); } +#if GDB_SELF_TEST + +namespace selftests { + +/* Verify functions to read and write logical tags. */ + +static void +aarch64_linux_ltag_tests (void) +{ + /* We have 4 bits of tags, but we test writing all the bits of the top + byte of address. */ + for (int i = 0; i < 1 << 8; i++) + { + CORE_ADDR addr = ((CORE_ADDR) i << 56) | 0xdeadbeef; + SELF_CHECK (aarch64_mte_get_ltag (addr) == (i & 0xf)); + + addr = aarch64_mte_set_ltag (0xdeadbeef, i); + SELF_CHECK (addr = ((CORE_ADDR) (i & 0xf) << 56) | 0xdeadbeef); + } +} + +} // namespace selftests +#endif /* GDB_SELF_TEST */ + void _initialize_aarch64_linux_tdep (); void _initialize_aarch64_linux_tdep () { gdbarch_register_osabi (bfd_arch_aarch64, 0, GDB_OSABI_LINUX, aarch64_linux_init_abi); + +#if GDB_SELF_TEST + selftests::register_test ("aarch64-linux-tagged-address", + selftests::aarch64_linux_ltag_tests); +#endif }