From: Yao Qi <qiyaoltc@gmail.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 06/15] regcache::cooked_write test
Date: Fri, 01 Dec 2017 10:48:00 -0000 [thread overview]
Message-ID: <1512125286-29788-7-git-send-email-yao.qi@linaro.org> (raw)
In-Reply-To: <1512125286-29788-1-git-send-email-yao.qi@linaro.org>
Since my following patches will change how each gdbarch read and write
pseudo registers, it's better to write a unit test to
regcache::cooked_write, to make sure my following changes don't cause
any regressions. See the comments on cooked_write_test.
gdb:
2017-11-27 Yao Qi <yao.qi@linaro.org>
* regcache.c (cooked_write_test): New function.
(_initialize_regcache): Register the test.
---
gdb/regcache.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 124 insertions(+)
diff --git a/gdb/regcache.c b/gdb/regcache.c
index a7a4683..4577913 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -1609,6 +1609,7 @@ maintenance_print_remote_registers (const char *args, int from_tty)
#include "selftest.h"
#include "selftest-arch.h"
#include "gdbthread.h"
+#include "target-float.h"
namespace selftests {
@@ -1926,6 +1927,127 @@ cooked_read_test (struct gdbarch *gdbarch)
}
}
+/* Test regcache::cooked_write by writing some expected contents to
+ registers, and checking that contents red from registers and the
+ expected contents are the same. */
+
+static void
+cooked_write_test (struct gdbarch *gdbarch)
+{
+ /* Error out if debugging something, because we're going to push the
+ test target, which would pop any existing target. */
+ if (current_target.to_stratum >= process_stratum)
+ error (_("target already pushed"));
+
+ /* Create a mock environment. A process_stratum target pushed. */
+
+ target_ops_no_register mock_target;
+
+ /* Push the process_stratum target so we can mock accessing
+ registers. */
+ push_target (&mock_target);
+
+ /* Pop it again on exit (return/exception). */
+ struct on_exit
+ {
+ ~on_exit ()
+ {
+ pop_all_targets_at_and_above (process_stratum);
+ }
+ } pop_targets;
+
+ readwrite_regcache readwrite (gdbarch);
+
+ const int num_regs = (gdbarch_num_regs (gdbarch)
+ + gdbarch_num_pseudo_regs (gdbarch));
+
+ for (auto regnum = 0; regnum < num_regs; regnum++)
+ {
+ if (register_size (gdbarch, regnum) == 0
+ || gdbarch_cannot_store_register (gdbarch, regnum))
+ continue;
+
+ auto bfd_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
+
+ if ((bfd_arch == bfd_arch_sparc
+ /* SPARC64_CWP_REGNUM, SPARC64_PSTATE_REGNUM,
+ SPARC64_ASI_REGNUM and SPARC64_CCR_REGNUM are hard to test. */
+ && gdbarch_ptr_bit (gdbarch) == 64
+ && (regnum >= gdbarch_num_regs (gdbarch)
+ && regnum <= gdbarch_num_regs (gdbarch) + 4))
+ || (bfd_arch == bfd_arch_sh
+ /* FPSCR_C_REGNUM in sh64 is hard to test. */
+ && gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_sh5
+ && regnum == 243)
+ || (bfd_arch == bfd_arch_spu
+ /* SPU pseudo registers except SPU_SP_REGNUM are got by
+ TARGET_OBJECT_SPU. */
+ && regnum >= gdbarch_num_regs (gdbarch) && regnum != 130))
+ continue;
+
+ std::vector<gdb_byte> expected (register_size (gdbarch, regnum), 0);
+ std::vector<gdb_byte> buf (register_size (gdbarch, regnum), 0);
+ const auto type = register_type (gdbarch, regnum);
+
+ if (TYPE_CODE (type) == TYPE_CODE_FLT
+ || TYPE_CODE (type) == TYPE_CODE_DECFLOAT)
+ {
+ /* Generate valid float format. */
+ target_float_from_string (expected.data (), type, "1.25");
+ }
+ else if (TYPE_CODE (type) == TYPE_CODE_INT
+ || TYPE_CODE (type) == TYPE_CODE_ARRAY
+ || TYPE_CODE (type) == TYPE_CODE_PTR
+ || TYPE_CODE (type) == TYPE_CODE_UNION
+ || TYPE_CODE (type) == TYPE_CODE_STRUCT)
+ {
+ if (bfd_arch == bfd_arch_ia64
+ || (regnum >= gdbarch_num_regs (gdbarch)
+ && (bfd_arch == bfd_arch_xtensa
+ || bfd_arch == bfd_arch_bfin
+ || bfd_arch == bfd_arch_m32c
+ /* m68hc11 pseudo registers are in memory. */
+ || bfd_arch == bfd_arch_m68hc11
+ || bfd_arch == bfd_arch_m68hc12
+ || bfd_arch == bfd_arch_s390))
+ || (bfd_arch == bfd_arch_frv
+ /* FRV pseudo registers except iacc0. */
+ && regnum > gdbarch_num_regs (gdbarch)))
+ {
+ /* Skip setting the expected values for some architecture
+ registers. */
+ }
+ else if (bfd_arch == bfd_arch_rl78 && regnum == 40)
+ {
+ /* RL78_PC_REGNUM */
+ for (auto j = 0; j < register_size (gdbarch, regnum) - 1; j++)
+ expected[j] = j;
+ }
+ else
+ {
+ for (auto j = 0; j < register_size (gdbarch, regnum); j++)
+ expected[j] = j;
+ }
+ }
+ else if (TYPE_CODE (type) == TYPE_CODE_FLAGS)
+ {
+ /* No idea how to test flags. */
+ continue;
+ }
+ else
+ {
+ /* If we don't know how to create the expected value for the
+ this type, make it fail. */
+ SELF_CHECK (0);
+ }
+
+ readwrite.cooked_write (regnum, expected.data ());
+
+ SELF_CHECK (readwrite.cooked_read (regnum, buf.data ()) == REG_VALID);
+ SELF_CHECK (expected == buf);
+ }
+}
+
} // namespace selftests
#endif /* GDB_SELF_TEST */
@@ -1972,5 +2094,7 @@ Takes an optional file parameter."),
selftests::register_test_foreach_arch ("regcache::cooked_read_test",
selftests::cooked_read_test);
+ selftests::register_test_foreach_arch ("regcache::cooked_write_test",
+ selftests::cooked_write_test);
#endif
}
--
1.9.1
next prev parent reply other threads:[~2017-12-01 10:48 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-01 10:48 [RFC 00/15] Remove regcache::m_readonly_p Yao Qi
2017-12-01 10:48 ` [PATCH 10/15] Class regcache_readonly Yao Qi
2018-01-24 3:05 ` Simon Marchi
2018-01-24 9:43 ` Yao Qi
2018-01-24 16:57 ` Simon Marchi
2018-01-24 17:37 ` Yao Qi
2018-01-24 18:01 ` Simon Marchi
2018-01-24 21:01 ` Yao Qi
2017-12-01 10:48 ` [PATCH 05/15] regcache_cooked_read -> regcache->cooked_read Yao Qi
2017-12-01 10:48 ` Yao Qi [this message]
2018-01-18 16:13 ` [PATCH 06/15] regcache::cooked_write test Simon Marchi
2018-01-22 11:12 ` Yao Qi
2017-12-01 10:48 ` [PATCH 01/15] Call cooked_read in ppu2spu_prev_register Yao Qi
2018-01-16 16:19 ` Yao Qi
2018-01-16 18:05 ` Ulrich Weigand
2018-01-18 12:22 ` Yao Qi
2017-12-01 10:48 ` [PATCH 09/15] Remove regcache_save and regcache_cpy Yao Qi
2017-12-01 10:48 ` [PATCH 04/15] Replace regcache_raw_read with regcache->raw_read Yao Qi
2017-12-01 10:48 ` [PATCH 14/15] Remove regcache::m_readonly_p Yao Qi
2017-12-01 10:48 ` [PATCH 15/15] Move register_dump to regcache-dump.c Yao Qi
2017-12-01 10:48 ` [PATCH 03/15] Remove mt port Yao Qi
2017-12-01 10:48 ` [PATCH 13/15] No longer create readonly regcache Yao Qi
2017-12-01 10:48 ` [PATCH 12/15] Replace regcache::dump with class register_dump Yao Qi
2017-12-01 10:48 ` [PATCH 08/15] class regcache_read and Pass regcache_read to gdbarch methods Yao Qi
2018-01-23 21:51 ` Simon Marchi
2018-01-23 22:28 ` Yao Qi
2017-12-01 10:48 ` [PATCH 02/15] Don't call gdbarch_pseudo_register_read_value in jit.c Yao Qi
2017-12-01 10:48 ` [PATCH 07/15] Class reg_buffer Yao Qi
2017-12-01 10:48 ` [PATCH 11/15] Class reg_buffer_rw Yao Qi
2018-01-16 16:18 ` [RFC 00/15] Remove regcache::m_readonly_p Yao Qi
2018-01-18 16:56 ` Simon Marchi
2018-01-22 14:58 ` Yao Qi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1512125286-29788-7-git-send-email-yao.qi@linaro.org \
--to=qiyaoltc@gmail.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox