aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorYao Qi <yao.qi@linaro.org>2017-09-05 09:54:53 +0100
committerYao Qi <yao.qi@linaro.org>2017-09-05 09:54:53 +0100
commit0a188386c032126045979b7fb7c238d715c81eb5 (patch)
tree7a34674b979bf52bd421901a608bfad9417f9e5a /gdb
parentf49ff00066929bf7c38f9c89ad640561bbb331f6 (diff)
downloadgdb-0a188386c032126045979b7fb7c238d715c81eb5.zip
gdb-0a188386c032126045979b7fb7c238d715c81eb5.tar.gz
gdb-0a188386c032126045979b7fb7c238d715c81eb5.tar.bz2
[GDBserver] unit test to i386_tdesc
This patch adds a unit test in GDBserver to test dynamically created target descriptions equal these pre-generated ones. gdb/gdbserver: 2017-09-05 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-09-05 Yao Qi <yao.qi@linaro.org> * regformats/regdef.h (struct reg): Override operator == and !=.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog4
-rw-r--r--gdb/gdbserver/ChangeLog8
-rw-r--r--gdb/gdbserver/linux-x86-tdesc.c37
-rw-r--r--gdb/gdbserver/tdesc.h42
-rw-r--r--gdb/regformats/regdef.h12
5 files changed, 102 insertions, 1 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index cebd4f5..8413504 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,9 @@
2017-09-05 Yao Qi <yao.qi@linaro.org>
+ * regformats/regdef.h (struct reg): Override operator == and !=.
+
+2017-09-05 Yao Qi <yao.qi@linaro.org>
+
* arch/tdesc.h: New file.
* regformats/regdat.sh: Generate code using tdesc_create_reg.
* target-descriptions.c: Update comments.
diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
index 66e9f53..20a0c97 100644
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,5 +1,13 @@
2017-09-05 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 !=.
+
+2017-09-05 Yao Qi <yao.qi@linaro.org>
+
* configure.srv (srv_tgtobj): Append linux-x86-tdesc.o.
(ipa_obj): Likewise.
* linux-i386-ipa.c: Include common/x86-xstate.h
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 */