From: Yao Qi <qiyaoltc@gmail.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 09/22] [GDBserver] unit test to i386_tdesc
Date: Mon, 21 Aug 2017 15:29:00 -0000 [thread overview]
Message-ID: <1503329347-26711-10-git-send-email-yao.qi@linaro.org> (raw)
In-Reply-To: <1503329347-26711-1-git-send-email-yao.qi@linaro.org>
This patch adds a unit test in GDBserver to test dynamically created
target descriptions equal these pre-generated ones.
gdb/gdbserver:
2017-07-07 Yao Qi <yao.qi@linaro.org>
* linux-x86-tdesc.c: Include selftest.h.
(i386_tdesc_test): New function.
(initialize_low_tdesc): Call selftests::register_test.
* tdesc.h: Include regdef.h.
(target_desc): Override operator == and !=.
gdb:
2017-07-07 Yao Qi <yao.qi@linaro.org>
* regformats/regdef.h (struct reg): Override operator == and !=.
---
gdb/gdbserver/linux-x86-tdesc.c | 37 ++++++++++++++++++++++++++++++++++++
gdb/gdbserver/tdesc.h | 42 ++++++++++++++++++++++++++++++++++++++++-
gdb/regformats/regdef.h | 12 ++++++++++++
3 files changed, 90 insertions(+), 1 deletion(-)
diff --git a/gdb/gdbserver/linux-x86-tdesc.c b/gdb/gdbserver/linux-x86-tdesc.c
index 0d0be83..1f3dbaf 100644
--- a/gdb/gdbserver/linux-x86-tdesc.c
+++ b/gdb/gdbserver/linux-x86-tdesc.c
@@ -63,6 +63,39 @@ extern const struct target_desc *tdesc_i386_mpx_linux;
static struct target_desc *i386_tdescs[X86_TDESC_LAST] = { };
+#if defined GDB_SELF_TEST && !defined IN_PROCESS_AGENT
+#include "selftest.h"
+
+namespace selftests {
+namespace tdesc {
+static void
+i386_tdesc_test ()
+{
+ struct
+ {
+ unsigned int mask;
+ const target_desc *tdesc;
+ } tdesc_tests[] = {
+ { X86_XSTATE_X87, tdesc_i386_mmx_linux },
+ { X86_XSTATE_SSE_MASK, tdesc_i386_linux },
+ { X86_XSTATE_AVX_MASK, tdesc_i386_avx_linux },
+ { X86_XSTATE_MPX_MASK, tdesc_i386_mpx_linux },
+ { X86_XSTATE_AVX_MPX_MASK, tdesc_i386_avx_mpx_linux },
+ { X86_XSTATE_AVX_AVX512_MASK, tdesc_i386_avx_avx512_linux },
+ { X86_XSTATE_AVX_MPX_AVX512_PKU_MASK, tdesc_i386_avx_mpx_avx512_pku_linux }
+ };
+
+ for (auto &elem : tdesc_tests)
+ {
+ const target_desc *tdesc = i386_linux_read_description (elem.mask);
+
+ SELF_CHECK (*tdesc == *elem.tdesc);
+ }
+}
+}
+} // namespace selftests
+#endif /* GDB_SELF_TEST */
+
void
initialize_low_tdesc ()
{
@@ -74,6 +107,10 @@ initialize_low_tdesc ()
init_registers_i386_avx_mpx_linux ();
init_registers_i386_avx_avx512_linux ();
init_registers_i386_avx_mpx_avx512_pku_linux ();
+
+#if GDB_SELF_TEST && !defined IN_PROCESS_AGENT
+ selftests::register_test (selftests::tdesc::i386_tdesc_test);
+#endif
#endif
}
diff --git a/gdb/gdbserver/tdesc.h b/gdb/gdbserver/tdesc.h
index 50d0364..49c82c6 100644
--- a/gdb/gdbserver/tdesc.h
+++ b/gdb/gdbserver/tdesc.h
@@ -21,7 +21,7 @@
#include "arch/tdesc.h"
-struct reg;
+#include "regdef.h"
typedef struct reg *tdesc_reg_p;
DEF_VEC_P(tdesc_reg_p);
@@ -66,6 +66,46 @@ public:
xfree (reg);
VEC_free (tdesc_reg_p, reg_defs);
}
+
+ bool operator== (const target_desc &other) const
+ {
+ if (VEC_length (tdesc_reg_p, reg_defs)
+ != VEC_length (tdesc_reg_p, other.reg_defs))
+ return false;
+
+ struct reg *reg;
+
+ for (int ix = 0;
+ VEC_iterate (tdesc_reg_p, reg_defs, ix, reg);
+ ix++)
+ {
+ struct reg *reg2
+ = VEC_index (tdesc_reg_p, other.reg_defs, ix);
+
+ if (reg != reg2 && *reg != *reg2)
+ return false;
+ }
+
+ /* Compare expedite_regs. */
+ int i = 0;
+ for (; expedite_regs[i] != NULL; i++)
+ {
+ if (strcmp (expedite_regs[i], other.expedite_regs[i]) != 0)
+ return false;
+ }
+ if (other.expedite_regs[i] != NULL)
+ return false;
+
+ if (strcmp (xmltarget, other.xmltarget) != 0)
+ return false;
+
+ return true;
+ }
+
+ bool operator!= (const target_desc &other) const
+ {
+ return !(*this == other);
+ }
#endif
};
diff --git a/gdb/regformats/regdef.h b/gdb/regformats/regdef.h
index de7a010..ff1d40b 100644
--- a/gdb/regformats/regdef.h
+++ b/gdb/regformats/regdef.h
@@ -34,6 +34,18 @@ struct reg
/* The size (in bits) of the value of this register, as transmitted. */
int size;
+
+ bool operator== (const reg &other) const
+ {
+ return (strcmp (name, other.name) == 0
+ && offset == other.offset
+ && size == other.size);
+ }
+
+ bool operator!= (const reg &other) const
+ {
+ return !(*this == other);
+ }
};
#endif /* REGDEF_H */
--
1.9.1
next prev parent reply other threads:[~2017-08-21 15:29 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-21 15:29 [PATCH 00/22 v4] Make GDB builtin target descriptions more flexible Yao Qi
2017-08-21 15:29 ` [PATCH 16/22] Centralize amd64-linux target descriptions Yao Qi
2017-08-21 15:29 ` [PATCH 15/22] Update comments in amd64_linux_core_read_description Yao Qi
2017-08-21 15:29 ` [PATCH 01/22] Use amd64_target_description to get tdesc_amd64 Yao Qi
2017-08-21 15:29 ` [PATCH 04/22] Let i386_target_description return tdesc_i386_mmx Yao Qi
2017-08-21 15:29 ` [PATCH 03/22] Return X86_XSTATE_SSE_MASK instead of 0 in i386fbsd_core_read_xcr0 Yao Qi
2017-08-21 16:23 ` John Baldwin
2017-08-21 16:46 ` Yao Qi
2017-08-21 17:00 ` John Baldwin
2017-08-21 15:29 ` [PATCH 20/22] [GDBserver] Shorten srv_amd64_linux_xmlfiles Yao Qi
2017-08-21 15:29 ` Yao Qi [this message]
2017-08-21 15:29 ` [PATCH 19/22] [GDBserver] Use pre-generated amd64-linux tdesc as test Yao Qi
2017-08-21 15:29 ` [PATCH 08/22] [GDBserver] Centralize tdesc for i386-linux Yao Qi
2017-08-21 15:29 ` [PATCH 05/22] Adjust code generated by regformats/regdat.sh Yao Qi
2017-08-21 15:29 ` [PATCH 11/22] Share i386-linux target description between GDB and GDBserver Yao Qi
2017-08-21 15:30 ` [PATCH 18/22] Convert amd64-linux target descriptions Yao Qi
2017-08-21 15:31 ` [PATCH 21/22] Remove features/i386/amd64-*linux.c and features/i386/x32-*linux.c Yao Qi
2017-08-21 15:31 ` [PATCH 17/22] Lazily and dynamically create amd64-linux target descriptions Yao Qi
2017-08-21 15:31 ` [PATCH 12/22] Remove features/i386/i386-*linux.c Yao Qi
2017-08-21 15:31 ` [PATCH 22/22] Convert the rest x86 target descriptions Yao Qi
2017-08-21 15:31 ` [PATCH 10/22] Dynamically composite xml in reply to GDB Yao Qi
2017-08-21 15:31 ` [PATCH 14/22] [GDBserver] Shorten srv_i386_linux_xmlfiles Yao Qi
2017-08-21 15:31 ` [PATCH 13/22] [GDBserver] Use pre-generated tdesc as test Yao Qi
2017-08-21 15:31 ` [PATCH 02/22] Use i386_target_description to get tdesc_i386 Yao Qi
2017-08-21 16:23 ` John Baldwin
2017-08-21 15:31 ` [PATCH 07/22] Return X86_TDESC_MMX in x86_get_ipa_tdesc_idx Yao Qi
2017-08-21 15:31 ` [PATCH 06/22] Use VEC for target_desc.reg_defs Yao Qi
2017-09-05 9:04 ` [PATCH 00/22 v4] Make GDB builtin target descriptions more flexible 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=1503329347-26711-10-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