aboutsummaryrefslogtreecommitdiff
path: root/gdb/gdbarch-selftests.c
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2022-08-30 15:21:47 +0100
committerAndrew Burgess <aburgess@redhat.com>2022-10-02 14:21:24 +0100
commit9a972b54040c6791a163b65a27d24d1acad7c397 (patch)
tree839d94225a4640966b5c1bba18479a7d4f1a465c /gdb/gdbarch-selftests.c
parent89e601ac3a2e29da46275a3dcb83855e662fb0c9 (diff)
downloadgdb-9a972b54040c6791a163b65a27d24d1acad7c397.zip
gdb-9a972b54040c6791a163b65a27d24d1acad7c397.tar.gz
gdb-9a972b54040c6791a163b65a27d24d1acad7c397.tar.bz2
gdb: add a gdbarch_register_name self test, and fix some architectures
This commit adds a self-test that checks that gdbarch_register_name never returns nullptr for any valid register number. Most architectures already met this requirement, there were just 6 that failed the new selftest, and are updated in this commit. Beyond the self-tests I don't have any facilities to test that the architectures I've adjusted still work correctly. If you review all the various gdbarch_register_name implementations then you will see that there are far more architectures that seem like they might return nullptr in some situations, e.g. alpha, avr, bpf, etc. This commit doesn't attempt to address these cases as non of them are hit during the selftest. Many of these cases can never be hit, for example, in alpha_register_name GDB checks for a register number less than zero, this case can't happen and could be changed into an assert. A later commit in this series will have a general cleanup of all the various register_name methods, and remove all references to NULL from their code, however, as that commit will be mostly adjusting code that is never hit, I want to keep those changes separate. The selftest has been tested on x86-64, but I don't have access to suitable systems to fully test any of the *-tdep.c code I've changed in this commit.
Diffstat (limited to 'gdb/gdbarch-selftests.c')
-rw-r--r--gdb/gdbarch-selftests.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/gdb/gdbarch-selftests.c b/gdb/gdbarch-selftests.c
index 68d340f..6825441 100644
--- a/gdb/gdbarch-selftests.c
+++ b/gdb/gdbarch-selftests.c
@@ -122,6 +122,30 @@ register_to_value_test (struct gdbarch *gdbarch)
}
}
+/* Test function gdbarch_register_name. */
+
+static void
+register_name_test (struct gdbarch *gdbarch)
+{
+ scoped_mock_context<test_target_ops> mockctx (gdbarch);
+
+ const int num_regs = gdbarch_num_cooked_regs (gdbarch);
+ for (auto regnum = 0; regnum < num_regs; regnum++)
+ {
+ /* If a register is to be hidden from the user then we should get
+ back an empty string, not nullptr. Every other register should
+ return a non-empty string. */
+ const char *name = gdbarch_register_name (gdbarch, regnum);
+
+ if (run_verbose() && name == nullptr)
+ debug_printf ("arch: %s, register: %d returned nullptr\n",
+ gdbarch_bfd_arch_info (gdbarch)->printable_name,
+ regnum);
+
+ SELF_CHECK (name != nullptr);
+ }
+}
+
} // namespace selftests
void _initialize_gdbarch_selftests ();
@@ -130,4 +154,7 @@ _initialize_gdbarch_selftests ()
{
selftests::register_test_foreach_arch ("register_to_value",
selftests::register_to_value_test);
+
+ selftests::register_test_foreach_arch ("register_name",
+ selftests::register_name_test);
}