aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorYao Qi <yao.qi@linaro.org>2017-05-09 12:36:53 +0100
committerYao Qi <yao.qi@linaro.org>2017-05-09 12:36:53 +0100
commit8248946cc5fd4522de630b9d86627af6e8fe0097 (patch)
tree4b3a95b65ad79c7201c1fc636106dacbcbdf659c /gdb
parente645cf40b111daef4518a58547de577eb9379ccb (diff)
downloadgdb-8248946cc5fd4522de630b9d86627af6e8fe0097.zip
gdb-8248946cc5fd4522de630b9d86627af6e8fe0097.tar.gz
gdb-8248946cc5fd4522de630b9d86627af6e8fe0097.tar.bz2
Add current_regcache unit test
This patch adds a unit test to current_regcache, to make sure it is correctly updated by get_thread_arch_aspace_regcache and registers_changed_ptid. gdb: 2017-05-09 Yao Qi <yao.qi@linaro.org> * regcache.c [GDB_SELF_TEST]: Include selftest.h. (current_regcache_size): New function. (current_regcache_test): New function. (_initialize_regcache) [GDB_SELF_TEST]: Register the unit test.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog7
-rw-r--r--gdb/regcache.c75
2 files changed, 81 insertions, 1 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index fec0727..cec3058 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2017-05-09 Yao Qi <yao.qi@linaro.org>
+
+ * regcache.c [GDB_SELF_TEST]: Include selftest.h.
+ (current_regcache_size): New function.
+ (current_regcache_test): New function.
+ (_initialize_regcache) [GDB_SELF_TEST]: Register the unit test.
+
2017-05-08 Alan Hayward <alan.hayward@arm.com>
* mips-tdep.c (mips_o32_return_value): Remove unused buffer.
diff --git a/gdb/regcache.c b/gdb/regcache.c
index d2c253a..07b1c97 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -1699,6 +1699,77 @@ maintenance_print_remote_registers (char *args, int from_tty)
regcache_print (args, regcache_dump_remote);
}
+#if GDB_SELF_TEST
+#include "selftest.h"
+
+namespace selftests {
+
+/* Return the number of elements in current_regcache. */
+
+static size_t
+current_regcache_size ()
+{
+ size_t i = 0;
+ for (auto list = current_regcache; list; list = list->next)
+ i++;
+
+ return i;
+}
+
+static void
+current_regcache_test (void)
+{
+ /* It is empty at the start. */
+ SELF_CHECK (current_regcache_size () == 0);
+
+ ptid_t ptid1 (1), ptid2 (2), ptid3 (3);
+
+ /* Get regcache from ptid1, a new regcache is added to
+ current_regcache. */
+ regcache *regcache = get_thread_arch_aspace_regcache (ptid1,
+ target_gdbarch (),
+ NULL);
+
+ SELF_CHECK (regcache != NULL);
+ SELF_CHECK (regcache->ptid () == ptid1);
+ SELF_CHECK (current_regcache_size () == 1);
+
+ /* Get regcache from ptid2, a new regcache is added to
+ current_regcache. */
+ regcache = get_thread_arch_aspace_regcache (ptid2,
+ target_gdbarch (),
+ NULL);
+ SELF_CHECK (regcache != NULL);
+ SELF_CHECK (regcache->ptid () == ptid2);
+ SELF_CHECK (current_regcache_size () == 2);
+
+ /* Get regcache from ptid3, a new regcache is added to
+ current_regcache. */
+ regcache = get_thread_arch_aspace_regcache (ptid3,
+ target_gdbarch (),
+ NULL);
+ SELF_CHECK (regcache != NULL);
+ SELF_CHECK (regcache->ptid () == ptid3);
+ SELF_CHECK (current_regcache_size () == 3);
+
+ /* Get regcache from ptid2 again, nothing is added to
+ current_regcache. */
+ regcache = get_thread_arch_aspace_regcache (ptid2,
+ target_gdbarch (),
+ NULL);
+ SELF_CHECK (regcache != NULL);
+ SELF_CHECK (regcache->ptid () == ptid2);
+ SELF_CHECK (current_regcache_size () == 3);
+
+ /* Mark ptid2 is changed, so regcache of ptid2 should be removed from
+ current_regcache. */
+ registers_changed_ptid (ptid2);
+ SELF_CHECK (current_regcache_size () == 2);
+}
+
+} // namespace selftests
+#endif /* GDB_SELF_TEST */
+
extern initialize_file_ftype _initialize_regcache; /* -Wmissing-prototype */
void
@@ -1738,5 +1809,7 @@ Print the internal register configuration including each register's\n\
remote register number and buffer offset in the g/G packets.\n\
Takes an optional file parameter."),
&maintenanceprintlist);
-
+#if GDB_SELF_TEST
+ register_self_test (selftests::current_regcache_test);
+#endif
}