public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 03/25] Class-fy tdesc_reg tdesc_type and tdesc_feature
  2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
                   ` (14 preceding siblings ...)
  2017-06-12  8:42 ` [PATCH 01/25] Move initialize_tdesc_mips* calls from mips-linux-nat.c to mips-linux-tdep.c Yao Qi
@ 2017-06-12  8:42 ` Yao Qi
  2017-06-19 20:55   ` Simon Marchi
  2017-06-19 21:30   ` Simon Marchi
  2017-06-12  8:42 ` [PATCH 19/25] GDBserver: remove srv_i386_linux_xmlfiles Yao Qi
                   ` (10 subsequent siblings)
  26 siblings, 2 replies; 82+ messages in thread
From: Yao Qi @ 2017-06-12  8:42 UTC (permalink / raw)
  To: gdb-patches

This patch class-fies them, adding ctor, dtor, and deleting
copy ctor and assignment operator.

gdb:

2017-05-20  Yao Qi  <yao.qi@linaro.org>

	* target-descriptions.c (tdesc_reg): Add ctor, dtor.
	Delete copy ctor and assignment operator.
	(tdesc_type): Likewise.
	(tdesc_feature): Likewise.
	(tdesc_free_reg): Remove.
	(tdesc_create_reg): Use new.
	(tdesc_free_type): Remove.
	(tdesc_create_vector): Use new.
	(tdesc_create_union): Likewise.
	(tdesc_create_flags): Likewise.
	(tdesc_create_enum): Likewise.
	(tdesc_free_feature): Delete.
	(free_target_description): Use delete.
---
 gdb/target-descriptions.c | 200 +++++++++++++++++++++++-----------------------
 1 file changed, 100 insertions(+), 100 deletions(-)

diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
index 9a7e2dd..e2dcd1d 100644
--- a/gdb/target-descriptions.c
+++ b/gdb/target-descriptions.c
@@ -48,6 +48,32 @@ DEF_VEC_O(property_s);
 
 typedef struct tdesc_reg
 {
+public:
+  tdesc_reg (struct tdesc_feature *feature, const char *name_,
+	     int regnum, int save_restore_, const char *group_,
+	     int bitsize_, const char *type_)
+    : name (xstrdup (name_)), target_regnum (regnum),
+      save_restore (save_restore_),
+      group (group_ ? xstrdup (group_) : NULL),
+      bitsize (bitsize_),
+      type (type_ ? xstrdup (type_) : xstrdup ("<unknown>"))
+  {
+    /* If the register's type is target-defined, look it up now.  We may not
+       have easy access to the containing feature when we want it later.  */
+    tdesc_type = tdesc_named_type (feature, type);
+  }
+
+  ~tdesc_reg ()
+  {
+    xfree (name);
+    xfree (type);
+    xfree (group);
+  }
+
+  /* Disable copying.  */
+  tdesc_reg (const tdesc_reg &) = delete;
+  tdesc_reg &operator= (const tdesc_reg &) = delete;
+
   /* The name of this register.  In standard features, it may be
      recognized by the architecture support code, or it may be purely
      for the user.  */
@@ -128,6 +154,43 @@ enum tdesc_type_kind
 
 typedef struct tdesc_type
 {
+public:
+  tdesc_type (const char *name_, enum tdesc_type_kind kind_)
+    : name (xstrdup (name_)), kind (kind_)
+  {
+    memset (&u, 0, sizeof (u));
+  }
+
+  ~tdesc_type ()
+  {
+    switch (kind)
+      {
+      case TDESC_TYPE_STRUCT:
+      case TDESC_TYPE_UNION:
+      case TDESC_TYPE_FLAGS:
+      case TDESC_TYPE_ENUM:
+	{
+	  struct tdesc_type_field *f;
+	  int ix;
+
+	  for (ix = 0;
+	       VEC_iterate (tdesc_type_field, u.u.fields, ix, f);
+	       ix++)
+	    xfree (f->name);
+
+	  VEC_free (tdesc_type_field, u.u.fields);
+	}
+	break;
+
+      default:
+	break;
+      }
+    xfree ((char *) name);
+  }
+  /* Disable copying.  */
+  tdesc_type (const tdesc_type &) = delete;
+  tdesc_type &operator= (const tdesc_type &) = delete;
+
   /* The name of this type.  If this type is a built-in type, this is
      a pointer to a constant string.  Otherwise, it's a
      malloc-allocated string (and thus must be freed).  */
@@ -161,15 +224,41 @@ DEF_VEC_P(tdesc_type_p);
 
 typedef struct tdesc_feature
 {
+public:
+  tdesc_feature (const char *name_)
+    : name (xstrdup (name_))
+  {}
+
+  ~tdesc_feature ()
+  {
+    struct tdesc_reg *reg;
+    struct tdesc_type *type;
+    int ix;
+
+    for (ix = 0; VEC_iterate (tdesc_reg_p, registers, ix, reg); ix++)
+      delete reg;
+    VEC_free (tdesc_reg_p, registers);
+
+    for (ix = 0; VEC_iterate (tdesc_type_p, types, ix, type); ix++)
+      delete type;
+    VEC_free (tdesc_type_p, types);
+
+    xfree (name);
+  }
+
+  /* Disable copying.  */
+  tdesc_feature (const tdesc_feature &) = delete;
+  tdesc_feature &operator= (const tdesc_feature &) = delete;
+
   /* The name of this feature.  It may be recognized by the architecture
      support code.  */
   char *name;
 
   /* The registers associated with this feature.  */
-  VEC(tdesc_reg_p) *registers;
+  VEC(tdesc_reg_p) *registers = NULL;
 
   /* The types associated with this feature.  */
-  VEC(tdesc_type_p) *types;
+  VEC(tdesc_type_p) *types = NULL;
 } *tdesc_feature_p;
 DEF_VEC_P(tdesc_feature_p);
 
@@ -1274,81 +1363,23 @@ tdesc_use_registers (struct gdbarch *gdbarch,
 }
 \f
 
-/* Methods for constructing a target description.  */
-
-static void
-tdesc_free_reg (struct tdesc_reg *reg)
-{
-  xfree (reg->name);
-  xfree (reg->type);
-  xfree (reg->group);
-  xfree (reg);
-}
-
 void
 tdesc_create_reg (struct tdesc_feature *feature, const char *name,
 		  int regnum, int save_restore, const char *group,
 		  int bitsize, const char *type)
 {
-  struct tdesc_reg *reg = XCNEW (struct tdesc_reg);
-
-  reg->name = xstrdup (name);
-  reg->target_regnum = regnum;
-  reg->save_restore = save_restore;
-  reg->group = group ? xstrdup (group) : NULL;
-  reg->bitsize = bitsize;
-  reg->type = type ? xstrdup (type) : xstrdup ("<unknown>");
-
-  /* If the register's type is target-defined, look it up now.  We may not
-     have easy access to the containing feature when we want it later.  */
-  reg->tdesc_type = tdesc_named_type (feature, reg->type);
+  tdesc_reg *reg = new tdesc_reg (feature, name, regnum, save_restore,
+				  group, bitsize, type);
 
   VEC_safe_push (tdesc_reg_p, feature->registers, reg);
 }
 
-/* Subroutine of tdesc_free_feature to simplify it.
-   Note: We do not want to free any referenced types here (e.g., types of
-   fields of a struct).  All types of a feature are recorded in
-   feature->types and are freed that way.  */
-
-static void
-tdesc_free_type (struct tdesc_type *type)
-{
-  switch (type->kind)
-    {
-    case TDESC_TYPE_STRUCT:
-    case TDESC_TYPE_UNION:
-    case TDESC_TYPE_FLAGS:
-    case TDESC_TYPE_ENUM:
-      {
-	struct tdesc_type_field *f;
-	int ix;
-
-	for (ix = 0;
-	     VEC_iterate (tdesc_type_field, type->u.u.fields, ix, f);
-	     ix++)
-	  xfree (f->name);
-
-	VEC_free (tdesc_type_field, type->u.u.fields);
-      }
-      break;
-
-    default:
-      break;
-    }
-
-  xfree ((char *) type->name);
-  xfree (type);
-}
-
 struct tdesc_type *
 tdesc_create_vector (struct tdesc_feature *feature, const char *name,
 		     struct tdesc_type *field_type, int count)
 {
-  struct tdesc_type *type = XCNEW (struct tdesc_type);
+  struct tdesc_type *type = new tdesc_type (name, TDESC_TYPE_VECTOR);
 
-  type->name = xstrdup (name);
-  type->kind = TDESC_TYPE_VECTOR;
   type->u.v.type = field_type;
   type->u.v.count = count;
 
@@ -1359,10 +1390,7 @@ tdesc_create_vector (struct tdesc_feature *feature, const char *name,
 struct tdesc_type *
 tdesc_create_struct (struct tdesc_feature *feature, const char *name)
 {
-  struct tdesc_type *type = XCNEW (struct tdesc_type);
-
-  type->name = xstrdup (name);
-  type->kind = TDESC_TYPE_STRUCT;
+  struct tdesc_type *type = new tdesc_type (name, TDESC_TYPE_STRUCT);
 
   VEC_safe_push (tdesc_type_p, feature->types, type);
   return type;
@@ -1383,10 +1411,7 @@ tdesc_set_struct_size (struct tdesc_type *type, int size)
 struct tdesc_type *
 tdesc_create_union (struct tdesc_feature *feature, const char *name)
 {
-  struct tdesc_type *type = XCNEW (struct tdesc_type);
-
-  type->name = xstrdup (name);
-  type->kind = TDESC_TYPE_UNION;
+  struct tdesc_type *type = new tdesc_type (name, TDESC_TYPE_UNION);
 
   VEC_safe_push (tdesc_type_p, feature->types, type);
   return type;
@@ -1396,12 +1421,10 @@ struct tdesc_type *
 tdesc_create_flags (struct tdesc_feature *feature, const char *name,
 		    int size)
 {
-  struct tdesc_type *type = XCNEW (struct tdesc_type);
+  struct tdesc_type *type = new tdesc_type (name, TDESC_TYPE_FLAGS);
 
   gdb_assert (size > 0);
 
-  type->name = xstrdup (name);
-  type->kind = TDESC_TYPE_FLAGS;
   type->u.u.size = size;
 
   VEC_safe_push (tdesc_type_p, feature->types, type);
@@ -1412,12 +1435,10 @@ struct tdesc_type *
 tdesc_create_enum (struct tdesc_feature *feature, const char *name,
 		   int size)
 {
-  struct tdesc_type *type = XCNEW (struct tdesc_type);
+  struct tdesc_type *type = new tdesc_type (name, TDESC_TYPE_ENUM);
 
   gdb_assert (size > 0);
 
-  type->name = xstrdup (name);
-  type->kind = TDESC_TYPE_ENUM;
   type->u.u.size = size;
 
   VEC_safe_push (tdesc_type_p, feature->types, type);
@@ -1521,31 +1542,10 @@ tdesc_add_enum_value (struct tdesc_type *type, int value,
   VEC_safe_push (tdesc_type_field, type->u.u.fields, &f);
 }
 
-static void
-tdesc_free_feature (struct tdesc_feature *feature)
-{
-  struct tdesc_reg *reg;
-  struct tdesc_type *type;
-  int ix;
-
-  for (ix = 0; VEC_iterate (tdesc_reg_p, feature->registers, ix, reg); ix++)
-    tdesc_free_reg (reg);
-  VEC_free (tdesc_reg_p, feature->registers);
-
-  for (ix = 0; VEC_iterate (tdesc_type_p, feature->types, ix, type); ix++)
-    tdesc_free_type (type);
-  VEC_free (tdesc_type_p, feature->types);
-
-  xfree (feature->name);
-  xfree (feature);
-}
-
 struct tdesc_feature *
 tdesc_create_feature (struct target_desc *tdesc, const char *name)
 {
-  struct tdesc_feature *new_feature = XCNEW (struct tdesc_feature);
-
-  new_feature->name = xstrdup (name);
+  struct tdesc_feature *new_feature = new tdesc_feature (name);
 
   VEC_safe_push (tdesc_feature_p, tdesc->features, new_feature);
   return new_feature;
@@ -1568,7 +1568,7 @@ free_target_description (void *arg)
   for (ix = 0;
        VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature);
        ix++)
-    tdesc_free_feature (feature);
+    delete feature;
   VEC_free (tdesc_feature_p, target_desc->features);
 
   for (ix = 0;
-- 
1.9.1

^ permalink raw reply	[flat|nested] 82+ messages in thread

* [PATCH 11/25] Use VEC for target_desc.reg_defs
  2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
                   ` (4 preceding siblings ...)
  2017-06-12  8:42 ` [PATCH 25/25] Remove features/i386/amd64-*linux.c and features/i386/x32-*linux.c Yao Qi
@ 2017-06-12  8:42 ` Yao Qi
  2017-06-28 19:01   ` Pedro Alves
  2017-06-12  8:42 ` [PATCH 08/25] Add "maint check xml-descriptions" to test builtin xml target descriptions Yao Qi
                   ` (20 subsequent siblings)
  26 siblings, 1 reply; 82+ messages in thread
From: Yao Qi @ 2017-06-12  8:42 UTC (permalink / raw)
  To: gdb-patches

Nowadays, target_desc.reg_defs is a pointer points to a pre-generated
array, which is not flexible.  This patch changes it from an array
to a VEC so that GDBserver can create target descriptions dynamically
later.  Instead of using pre-generated array, the -generated.c calls
VEC_safe_push to add each register to vector.

Since target_desc.reg_defs is used in IPA, we need to build common/vec.c
for IPA too.

gdb/gdbserver:

2017-05-23  Yao Qi  <yao.qi@linaro.org>

	* Makefile.in (IPA_OBJS): Add vec-ipa.o
	* regcache.c (get_thread_regcache): Use VEC_length.
	(init_register_cache): Likewise.
	(regcache_cpy): Likewise.
	(registers_to_string): Iterate reg_defs via VEC_iterate.
	(find_regno): Likewise.
	(find_register_by_number): Use VEC_index.
	(register_size): Call find_register_by_number.
	(register_data): Call find_register_by_number.
	(supply_regblock): Use VEC_length.
	(regcache_raw_read_unsigned): Likewise.
	* tdesc.c (init_target_desc): Iterate reg_defs via
	VEC_iterate.
	(default_description): Update initializer.
	(copy_target_description): Don't update field num_registers.
	* tdesc.h (struct target_desc) <reg_defs>: Change it to VEC.
	<num_registers>: Remove.

gdb:

2017-05-23  Yao Qi  <yao.qi@linaro.org>

	* regformats/regdat.sh: Update generated code.
---
 gdb/gdbserver/Makefile.in |  2 +-
 gdb/gdbserver/regcache.c  | 34 +++++++++++++++++++---------------
 gdb/gdbserver/tdesc.c     | 10 +++++-----
 gdb/gdbserver/tdesc.h     | 11 +++++------
 gdb/regformats/regdat.sh  | 13 +++++++------
 5 files changed, 37 insertions(+), 33 deletions(-)

diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
index 01dfdc0..1974db0 100644
--- a/gdb/gdbserver/Makefile.in
+++ b/gdb/gdbserver/Makefile.in
@@ -387,7 +387,7 @@ gdbreplay$(EXEEXT): $(GDBREPLAY_OBS) $(LIBGNU) $(LIBIBERTY)
 IPA_OBJS = ax-ipa.o tracepoint-ipa.o format-ipa.o utils-ipa.o \
 	regcache-ipa.o remote-utils-ipa.o common-utils-ipa.o \
 	tdesc-ipa.o print-utils-ipa.o rsp-low-ipa.o errors-ipa.o \
-	${IPA_DEPFILES}
+	vec-ipa.o ${IPA_DEPFILES}
 
 IPA_LIB = libinproctrace.so
 
diff --git a/gdb/gdbserver/regcache.c b/gdb/gdbserver/regcache.c
index 0f16f60..7dbdca7 100644
--- a/gdb/gdbserver/regcache.c
+++ b/gdb/gdbserver/regcache.c
@@ -54,7 +54,7 @@ get_thread_regcache (struct thread_info *thread, int fetch)
       current_thread = thread;
       /* Invalidate all registers, to prevent stale left-overs.  */
       memset (regcache->register_status, REG_UNAVAILABLE,
-	      regcache->tdesc->num_registers);
+	      VEC_length (tdesc_reg_p, regcache->tdesc->reg_defs));
       fetch_inferior_registers (regcache, -1);
       current_thread = saved_thread;
       regcache->registers_valid = 1;
@@ -145,9 +145,9 @@ init_register_cache (struct regcache *regcache,
 	= (unsigned char *) xcalloc (1, tdesc->registers_size);
       regcache->registers_owned = 1;
       regcache->register_status
-	= (unsigned char *) xmalloc (tdesc->num_registers);
+	= (unsigned char *) xmalloc (VEC_length (tdesc_reg_p, tdesc->reg_defs));
       memset ((void *) regcache->register_status, REG_UNAVAILABLE,
-	      tdesc->num_registers);
+	      VEC_length (tdesc_reg_p, tdesc->reg_defs));
 #else
       gdb_assert_not_reached ("can't allocate memory from the heap");
 #endif
@@ -204,7 +204,7 @@ regcache_cpy (struct regcache *dst, struct regcache *src)
 #ifndef IN_PROCESS_AGENT
   if (dst->register_status != NULL && src->register_status != NULL)
     memcpy (dst->register_status, src->register_status,
-	    src->tdesc->num_registers);
+	    VEC_length (tdesc_reg_p, src->tdesc->reg_defs));
 #endif
   dst->registers_valid = src->registers_valid;
 }
@@ -218,8 +218,9 @@ registers_to_string (struct regcache *regcache, char *buf)
   unsigned char *registers = regcache->registers;
   const struct target_desc *tdesc = regcache->tdesc;
   int i;
+  struct reg *reg;
 
-  for (i = 0; i < tdesc->num_registers; i++)
+  for (i = 0; VEC_iterate (tdesc_reg_p, tdesc->reg_defs, i, reg); i++)
     {
       if (regcache->register_status[i] == REG_VALID)
 	{
@@ -257,22 +258,23 @@ int
 find_regno (const struct target_desc *tdesc, const char *name)
 {
   int i;
+  struct reg *reg;
 
-  for (i = 0; i < tdesc->num_registers; i++)
-    if (strcmp (name, tdesc->reg_defs[i].name) == 0)
+  for (i = 0; VEC_iterate (tdesc_reg_p, tdesc->reg_defs, i, reg); i++)
+    if (strcmp (name, reg->name) == 0)
       return i;
   internal_error (__FILE__, __LINE__, "Unknown register %s requested",
 		  name);
 }
 
+#endif
+
 struct reg *
 find_register_by_number (const struct target_desc *tdesc, int n)
 {
-  return &tdesc->reg_defs[n];
+  return VEC_index (tdesc_reg_p, tdesc->reg_defs, n);
 }
 
-#endif
-
 #ifndef IN_PROCESS_AGENT
 static void
 free_register_cache_thread (struct thread_info *thread)
@@ -312,7 +314,7 @@ register_cache_size (const struct target_desc *tdesc)
 int
 register_size (const struct target_desc *tdesc, int n)
 {
-  return tdesc->reg_defs[n].size / 8;
+  return find_register_by_number (tdesc, n)->size / 8;
 }
 
 /* See common/common-regcache.h.  */
@@ -326,7 +328,8 @@ regcache_register_size (const struct regcache *regcache, int n)
 static unsigned char *
 register_data (struct regcache *regcache, int n, int fetch)
 {
-  return regcache->registers + regcache->tdesc->reg_defs[n].offset / 8;
+  return (regcache->registers
+	  + find_register_by_number (regcache->tdesc, n)->offset / 8);
 }
 
 /* Supply register N, whose contents are stored in BUF, to REGCACHE.
@@ -385,7 +388,7 @@ supply_regblock (struct regcache *regcache, const void *buf)
       {
 	int i;
 
-	for (i = 0; i < tdesc->num_registers; i++)
+	for (i = 0; i < VEC_length (tdesc_reg_p, tdesc->reg_defs); i++)
 	  regcache->register_status[i] = REG_VALID;
       }
 #endif
@@ -399,7 +402,7 @@ supply_regblock (struct regcache *regcache, const void *buf)
       {
 	int i;
 
-	for (i = 0; i < tdesc->num_registers; i++)
+	for (i = 0; i < VEC_length (tdesc_reg_p, tdesc->reg_defs); i++)
 	  regcache->register_status[i] = REG_UNAVAILABLE;
       }
 #endif
@@ -431,7 +434,8 @@ regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
   int size;
 
   gdb_assert (regcache != NULL);
-  gdb_assert (regnum >= 0 && regnum < regcache->tdesc->num_registers);
+  gdb_assert (regnum >= 0
+	      && regnum < VEC_length (tdesc_reg_p, regcache->tdesc->reg_defs));
 
   size = register_size (regcache->tdesc, regnum);
 
diff --git a/gdb/gdbserver/tdesc.c b/gdb/gdbserver/tdesc.c
index fdd35197..1b1882e 100644
--- a/gdb/gdbserver/tdesc.c
+++ b/gdb/gdbserver/tdesc.c
@@ -23,12 +23,13 @@ void
 init_target_desc (struct target_desc *tdesc)
 {
   int offset, i;
+  struct reg *reg;
 
   offset = 0;
-  for (i = 0; i < tdesc->num_registers; i++)
+  for (i = 0; VEC_iterate (tdesc_reg_p, tdesc->reg_defs, i, reg); i++)
     {
-      tdesc->reg_defs[i].offset = offset;
-      offset += tdesc->reg_defs[i].size;
+      reg->offset = offset;
+      offset += reg->size;
     }
 
   tdesc->registers_size = offset / 8;
@@ -40,14 +41,13 @@ init_target_desc (struct target_desc *tdesc)
 
 #ifndef IN_PROCESS_AGENT
 
-static const struct target_desc default_description = { 0 };
+static const struct target_desc default_description = { NULL, 0, NULL, NULL };
 
 void
 copy_target_description (struct target_desc *dest,
 			 const struct target_desc *src)
 {
   dest->reg_defs = src->reg_defs;
-  dest->num_registers = src->num_registers;
   dest->expedite_regs = src->expedite_regs;
   dest->registers_size = src->registers_size;
   dest->xmltarget = src->xmltarget;
diff --git a/gdb/gdbserver/tdesc.h b/gdb/gdbserver/tdesc.h
index 0341278..424a2fd 100644
--- a/gdb/gdbserver/tdesc.h
+++ b/gdb/gdbserver/tdesc.h
@@ -21,17 +21,16 @@
 
 struct reg;
 
+typedef struct reg *tdesc_reg_p;
+DEF_VEC_P(tdesc_reg_p);
+
 /* A target description.  */
 
 struct target_desc
 {
-  /* An array of NUM_REGISTERS elements of register definitions that
+  /* A vector of elements of register definitions that
      describe the inferior's register set.  */
-  struct reg *reg_defs;
-
-  /* The number of registers in inferior's register set (and thus in
-     the regcache).  */
-  int num_registers;
+  VEC(tdesc_reg_p) *reg_defs;
 
   /* The register cache size, in bytes.  */
   int registers_size;
diff --git a/gdb/regformats/regdat.sh b/gdb/regformats/regdat.sh
index 2c764cd..236cd93 100755
--- a/gdb/regformats/regdat.sh
+++ b/gdb/regformats/regdat.sh
@@ -131,8 +131,8 @@ do
     echo "{"
     echo "  static struct target_desc tdesc_${name}_s;"
     echo "  struct target_desc *result = &tdesc_${name}_s;"
+    echo "  memset (result, 0, sizeof (*result));"
 
-    echo "static struct reg regs_${name}[] = {"
     continue
   elif test "${type}" = "xmltarget"; then
     xmltarget="${entry}"
@@ -150,13 +150,17 @@ do
     echo "$0: $1 does not specify \`\`name''." 1>&2
     exit 1
   else
-    echo "  { \"${entry}\", ${offset}, ${type} },"
+    echo "  {struct reg *reg = XCNEW (struct reg);"
+    echo "  reg->name = \"${entry}\";"
+    echo "  reg->offset = ${offset};"
+    echo "  reg->size = ${type};"
+    echo "  VEC_safe_push (tdesc_reg_p, result->reg_defs, reg);"
+    echo "  };"
     offset=`expr ${offset} + ${type}`
     i=`expr $i + 1`
   fi
 done
 
-echo "};"
 echo
 echo "static const char *expedite_regs_${name}[] = { \"`echo ${expedite} | sed 's/,/", "/g'`\", 0 };"
 if test "${xmltarget}" = x; then
@@ -178,9 +182,6 @@ fi
 echo
 
 cat <<EOF
-  result->reg_defs = regs_${name};
-  result->num_registers = sizeof (regs_${name}) / sizeof (regs_${name}[0]);
-
 #ifndef IN_PROCESS_AGENT
   result->expedite_regs = expedite_regs_${name};
   result->xmltarget = xmltarget_${name};
-- 
1.9.1

^ permalink raw reply	[flat|nested] 82+ messages in thread

* [PATCH 18/25] [GDBserver] Use pre-generated tdesc as test
  2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
  2017-06-12  8:42 ` [PATCH 04/25] Centralize i386 linux target descriptions Yao Qi
  2017-06-12  8:42 ` [PATCH 06/25] Generate c for feature instead of tdesc Yao Qi
@ 2017-06-12  8:42 ` Yao Qi
  2017-06-12  8:42 ` [PATCH 12/25] [GDBserver] Centralize tdesc for i386-linux Yao Qi
                   ` (23 subsequent siblings)
  26 siblings, 0 replies; 82+ messages in thread
From: Yao Qi @ 2017-06-12  8:42 UTC (permalink / raw)
  To: gdb-patches

Now, these *-generate.c files are only used in GDBserver for unit test.
If $development is false (in release), these *-generate.c files won't be
used at all.

gdb/gdbserver:

2017-05-26  Yao Qi  <yao.qi@linaro.org>

	* configure.srv: Set srv_i386_linux_regobj empty if $development
	is false.
	* linux-x86-tdesc.c: TODO.
---
 gdb/gdbserver/configure.srv              |  11 +++-
 gdb/gdbserver/linux-i386-ipa.c           |   2 -
 gdb/gdbserver/linux-x86-low.c            |   2 +
 gdb/gdbserver/linux-x86-tdesc-selftest.c | 100 +++++++++++++++++++++++++++++++
 gdb/gdbserver/linux-x86-tdesc.c          |  89 ---------------------------
 5 files changed, 110 insertions(+), 94 deletions(-)
 create mode 100644 gdb/gdbserver/linux-x86-tdesc-selftest.c

diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv
index 3662f05..0e774ab 100644
--- a/gdb/gdbserver/configure.srv
+++ b/gdb/gdbserver/configure.srv
@@ -25,11 +25,16 @@
 srv_hostio_err_objs="hostio-errno.o"
 
 srv_i386_regobj="i386.o i386-avx.o i386-avx-avx512.o i386-avx-mpx-avx512-pku.o i386-mpx.o i386-avx-mpx.o i386-mmx.o"
-srv_i386_linux_regobj="i386-linux.o i386-avx-linux.o i386-avx-avx512-linux.o i386-avx-mpx-avx512-pku-linux.o i386-mpx-linux.o i386-avx-mpx-linux.o i386-mmx-linux.o"
+
+if $development; then
+   srv_i386_linux_regobj="i386-linux.o i386-avx-linux.o i386-avx-avx512-linux.o i386-avx-mpx-avx512-pku-linux.o i386-mpx-linux.o i386-avx-mpx-linux.o i386-mmx-linux.o linux-x86-tdesc-selftest.o"
+else
+   srv_i386_linux_regobj=""
+fi
+
 srv_amd64_regobj="amd64.o amd64-avx.o amd64-avx-avx512.o amd64-avx-mpx-avx512-pku.o amd64-mpx.o amd64-avx-mpx.o x32.o x32-avx.o x32-avx-avx512.o"
 srv_amd64_linux_regobj="amd64-linux.o amd64-avx-linux.o amd64-avx-avx512-linux.o amd64-avx-mpx-avx512-pku-linux.o amd64-mpx-linux.o amd64-avx-mpx-linux.o x32-linux.o x32-avx-linux.o x32-avx-avx512-linux.o"
 
-ipa_i386_linux_regobj="i386-linux-ipa.o i386-avx-linux-ipa.o  i386-avx-mpx-linux-ipa.o i386-avx-avx512-linux-ipa.o i386-avx-mpx-avx512-pku-linux-ipa.o i386-mpx-linux-ipa.o i386-mmx-linux-ipa.o"
 ipa_amd64_linux_regobj="amd64-linux-ipa.o amd64-avx-linux-ipa.o amd64-avx-mpx-linux-ipa.o amd64-avx-avx512-linux-ipa.o amd64-avx-mpx-avx512-pku-linux-ipa.o amd64-mpx-linux-ipa.o"
 ipa_ppc_linux_regobj="powerpc-32l-ipa.o powerpc-altivec32l-ipa.o powerpc-cell32l-ipa.o powerpc-vsx32l-ipa.o powerpc-isa205-32l-ipa.o powerpc-isa205-altivec32l-ipa.o powerpc-isa205-vsx32l-ipa.o powerpc-e500l-ipa.o powerpc-64l-ipa.o powerpc-altivec64l-ipa.o powerpc-cell64l-ipa.o powerpc-vsx64l-ipa.o powerpc-isa205-64l-ipa.o powerpc-isa205-altivec64l-ipa.o powerpc-isa205-vsx64l-ipa.o"
 
@@ -129,7 +134,7 @@ case "${target}" in
 			srv_linux_regsets=yes
 			srv_linux_thread_db=yes
 			srv_linux_btrace=yes
-			ipa_obj="${ipa_i386_linux_regobj} linux-i386-ipa.o linux-x86-tdesc-ipa.o"
+			ipa_obj="linux-i386-ipa.o linux-x86-tdesc-ipa.o"
 			;;
   i[34567]86-*-lynxos*)	srv_regobj="i386.o"
 			srv_tgtobj="lynx-low.o lynx-i386-low.o"
diff --git a/gdb/gdbserver/linux-i386-ipa.c b/gdb/gdbserver/linux-i386-ipa.c
index bca3fdb..1804d41 100644
--- a/gdb/gdbserver/linux-i386-ipa.c
+++ b/gdb/gdbserver/linux-i386-ipa.c
@@ -262,7 +262,5 @@ alloc_jump_pad_buffer (size_t size)
 void
 initialize_low_tracepoint (void)
 {
-  initialize_low_tdesc ();
-
   initialize_fast_tracepoint_trampoline_buffer ();
 }
diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c
index f5d4aa1..7744d3b 100644
--- a/gdb/gdbserver/linux-x86-low.c
+++ b/gdb/gdbserver/linux-x86-low.c
@@ -2985,7 +2985,9 @@ initialize_low_arch (void)
   tdesc_amd64_linux_no_xml->xmltarget = xmltarget_amd64_linux_no_xml;
 #endif
 
+#if GDB_SELF_TEST
   initialize_low_tdesc ();
+#endif
 
   tdesc_i386_linux_no_xml = XNEW (struct target_desc);
   copy_target_description (tdesc_i386_linux_no_xml,
diff --git a/gdb/gdbserver/linux-x86-tdesc-selftest.c b/gdb/gdbserver/linux-x86-tdesc-selftest.c
new file mode 100644
index 0000000..31f5240
--- /dev/null
+++ b/gdb/gdbserver/linux-x86-tdesc-selftest.c
@@ -0,0 +1,100 @@
+/* Copyright (C) 2017 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "server.h"
+#include "linux-x86-tdesc.h"
+#include "tdesc.h"
+#include "../selftest.h"
+
+/* Defined in auto-generated file i386-linux.c.  */
+void init_registers_i386_linux (void);
+extern const struct target_desc *tdesc_i386_linux;
+
+/* Defined in auto-generated file i386-mmx-linux.c.  */
+void init_registers_i386_mmx_linux (void);
+extern const struct target_desc *tdesc_i386_mmx_linux;
+
+/* Defined in auto-generated file i386-avx-linux.c.  */
+void init_registers_i386_avx_linux (void);
+extern const struct target_desc *tdesc_i386_avx_linux;
+
+/* Defined in auto-generated file i386-avx-mpx-linux.c.  */
+void init_registers_i386_avx_mpx_linux (void);
+extern const struct target_desc *tdesc_i386_avx_mpx_linux;
+
+/* Defined in auto-generated file i386-avx-avx512-linux.c.  */
+void init_registers_i386_avx_avx512_linux (void);
+extern const struct target_desc *tdesc_i386_avx_avx512_linux;
+
+/* Defined in auto-generated file i386-avx-mpx-avx512-linux.c.  */
+void init_registers_i386_avx_mpx_avx512_pku_linux (void);
+extern const struct target_desc *tdesc_i386_avx_mpx_avx512_pku_linux;
+
+/* Defined in auto-generated file i386-mpx-linux.c.  */
+void init_registers_i386_mpx_linux (void);
+extern const struct target_desc *tdesc_i386_mpx_linux;
+
+namespace selftests {
+namespace gdbserver {
+static void
+i386_tdesc_test ()
+{
+  const struct target_desc *tdesc = i386_get_ipa_tdesc (X86_TDESC_MMX);
+
+  SELF_CHECK (*tdesc == *tdesc_i386_mmx_linux);
+  delete tdesc;
+
+  tdesc = i386_get_ipa_tdesc (X86_TDESC_SSE);
+  SELF_CHECK (*tdesc == *tdesc_i386_linux);
+  delete tdesc;
+
+  tdesc = i386_get_ipa_tdesc (X86_TDESC_AVX);
+  SELF_CHECK (*tdesc == *tdesc_i386_avx_linux);
+  delete tdesc;
+
+  tdesc = i386_get_ipa_tdesc (X86_TDESC_MPX);
+  SELF_CHECK (*tdesc == *tdesc_i386_mpx_linux);
+  delete tdesc;
+
+  tdesc = i386_get_ipa_tdesc (X86_TDESC_AVX_MPX);
+  SELF_CHECK (*tdesc == *tdesc_i386_avx_mpx_linux);
+  delete tdesc;
+
+  tdesc = i386_get_ipa_tdesc (X86_TDESC_AVX_AVX512);
+  SELF_CHECK (*tdesc == *tdesc_i386_avx_avx512_linux);
+  delete tdesc;
+
+  tdesc = i386_get_ipa_tdesc (X86_TDESC_AVX_MPX_AVX512_PKU);
+  SELF_CHECK (*tdesc == *tdesc_i386_avx_mpx_avx512_pku_linux);
+  delete tdesc;
+}
+}
+} // namespace selftests
+
+void
+initialize_low_tdesc ()
+{
+  init_registers_i386_linux ();
+  init_registers_i386_mmx_linux ();
+  init_registers_i386_avx_linux ();
+  init_registers_i386_mpx_linux ();
+  init_registers_i386_avx_mpx_linux ();
+  init_registers_i386_avx_avx512_linux ();
+  init_registers_i386_avx_mpx_avx512_pku_linux ();
+
+  register_self_test (selftests::gdbserver::i386_tdesc_test);
+}
diff --git a/gdb/gdbserver/linux-x86-tdesc.c b/gdb/gdbserver/linux-x86-tdesc.c
index 0dc5275..2e4079a 100644
--- a/gdb/gdbserver/linux-x86-tdesc.c
+++ b/gdb/gdbserver/linux-x86-tdesc.c
@@ -29,97 +29,8 @@
 #include "../features/i386/32bit-mpx.c"
 #include "../features/i386/32bit-pkeys.c"
 
-#if defined __i386__ || !defined IN_PROCESS_AGENT
-/* Defined in auto-generated file i386-linux.c.  */
-void init_registers_i386_linux (void);
-extern const struct target_desc *tdesc_i386_linux;
-
-/* Defined in auto-generated file i386-mmx-linux.c.  */
-void init_registers_i386_mmx_linux (void);
-extern const struct target_desc *tdesc_i386_mmx_linux;
-
-/* Defined in auto-generated file i386-avx-linux.c.  */
-void init_registers_i386_avx_linux (void);
-extern const struct target_desc *tdesc_i386_avx_linux;
-
-/* Defined in auto-generated file i386-avx-mpx-linux.c.  */
-void init_registers_i386_avx_mpx_linux (void);
-extern const struct target_desc *tdesc_i386_avx_mpx_linux;
-
-/* Defined in auto-generated file i386-avx-avx512-linux.c.  */
-void init_registers_i386_avx_avx512_linux (void);
-extern const struct target_desc *tdesc_i386_avx_avx512_linux;
-
-/* Defined in auto-generated file i386-avx-mpx-avx512-linux.c.  */
-void init_registers_i386_avx_mpx_avx512_pku_linux (void);
-extern const struct target_desc *tdesc_i386_avx_mpx_avx512_pku_linux;
-
-/* Defined in auto-generated file i386-mpx-linux.c.  */
-void init_registers_i386_mpx_linux (void);
-extern const struct target_desc *tdesc_i386_mpx_linux;
-#endif
-
 static const struct target_desc *i386_tdescs[X86_TDESC_LAST] = { };
 
-#if defined GDB_SELF_TEST && !defined IN_PROCESS_AGENT
-#include "selftest.h"
-
-namespace selftests {
-namespace gdbserver {
-static void
-i386_tdesc_test ()
-{
-  const struct target_desc *tdesc = i386_get_ipa_tdesc (X86_TDESC_MMX);
-
-  SELF_CHECK (*tdesc == *tdesc_i386_mmx_linux);
-  delete tdesc;
-
-  tdesc = i386_get_ipa_tdesc (X86_TDESC_SSE);
-  SELF_CHECK (*tdesc == *tdesc_i386_linux);
-  delete tdesc;
-
-  tdesc = i386_get_ipa_tdesc (X86_TDESC_AVX);
-  SELF_CHECK (*tdesc == *tdesc_i386_avx_linux);
-  delete tdesc;
-
-  tdesc = i386_get_ipa_tdesc (X86_TDESC_MPX);
-  SELF_CHECK (*tdesc == *tdesc_i386_mpx_linux);
-  delete tdesc;
-
-  tdesc = i386_get_ipa_tdesc (X86_TDESC_AVX_MPX);
-  SELF_CHECK (*tdesc == *tdesc_i386_avx_mpx_linux);
-  delete tdesc;
-
-  tdesc = i386_get_ipa_tdesc (X86_TDESC_AVX_AVX512);
-  SELF_CHECK (*tdesc == *tdesc_i386_avx_avx512_linux);
-  delete tdesc;
-
-  tdesc = i386_get_ipa_tdesc (X86_TDESC_AVX_MPX_AVX512_PKU);
-  SELF_CHECK (*tdesc == *tdesc_i386_avx_mpx_avx512_pku_linux);
-  delete tdesc;
-}
-}
-} // namespace selftests
-#endif /* GDB_SELF_TEST */
-
-void
-initialize_low_tdesc ()
-{
-#if defined __i386__ || !defined IN_PROCESS_AGENT
-  init_registers_i386_linux ();
-  init_registers_i386_mmx_linux ();
-  init_registers_i386_avx_linux ();
-  init_registers_i386_mpx_linux ();
-  init_registers_i386_avx_mpx_linux ();
-  init_registers_i386_avx_avx512_linux ();
-  init_registers_i386_avx_mpx_avx512_pku_linux ();
-
-#if GDB_SELF_TEST
-  register_self_test (selftests::gdbserver::i386_tdesc_test);
-#endif
-#endif
-}
-
 const struct target_desc *
 i386_get_ipa_tdesc (int idx)
 {
-- 
1.9.1

^ permalink raw reply	[flat|nested] 82+ messages in thread

* [PATCH 14/25] [RFC] GDBserver self test
  2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
                   ` (12 preceding siblings ...)
  2017-06-12  8:42 ` [PATCH 02/25] Adjust the order of 32bit-linux.xml and 32bit-sse.xml in i386/i386-linux.xml Yao Qi
@ 2017-06-12  8:42 ` Yao Qi
  2017-06-28 17:09   ` Pedro Alves
  2017-06-12  8:42 ` [PATCH 01/25] Move initialize_tdesc_mips* calls from mips-linux-nat.c to mips-linux-tdep.c Yao Qi
                   ` (12 subsequent siblings)
  26 siblings, 1 reply; 82+ messages in thread
From: Yao Qi @ 2017-06-12  8:42 UTC (permalink / raw)
  To: gdb-patches

This patch uses GDB self test in GDBserver.  The self tests are run if
GDBserver is started with option --self-test.

gdb/gdbserver:

2017-05-26  Yao Qi  <yao.qi@linaro.org>

	* configure.ac: AC_DEFINE GDB_SELF_TEST if $development.
	* configure, config.in: Re-generated.
	* server.c: Include sefltest.h and selftest.c.
	(captured_main): Handle option --self-test.
gdb:

2017-05-26  Yao Qi  <yao.qi@linaro.org>

	* selftest.c: Adjust it for GDBserver.

gdb/testsuite:

2017-05-26  Yao Qi  <yao.qi@linaro.org>

	* gdb.server/unittest.exp: New.
---
 gdb/gdbserver/config.in               |  3 +++
 gdb/gdbserver/configure               | 12 +++++++---
 gdb/gdbserver/configure.ac            |  5 +++++
 gdb/gdbserver/server.c                | 18 ++++++++++++++-
 gdb/selftest.c                        | 18 ++++++++++++++-
 gdb/testsuite/gdb.server/unittest.exp | 41 +++++++++++++++++++++++++++++++++++
 6 files changed, 92 insertions(+), 5 deletions(-)
 create mode 100644 gdb/testsuite/gdb.server/unittest.exp

diff --git a/gdb/gdbserver/config.in b/gdb/gdbserver/config.in
index 34a7443..5dacbac 100644
--- a/gdb/gdbserver/config.in
+++ b/gdb/gdbserver/config.in
@@ -8,6 +8,9 @@
 /* Define to 1 if using `alloca.c'. */
 #undef C_ALLOCA
 
+/* Define if self-testing features should be enabled */
+#undef GDB_SELF_TEST
+
 /* Define to 1 if you have `alloca', as a function or macro. */
 #undef HAVE_ALLOCA
 
diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure
index b314c41..8d439ec 100755
--- a/gdb/gdbserver/configure
+++ b/gdb/gdbserver/configure
@@ -5813,6 +5813,12 @@ fi
   fi
 
 
+if $development; then
+
+$as_echo "#define GDB_SELF_TEST 1" >>confdefs.h
+
+fi
+
  case ${build_alias} in
   "") build_noncanonical=${build} ;;
   *) build_noncanonical=${build_alias} ;;
@@ -7498,9 +7504,9 @@ _ACEOF
 fi
 
 
-# See if <sys/user.h> supports the %fs_base and %gs_base amd64 segment
-# registers.  Older amd64 Linux's don't have the fs_base and gs_base
-# members of `struct user_regs_struct'.
+# See if <sys/user.h> supports the %fs_base and %gs_bas amd64 segment registers.
+# Older amd64 Linux's don't have the fs_base and gs_base members of
+# `struct user_regs_struct'.
 ac_fn_c_check_member "$LINENO" "struct user_regs_struct" "fs_base" "ac_cv_member_struct_user_regs_struct_fs_base" "#include <sys/user.h>
 "
 if test "x$ac_cv_member_struct_user_regs_struct_fs_base" = x""yes; then :
diff --git a/gdb/gdbserver/configure.ac b/gdb/gdbserver/configure.ac
index 4ea7913..36e21c5 100644
--- a/gdb/gdbserver/configure.ac
+++ b/gdb/gdbserver/configure.ac
@@ -56,6 +56,11 @@ else
 fi
 GDB_AC_LIBMCHECK(${libmcheck_default})
 
+if $development; then
+  AC_DEFINE(GDB_SELF_TEST, 1,
+            [Define if self-testing features should be enabled])
+fi
+
 ACX_NONCANONICAL_TARGET
 ACX_NONCANONICAL_HOST
 
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index 69fcab1..428a9db 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -3487,6 +3487,9 @@ detach_or_kill_for_exit_cleanup (void *ignore)
   END_CATCH
 }
 
+#include "../selftest.h"
+#include "../selftest.c"
+
 /* Main function.  This is called by the real "main" function,
    wrapped in a TRY_CATCH that handles any uncaught exceptions.  */
 
@@ -3501,6 +3504,7 @@ captured_main (int argc, char *argv[])
   volatile int multi_mode = 0;
   volatile int attach = 0;
   int was_running;
+  bool selftest = false;
 
   while (*next_arg != NULL && **next_arg == '-')
     {
@@ -3608,6 +3612,11 @@ captured_main (int argc, char *argv[])
 	disable_randomization = 0;
       else if (strcmp (*next_arg, "--once") == 0)
 	run_once = 1;
+      else if (strcmp (*next_arg, "--self-test") == 0)
+	{
+	  selftest = true;
+	  break;
+	}
       else
 	{
 	  fprintf (stderr, "Unknown argument: %s\n", *next_arg);
@@ -3623,7 +3632,8 @@ captured_main (int argc, char *argv[])
       port = *next_arg;
       next_arg++;
     }
-  if (port == NULL || (!attach && !multi_mode && *next_arg == NULL))
+  if ((port == NULL || (!attach && !multi_mode && *next_arg == NULL))
+       && !selftest)
     {
       gdbserver_usage (stderr);
       exit (1);
@@ -3676,6 +3686,12 @@ captured_main (int argc, char *argv[])
   own_buf = (char *) xmalloc (PBUFSIZ + 1);
   mem_buf = (unsigned char *) xmalloc (PBUFSIZ);
 
+  if (selftest)
+    {
+      run_self_tests ();
+      throw_quit ("Quit");
+    }
+
   if (pid == 0 && *next_arg != NULL)
     {
       int i, n;
diff --git a/gdb/selftest.c b/gdb/selftest.c
index 14b76f6..c947749 100644
--- a/gdb/selftest.c
+++ b/gdb/selftest.c
@@ -15,8 +15,15 @@
 
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
-
+#include "config.h"
+#ifdef GDBSERVER
+#define QUIT do {} while (0)
+#else
 #include "defs.h"
+#endif
+#include "common-defs.h"
+#include "common-exceptions.h"
+#include "common-debug.h"
 #include "selftest.h"
 #include <vector>
 
@@ -50,15 +57,24 @@ run_self_tests (void)
       CATCH (ex, RETURN_MASK_ERROR)
 	{
 	  ++failed;
+	  #ifndef GDBSERVER
 	  exception_fprintf (gdb_stderr, ex, _("Self test failed: "));
+	  #endif
 	}
       END_CATCH
 
+#ifndef GDBSERVER
       /* Clear GDB internal state.  */
       registers_changed ();
       reinit_frame_cache ();
+#endif
     }
 
+  #ifdef GDBSERVER
+  debug_printf ("Ran %lu unit tests, %d failed\n",
+		(long) tests.size (), failed);
+  #else
   printf_filtered (_("Ran %lu unit tests, %d failed\n"),
 		   (long) tests.size (), failed);
+  #endif
 }
diff --git a/gdb/testsuite/gdb.server/unittest.exp b/gdb/testsuite/gdb.server/unittest.exp
new file mode 100644
index 0000000..6dc4b6e
--- /dev/null
+++ b/gdb/testsuite/gdb.server/unittest.exp
@@ -0,0 +1,41 @@
+# This testcase is part of GDB, the GNU debugger.
+
+# Copyright 2017 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+load_lib gdbserver-support.exp
+
+standard_testfile
+
+if { [skip_gdbserver_tests] } {
+    return 0
+}
+
+global server_spawn_id
+
+set gdbserver [find_gdbserver]
+set gdbserver_command "$gdbserver --self-test"
+
+set server_spawn_id [remote_spawn target $gdbserver_command]
+
+gdb_expect {
+    -i $server_spawn_id
+    -re "Ran $decimal unit tests, 0 failed" {
+	pass "unit tests"
+    }
+    -re "Ran $decimal unit tests, $decimal failed" {
+	fail "unit tests"
+    }
+}
-- 
1.9.1

^ permalink raw reply	[flat|nested] 82+ messages in thread

* [PATCH 19/25] GDBserver: remove srv_i386_linux_xmlfiles
  2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
                   ` (15 preceding siblings ...)
  2017-06-12  8:42 ` [PATCH 03/25] Class-fy tdesc_reg tdesc_type and tdesc_feature Yao Qi
@ 2017-06-12  8:42 ` Yao Qi
  2017-06-12  8:42 ` [PATCH 10/25] Adjust code generated by regformats/regdat.sh Yao Qi
                   ` (9 subsequent siblings)
  26 siblings, 0 replies; 82+ messages in thread
From: Yao Qi @ 2017-06-12  8:42 UTC (permalink / raw)
  To: gdb-patches

Now, GDBserver is able to create XML contents for target descriptions,
so that the list of XML files about i386-linux are not needed.

gdb/gdbserver:

2017-05-26  Yao Qi  <yao.qi@linaro.org>

	* configure.srv: Remove srv_i386_linux_xmlfiles.
---
 gdb/gdbserver/configure.srv | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv
index 0e774ab..5c3ba1f 100644
--- a/gdb/gdbserver/configure.srv
+++ b/gdb/gdbserver/configure.srv
@@ -42,7 +42,6 @@ srv_i386_32bit_xmlfiles="i386/32bit-core.xml i386/32bit-sse.xml i386/32bit-avx.x
 srv_i386_64bit_xmlfiles="i386/64bit-core.xml i386/64bit-segments.xml i386/64bit-sse.xml i386/64bit-avx.xml i386/64bit-avx512.xml i386/x32-core.xml i386/64bit-mpx.xml i386/64bit-pkeys.xml"
 srv_i386_xmlfiles="i386/i386.xml i386/i386-avx.xml i386/i386-avx-avx512.xml i386/i386-avx-mpx-avx512-pku.xml i386/i386-mpx.xml i386/i386-avx-mpx.xml i386/i386-mmx.xml $srv_i386_32bit_xmlfiles"
 srv_amd64_xmlfiles="i386/amd64.xml i386/amd64-avx.xml i386/amd64-avx-avx512.xml i386/amd64-avx-mpx-avx512-pku.xml i386/x32.xml i386/x32-avx.xml i386/x32-avx-avx512.xml i386/amd64-mpx.xml i386/amd64-avx-mpx.xml  $srv_i386_64bit_xmlfiles"
-srv_i386_linux_xmlfiles="i386/i386-linux.xml i386/i386-avx-linux.xml i386/i386-avx-avx512-linux.xml i386/i386-avx-mpx-avx512-pku-linux.xml i386/i386-mmx-linux.xml i386/32bit-linux.xml i386/i386-mpx-linux.xml i386/i386-avx-mpx-linux.xml $srv_i386_32bit_xmlfiles"
 srv_amd64_linux_xmlfiles="i386/amd64-linux.xml i386/amd64-avx-linux.xml i386/amd64-avx-avx512.xml i386/amd64-avx-mpx-avx512-pku-linux.xml i386/64bit-linux.xml i386/amd64-mpx-linux.xml i386/amd64-avx-mpx-linux.xml i386/x32-linux.xml i386/x32-avx-linux.xml i386/x32-avx-avx512-linux.xml $srv_i386_64bit_xmlfiles"
 
 
@@ -120,7 +119,7 @@ case "${target}" in
 			srv_xmlfiles="$srv_i386_xmlfiles"
 			;;
   i[34567]86-*-linux*)	srv_regobj="$srv_i386_linux_regobj"
-			srv_xmlfiles="$srv_i386_linux_xmlfiles"
+			srv_xmlfiles="$srv_i386_32bit_xmlfiles"
 			if test "$gdb_cv_i386_is_x86_64" = yes ; then
 			    srv_regobj="$srv_regobj $srv_amd64_linux_regobj"
 			    srv_xmlfiles="${srv_xmlfiles} $srv_amd64_linux_xmlfiles"
@@ -366,7 +365,7 @@ case "${target}" in
 			srv_tgtobj="${srv_tgtobj} linux-btrace.o x86-linux.o"
 			srv_tgtobj="${srv_tgtobj} x86-linux-dregs.o"
 			srv_tgtobj="${srv_tgtobj} amd64-linux-siginfo.o"
-			srv_xmlfiles="$srv_i386_linux_xmlfiles $srv_amd64_linux_xmlfiles"
+			srv_xmlfiles="$srv_i386_32bit_xmlfiles $srv_amd64_linux_xmlfiles"
 			srv_linux_usrregs=yes # This is for i386 progs.
 			srv_linux_regsets=yes
 			srv_linux_thread_db=yes
-- 
1.9.1

^ permalink raw reply	[flat|nested] 82+ messages in thread

* [PATCH 07/25] Lazily and dynamically create i386-linux target descriptions
  2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
                   ` (17 preceding siblings ...)
  2017-06-12  8:42 ` [PATCH 10/25] Adjust code generated by regformats/regdat.sh Yao Qi
@ 2017-06-12  8:42 ` Yao Qi
  2017-06-20 11:01   ` Pedro Alves
  2017-06-12  8:42 ` [PATCH 09/25] Use target_desc fields expedite_regs and xmltarget ifndef IN_PROCESS_AGENT Yao Qi
                   ` (7 subsequent siblings)
  26 siblings, 1 reply; 82+ messages in thread
From: Yao Qi @ 2017-06-12  8:42 UTC (permalink / raw)
  To: gdb-patches

Instead of using pre-generated target descriptions, this patch
changes GDB to lazily and dynamically create target descriptions
according to the target hardware capability (xcr0 in i386).
This support any combination of target features.

This patch also adds a unit test to make sure dynamically generated
tdesc are identical to these generated from xml files.

gdb:

2017-04-27  Yao Qi  <yao.qi@linaro.org>

	* i386-linux-tdep.c (i386_linux_read_description): Generate
	target description if it doesn't exist.
        [GDB_SELF_TEST] (i386_linux_read_description_test): New unit test.
        (_initialize_i386_linux_tdep) [GDB_SELF_TEST]: Register unit test.
---
 gdb/features/i386/32bit-linux.c |  1 +
 gdb/features/i386/32bit-sse.c   |  1 +
 gdb/i386-linux-tdep.c           | 83 ++++++++++++++++++++++++-----------------
 gdb/target-descriptions.c       | 11 ++++++
 4 files changed, 62 insertions(+), 34 deletions(-)

diff --git a/gdb/features/i386/32bit-linux.c b/gdb/features/i386/32bit-linux.c
index 3f7bfe7..ff90d40 100644
--- a/gdb/features/i386/32bit-linux.c
+++ b/gdb/features/i386/32bit-linux.c
@@ -11,6 +11,7 @@ create_feature_i386_32bit_linux (struct target_desc *result, long regnum)
   struct tdesc_feature *feature;
 
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
+  regnum = 41;
   tdesc_create_reg (feature, "orig_eax", regnum++, 1, NULL, 32, "int");
   return regnum;
 }
diff --git a/gdb/features/i386/32bit-sse.c b/gdb/features/i386/32bit-sse.c
index 9aa7d3e..08c3948 100644
--- a/gdb/features/i386/32bit-sse.c
+++ b/gdb/features/i386/32bit-sse.c
@@ -63,6 +63,7 @@ create_feature_i386_32bit_sse (struct target_desc *result, long regnum)
   tdesc_add_flag (type, 12, "PM");
   tdesc_add_flag (type, 15, "FZ");
 
+  regnum = 32;
   tdesc_create_reg (feature, "xmm0", regnum++, 1, NULL, 128, "vec128");
   tdesc_create_reg (feature, "xmm1", regnum++, 1, NULL, 128, "vec128");
   tdesc_create_reg (feature, "xmm2", regnum++, 1, NULL, 128, "vec128");
diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c
index 1bc1a6f..5ca58a1 100644
--- a/gdb/i386-linux-tdep.c
+++ b/gdb/i386-linux-tdep.c
@@ -45,13 +45,14 @@
 
 #include "record-full.h"
 #include "linux-record.h"
-#include "features/i386/i386-linux.c"
-#include "features/i386/i386-mmx-linux.c"
-#include "features/i386/i386-mpx-linux.c"
-#include "features/i386/i386-avx-mpx-linux.c"
-#include "features/i386/i386-avx-linux.c"
-#include "features/i386/i386-avx-avx512-linux.c"
-#include "features/i386/i386-avx-mpx-avx512-pku-linux.c"
+
+#include "features/i386/32bit-core.c"
+#include "features/i386/32bit-sse.c"
+#include "features/i386/32bit-linux.c"
+#include "features/i386/32bit-avx.c"
+#include "features/i386/32bit-mpx.c"
+#include "features/i386/32bit-avx512.c"
+#include "features/i386/32bit-pkeys.c"
 
 /* Return non-zero, when the register is in the corresponding register
    group.  Put the LINUX_ORIG_EAX register in the system group.  */
@@ -681,27 +682,50 @@ i386_linux_core_read_xcr0 (bfd *abfd)
 const struct target_desc *
 i386_linux_read_description (uint64_t xcr0)
 {
-  switch ((xcr0 & X86_XSTATE_ALL_MASK))
+  if (xcr0 == 0)
+    return NULL;
+
+  static struct target_desc *i386_linux_tdescs \
+    [2/*X87*/][2/*SSE*/][2/*AVX*/][2/*MPX*/][2/*AVX512*/][2/*PKRU*/] = {};
+  struct target_desc **tdesc;
+
+  tdesc = &i386_linux_tdescs[(xcr0 & X86_XSTATE_X87) ? 1 : 0]
+    [(xcr0 & X86_XSTATE_SSE) ? 1 : 0]
+    [(xcr0 & X86_XSTATE_AVX) ? 1 : 0]
+    [(xcr0 & X86_XSTATE_MPX) ? 1 : 0]
+    [(xcr0 & X86_XSTATE_AVX512) ? 1 : 0]
+    [(xcr0 & X86_XSTATE_PKRU) ? 1 : 0];
+
+  if (*tdesc == NULL)
     {
-    case X86_XSTATE_AVX_MPX_AVX512_PKU_MASK:
-      return tdesc_i386_avx_mpx_avx512_pku_linux;
-    case X86_XSTATE_AVX_AVX512_MASK:
-      return tdesc_i386_avx_avx512_linux;
-    case X86_XSTATE_MPX_MASK:
-      return tdesc_i386_mpx_linux;
-    case X86_XSTATE_AVX_MPX_MASK:
-      return tdesc_i386_avx_mpx_linux;
-    case X86_XSTATE_AVX_MASK:
-      return tdesc_i386_avx_linux;
-    case X86_XSTATE_SSE_MASK:
-      return tdesc_i386_linux;
-    case X86_XSTATE_X87_MASK:
-      return tdesc_i386_mmx_linux;
-    default:
-      break;
+      *tdesc = allocate_target_description ();
+      set_tdesc_architecture (*tdesc, bfd_scan_arch ("i386"));
+      set_tdesc_osabi (*tdesc, osabi_from_tdesc_string ("GNU/Linux"));
+
+      long regnum = 0;
+
+      if (xcr0 & X86_XSTATE_X87)
+	regnum = create_feature_i386_32bit_core (*tdesc, regnum);
+
+      if (xcr0 & X86_XSTATE_SSE)
+	regnum = create_feature_i386_32bit_sse (*tdesc, regnum);
+
+      regnum = create_feature_i386_32bit_linux (*tdesc, regnum);
+
+      if (xcr0 & X86_XSTATE_AVX)
+	regnum = create_feature_i386_32bit_avx (*tdesc, regnum);
+
+      if (xcr0 & X86_XSTATE_MPX)
+	regnum = create_feature_i386_32bit_mpx (*tdesc, regnum);
+
+      if (xcr0 & X86_XSTATE_AVX512)
+	regnum = create_feature_i386_32bit_avx512 (*tdesc, regnum);
+
+      if (xcr0 & X86_XSTATE_PKRU)
+	regnum = create_feature_i386_32bit_pkeys (*tdesc, regnum);
     }
 
-  return NULL;
+  return *tdesc;
 }
 
 /* Get Linux/x86 target description from core dump.  */
@@ -1092,13 +1116,4 @@ _initialize_i386_linux_tdep (void)
 {
   gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_LINUX,
 			  i386_linux_init_abi);
-
-  /* Initialize the Linux target description.  */
-  initialize_tdesc_i386_linux ();
-  initialize_tdesc_i386_mmx_linux ();
-  initialize_tdesc_i386_avx_linux ();
-  initialize_tdesc_i386_mpx_linux ();
-  initialize_tdesc_i386_avx_mpx_linux ();
-  initialize_tdesc_i386_avx_avx512_linux ();
-  initialize_tdesc_i386_avx_mpx_avx512_pku_linux ();
 }
diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
index fceab5f..c0b716a 100644
--- a/gdb/target-descriptions.c
+++ b/gdb/target-descriptions.c
@@ -2100,6 +2100,12 @@ public:
 
   void visit (const tdesc_reg *reg) override
   {
+    if (reg->target_regnum > next_regnum)
+      {
+	printf_unfiltered ("  regnum = %ld;\n", reg->target_regnum);
+	next_regnum = reg->target_regnum;
+      }
+
     printf_unfiltered ("  tdesc_create_reg (feature, \"%s\", regnum++, %d, ",
 		       reg->name, reg->save_restore);
     if (reg->group)
@@ -2107,8 +2113,13 @@ public:
     else
       printf_unfiltered ("NULL, ");
     printf_unfiltered ("%d, \"%s\");\n", reg->bitsize, reg->type);
+
+    next_regnum++;
   }
 
+private:
+  /* The register number to use for the next register we see.  */
+  int next_regnum = 0;
 };
 
 static void
-- 
1.9.1

^ permalink raw reply	[flat|nested] 82+ messages in thread

* [PATCH 10/25] Adjust code generated by regformats/regdat.sh
  2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
                   ` (16 preceding siblings ...)
  2017-06-12  8:42 ` [PATCH 19/25] GDBserver: remove srv_i386_linux_xmlfiles Yao Qi
@ 2017-06-12  8:42 ` Yao Qi
  2017-06-20 11:09   ` Pedro Alves
  2017-06-12  8:42 ` [PATCH 07/25] Lazily and dynamically create i386-linux target descriptions Yao Qi
                   ` (8 subsequent siblings)
  26 siblings, 1 reply; 82+ messages in thread
From: Yao Qi @ 2017-06-12  8:42 UTC (permalink / raw)
  To: gdb-patches

regformats/regdat.sh generate some *-generated.c files when GDBserver
is built.  Each .c file has some static variables, which are only used
within function init_registers_XXX, like this,

static struct reg regs_i386_linux[] = {
  { "eax", 0, 32 },
  { "ecx", 32, 32 },
  ...
};

static const char *expedite_regs_i386_linux[] = { "ebp", "esp", "eip", 0 };
static const char *xmltarget_i386_linux = "i386-linux.xml";

void
init_registers_i386_linux (void)
{
  ...
}

This patch moves these static variables' definitions to function
init_registers_XXX, so the generated files look like this,

void
init_registers_i386_linux (void)
{
  static struct target_desc tdesc_i386_linux_s;
  struct target_desc *result = &tdesc_i386_linux_s;
static struct reg regs_i386_linux[] = {
  ...
};

static const char *expedite_regs_i386_linux[] = { "ebp", "esp", "eip", 0 };
static const char *xmltarget_i386_linux = "i386-linux.xml";

  ...
}

gdb:

2017-06-06  Yao Qi  <yao.qi@linaro.org>

	* regformats/regdat.sh: Adjust code order.
---
 gdb/regformats/regdat.sh | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/gdb/regformats/regdat.sh b/gdb/regformats/regdat.sh
index 651f703..2c764cd 100755
--- a/gdb/regformats/regdat.sh
+++ b/gdb/regformats/regdat.sh
@@ -123,6 +123,15 @@ while do_read
 do
   if test "${type}" = "name"; then
     name="${entry}"
+
+    echo "const struct target_desc *tdesc_${name};"
+    echo ""
+    echo "void"
+    echo "init_registers_${name} (void)"
+    echo "{"
+    echo "  static struct target_desc tdesc_${name}_s;"
+    echo "  struct target_desc *result = &tdesc_${name}_s;"
+
     echo "static struct reg regs_${name}[] = {"
     continue
   elif test "${type}" = "xmltarget"; then
@@ -169,14 +178,6 @@ fi
 echo
 
 cat <<EOF
-const struct target_desc *tdesc_${name};
-
-void
-init_registers_${name} (void)
-{
-  static struct target_desc tdesc_${name}_s;
-  struct target_desc *result = &tdesc_${name}_s;
-
   result->reg_defs = regs_${name};
   result->num_registers = sizeof (regs_${name}) / sizeof (regs_${name}[0]);
 
-- 
1.9.1

^ permalink raw reply	[flat|nested] 82+ messages in thread

* [PATCH 09/25] Use target_desc fields expedite_regs and xmltarget ifndef IN_PROCESS_AGENT
  2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
                   ` (18 preceding siblings ...)
  2017-06-12  8:42 ` [PATCH 07/25] Lazily and dynamically create i386-linux target descriptions Yao Qi
@ 2017-06-12  8:42 ` Yao Qi
  2017-06-28 16:16   ` Pedro Alves
  2017-06-12  8:42 ` [PATCH 22/25] Regenerate two regformats/i386/.dat files Yao Qi
                   ` (6 subsequent siblings)
  26 siblings, 1 reply; 82+ messages in thread
From: Yao Qi @ 2017-06-12  8:42 UTC (permalink / raw)
  To: gdb-patches

struct target_desc is used by both GDBserver and IPA, but fields expedite_regs
and xmltarget are only used in GDBserver, so this patch wraps these two fields
by ifndef IN_PROCESS_AGENT.  This patch also changes regformats/regdat.sh to
generate .c files in this way too.

gdb/gdbserver:

2017-06-06  Yao Qi  <yao.qi@linaro.org>

	* tdesc.h (struct target_desc) [IN_PROCESS_AGENT] <expedite_regs>:
	Remove.
	[IN_PROCESS_AGENT] <xmltarget>: Likewise.

gdb:

2017-06-06  Yao Qi  <yao.qi@linaro.org>

	* regformats/regdat.sh: Generate code with "ifndef IN_PROCESS_AGENT".
---
 gdb/gdbserver/tdesc.h    | 2 ++
 gdb/regformats/regdat.sh | 3 +++
 2 files changed, 5 insertions(+)

diff --git a/gdb/gdbserver/tdesc.h b/gdb/gdbserver/tdesc.h
index ada879d..0341278 100644
--- a/gdb/gdbserver/tdesc.h
+++ b/gdb/gdbserver/tdesc.h
@@ -36,6 +36,7 @@ struct target_desc
   /* The register cache size, in bytes.  */
   int registers_size;
 
+#ifndef IN_PROCESS_AGENT
   /* An array of register names.  These are the "expedite" registers:
      registers whose values are sent along with stop replies.  */
   const char **expedite_regs;
@@ -45,6 +46,7 @@ struct target_desc
      verbatim XML code (prefixed with a '@') or else the name of the
      actual XML file to be used in place of "target.xml".  */
   const char *xmltarget;
+#endif
 };
 
 /* Copy target description SRC to DEST.  */
diff --git a/gdb/regformats/regdat.sh b/gdb/regformats/regdat.sh
index 4c73352..651f703 100755
--- a/gdb/regformats/regdat.sh
+++ b/gdb/regformats/regdat.sh
@@ -179,8 +179,11 @@ init_registers_${name} (void)
 
   result->reg_defs = regs_${name};
   result->num_registers = sizeof (regs_${name}) / sizeof (regs_${name}[0]);
+
+#ifndef IN_PROCESS_AGENT
   result->expedite_regs = expedite_regs_${name};
   result->xmltarget = xmltarget_${name};
+#endif
 
   init_target_desc (result);
 
-- 
1.9.1

^ permalink raw reply	[flat|nested] 82+ messages in thread

* [PATCH 13/25] Dynamically create tdesc in GDBserver
  2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
                   ` (21 preceding siblings ...)
  2017-06-12  8:42 ` [PATCH 21/25] Lazily and dynamically create amd64-linux target descriptions Yao Qi
@ 2017-06-12  8:42 ` Yao Qi
  2017-06-12  8:42 ` [PATCH 24/25] [GDBserver] Use pre-generated amd64-linux tdesc as test Yao Qi
                   ` (3 subsequent siblings)
  26 siblings, 0 replies; 82+ messages in thread
From: Yao Qi @ 2017-06-12  8:42 UTC (permalink / raw)
  To: gdb-patches

In this patch, GDBserver starts to use gdb/features/*.c feature files
by including them, so that GDBserver can create target descriptions
from features dynamically, like GDB does.  Adjust these feature .c
files for GDBserver.

These feature .c files calls some target description APIs only defined
GDB, so this patch also adds them in GDBserver.

TODO: complete ChangeLog.

gdb:

2017-06-06  Yao Qi  <yao.qi@linaro.org>

	* features/i386/32bit-avx.c: Re-generated.
	* features/i386/32bit-avx512.c: Re-generated.
	* features/i386/32bit-core.c: Re-generated.
	* features/i386/32bit-linux.c: Re-generated.
	* features/i386/32bit-mpx.c: Re-generated.
	* features/i386/32bit-pkeys.c: Re-generated.
	* features/i386/32bit-sse.c: Re-generated.

gdb/gdbserver:

2017-06-06  Yao Qi  <yao.qi@linaro.org>

	* linux-x86-tdesc.c: Include ../features/i386/32bit-*.c.
	(initialize_low_tdesc): Don't use tdesc_i386_XXX_linux.
	(i386_get_ipa_tdesc): Create target descriptions.
	* tdesc.c (init_target_desc):
	(current_target_desc):
	(tdesc_create_feature): +
	(tdesc_create_flags): +
	(tdesc_add_flag): +
	(tdesc_named_type): +
	(tdesc_create_reg): +
	(tdesc_create_vector): +
	(tdesc_add_bitfield): +
	(tdesc_add_field): +
	(tdesc_set_struct_size): +
	* tdesc.h (target_desc::target_desc): New.
	(target_desc::~target_desc): New.
	* regformats/regdat.sh: Generate code to call
	tdesc_create_reg.
	* target-descriptions.c (print_c_feature::visit): Print
	code for GDB.
---
 gdb/features/i386/32bit-avx.c    |  4 ++
 gdb/features/i386/32bit-avx512.c |  4 ++
 gdb/features/i386/32bit-core.c   |  4 ++
 gdb/features/i386/32bit-linux.c  |  4 ++
 gdb/features/i386/32bit-mpx.c    |  4 ++
 gdb/features/i386/32bit-pkeys.c  |  4 ++
 gdb/features/i386/32bit-sse.c    |  4 ++
 gdb/gdbserver/linux-x86-tdesc.c  | 86 +++++++++++++++++++++++++++++++++++-----
 gdb/gdbserver/tdesc.c            | 78 +++++++++++++++++++++++++++++++++++-
 gdb/gdbserver/tdesc.h            | 58 ++++++++++++++++++++++++++-
 gdb/regformats/regdat.sh         | 10 ++---
 gdb/target-descriptions.c        |  4 ++
 12 files changed, 243 insertions(+), 21 deletions(-)

diff --git a/gdb/features/i386/32bit-avx.c b/gdb/features/i386/32bit-avx.c
index 53a939b..bae025d 100644
--- a/gdb/features/i386/32bit-avx.c
+++ b/gdb/features/i386/32bit-avx.c
@@ -1,9 +1,13 @@
 /* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
   Original: 32bit-avx.xml.tmp */
 
+#ifdef GDBSERVER
+#include "tdesc.h"
+#else
 #include "defs.h"
 #include "osabi.h"
 #include "target-descriptions.h"
+#endif
 
 static int
 create_feature_i386_32bit_avx (struct target_desc *result, long regnum)
diff --git a/gdb/features/i386/32bit-avx512.c b/gdb/features/i386/32bit-avx512.c
index 9bbf392..ca15f8b 100644
--- a/gdb/features/i386/32bit-avx512.c
+++ b/gdb/features/i386/32bit-avx512.c
@@ -1,9 +1,13 @@
 /* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
   Original: 32bit-avx512.xml.tmp */
 
+#ifdef GDBSERVER
+#include "tdesc.h"
+#else
 #include "defs.h"
 #include "osabi.h"
 #include "target-descriptions.h"
+#endif
 
 static int
 create_feature_i386_32bit_avx512 (struct target_desc *result, long regnum)
diff --git a/gdb/features/i386/32bit-core.c b/gdb/features/i386/32bit-core.c
index c5f0fca..8db91ab 100644
--- a/gdb/features/i386/32bit-core.c
+++ b/gdb/features/i386/32bit-core.c
@@ -1,9 +1,13 @@
 /* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
   Original: 32bit-core.xml.tmp */
 
+#ifdef GDBSERVER
+#include "tdesc.h"
+#else
 #include "defs.h"
 #include "osabi.h"
 #include "target-descriptions.h"
+#endif
 
 static int
 create_feature_i386_32bit_core (struct target_desc *result, long regnum)
diff --git a/gdb/features/i386/32bit-linux.c b/gdb/features/i386/32bit-linux.c
index ff90d40..7535c55 100644
--- a/gdb/features/i386/32bit-linux.c
+++ b/gdb/features/i386/32bit-linux.c
@@ -1,9 +1,13 @@
 /* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
   Original: 32bit-linux.xml.tmp */
 
+#ifdef GDBSERVER
+#include "tdesc.h"
+#else
 #include "defs.h"
 #include "osabi.h"
 #include "target-descriptions.h"
+#endif
 
 static int
 create_feature_i386_32bit_linux (struct target_desc *result, long regnum)
diff --git a/gdb/features/i386/32bit-mpx.c b/gdb/features/i386/32bit-mpx.c
index 50b627e..9f1ae67 100644
--- a/gdb/features/i386/32bit-mpx.c
+++ b/gdb/features/i386/32bit-mpx.c
@@ -1,9 +1,13 @@
 /* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
   Original: 32bit-mpx.xml.tmp */
 
+#ifdef GDBSERVER
+#include "tdesc.h"
+#else
 #include "defs.h"
 #include "osabi.h"
 #include "target-descriptions.h"
+#endif
 
 static int
 create_feature_i386_32bit_mpx (struct target_desc *result, long regnum)
diff --git a/gdb/features/i386/32bit-pkeys.c b/gdb/features/i386/32bit-pkeys.c
index afb4958..86035ab 100644
--- a/gdb/features/i386/32bit-pkeys.c
+++ b/gdb/features/i386/32bit-pkeys.c
@@ -1,9 +1,13 @@
 /* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
   Original: 32bit-pkeys.xml.tmp */
 
+#ifdef GDBSERVER
+#include "tdesc.h"
+#else
 #include "defs.h"
 #include "osabi.h"
 #include "target-descriptions.h"
+#endif
 
 static int
 create_feature_i386_32bit_pkeys (struct target_desc *result, long regnum)
diff --git a/gdb/features/i386/32bit-sse.c b/gdb/features/i386/32bit-sse.c
index 08c3948..876c04d 100644
--- a/gdb/features/i386/32bit-sse.c
+++ b/gdb/features/i386/32bit-sse.c
@@ -1,9 +1,13 @@
 /* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
   Original: 32bit-sse.xml.tmp */
 
+#ifdef GDBSERVER
+#include "tdesc.h"
+#else
 #include "defs.h"
 #include "osabi.h"
 #include "target-descriptions.h"
+#endif
 
 static int
 create_feature_i386_32bit_sse (struct target_desc *result, long regnum)
diff --git a/gdb/gdbserver/linux-x86-tdesc.c b/gdb/gdbserver/linux-x86-tdesc.c
index e294a98..f247a3c 100644
--- a/gdb/gdbserver/linux-x86-tdesc.c
+++ b/gdb/gdbserver/linux-x86-tdesc.c
@@ -18,8 +18,17 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "server.h"
+#include "tdesc.h"
 #include "linux-x86-tdesc.h"
 
+#include "../features/i386/32bit-core.c"
+#include "../features/i386/32bit-linux.c"
+#include "../features/i386/32bit-sse.c"
+#include "../features/i386/32bit-avx.c"
+#include "../features/i386/32bit-avx512.c"
+#include "../features/i386/32bit-mpx.c"
+#include "../features/i386/32bit-pkeys.c"
+
 #if defined __i386__ || !defined IN_PROCESS_AGENT
 /* Defined in auto-generated file i386-linux.c.  */
 void init_registers_i386_linux (void);
@@ -63,15 +72,6 @@ initialize_low_tdesc ()
   init_registers_i386_avx_mpx_linux ();
   init_registers_i386_avx_avx512_linux ();
   init_registers_i386_avx_mpx_avx512_pku_linux ();
-
-  i386_tdescs[X86_TDESC_MMX] = tdesc_i386_mmx_linux;
-  i386_tdescs[X86_TDESC_SSE] = tdesc_i386_linux;
-  i386_tdescs[X86_TDESC_AVX] = tdesc_i386_avx_linux;
-  i386_tdescs[X86_TDESC_MPX] = tdesc_i386_mpx_linux;
-  i386_tdescs[X86_TDESC_AVX_MPX] = tdesc_i386_avx_mpx_linux;
-  i386_tdescs[X86_TDESC_AVX_AVX512] = tdesc_i386_avx_avx512_linux;
-  i386_tdescs[X86_TDESC_AVX_MPX_AVX512_PKU]
-    = tdesc_i386_avx_mpx_avx512_pku_linux;
 #endif
 }
 
@@ -82,7 +82,73 @@ i386_get_ipa_tdesc (int idx)
     internal_error (__FILE__, __LINE__,
 		    "unknown ipa tdesc index: %d", idx);
 
-  return i386_tdescs[idx];
+  struct target_desc **tdesc = (struct target_desc **) &i386_tdescs[idx];
+
+  if (*tdesc == NULL)
+    {
+      *tdesc = new target_desc ();
+      long regnum = 0;
+
+      regnum = create_feature_i386_32bit_core (*tdesc, regnum);
+
+      if (idx != X86_TDESC_MMX)
+	regnum = create_feature_i386_32bit_sse (*tdesc, regnum);
+
+      regnum = create_feature_i386_32bit_linux (*tdesc, regnum);
+
+      if (idx == X86_TDESC_AVX || idx == X86_TDESC_AVX_MPX
+	  || idx == X86_TDESC_AVX_AVX512
+	  || idx == X86_TDESC_AVX_MPX_AVX512_PKU)
+	regnum = create_feature_i386_32bit_avx (*tdesc, regnum);
+
+      if (idx == X86_TDESC_MPX || idx == X86_TDESC_AVX_MPX
+	  || idx == X86_TDESC_AVX_MPX_AVX512_PKU)
+	regnum = create_feature_i386_32bit_mpx (*tdesc, regnum);
+
+      if (idx == X86_TDESC_AVX_AVX512
+	  || idx == X86_TDESC_AVX_MPX_AVX512_PKU)
+	regnum = create_feature_i386_32bit_avx512 (*tdesc, regnum);
+
+      if (idx == X86_TDESC_AVX_MPX_AVX512_PKU)
+	regnum = create_feature_i386_32bit_pkeys (*tdesc, regnum);
+
+      init_target_desc (*tdesc);
+
+#ifndef IN_PROCESS_AGENT
+      static const char *expedite_regs_i386[] = { "ebp", "esp", "eip", NULL };
+      (*tdesc)->expedite_regs = expedite_regs_i386;
+
+      switch (idx)
+	{
+	case X86_TDESC_MMX:
+	  (*tdesc)->xmltarget = "i386-mmx-linux.xml";
+	  break;
+	case X86_TDESC_SSE:
+	  (*tdesc)->xmltarget = "i386-linux.xml";
+	  break;
+	case X86_TDESC_AVX:
+	  (*tdesc)->xmltarget = "i386-avx-linux.xml";
+	  break;
+	case X86_TDESC_MPX:
+	  (*tdesc)->xmltarget = "i386-mpx-linux.xml";
+	  break;
+	case X86_TDESC_AVX_MPX:
+	  (*tdesc)->xmltarget = "i386-avx-mpx-linux.xml";
+	  break;
+	case X86_TDESC_AVX_AVX512:
+	  (*tdesc)->xmltarget = "i386-avx-avx512-linux.xml";
+	  break;
+	case X86_TDESC_AVX_MPX_AVX512_PKU:
+	  (*tdesc)->xmltarget = "i386-avx-mpx-avx512-pku-linux.xml";
+	  break;
+	default:
+	  internal_error (__FILE__, __LINE__,
+			  "unknown ipa tdesc index: %d", idx);
+	}
+
+#endif
+    }
+  return *tdesc;;
 }
 
 #ifdef IN_PROCESS_AGENT
diff --git a/gdb/gdbserver/tdesc.c b/gdb/gdbserver/tdesc.c
index 1b1882e..686c76a 100644
--- a/gdb/gdbserver/tdesc.c
+++ b/gdb/gdbserver/tdesc.c
@@ -41,7 +41,7 @@ init_target_desc (struct target_desc *tdesc)
 
 #ifndef IN_PROCESS_AGENT
 
-static const struct target_desc default_description = { NULL, 0, NULL, NULL };
+static const struct target_desc default_description {};
 
 void
 copy_target_description (struct target_desc *dest,
@@ -61,5 +61,79 @@ current_target_desc (void)
 
   return current_process ()->tdesc;
 }
-
 #endif
+
+struct tdesc_type
+{};
+
+struct tdesc_feature *
+tdesc_create_feature (struct target_desc *tdesc, const char *name)
+{
+  return tdesc;
+}
+
+struct tdesc_type *
+tdesc_create_flags (struct tdesc_feature *feature, const char *name,
+		    int size)
+{
+  return NULL;
+}
+
+void
+tdesc_add_flag (struct tdesc_type *type, int start,
+		const char *flag_name)
+{}
+
+struct tdesc_type *
+tdesc_named_type (const struct tdesc_feature *feature, const char *id)
+{
+  return NULL;
+}
+
+void
+tdesc_create_reg (struct tdesc_feature *feature, const char *name,
+		  int regnum, int save_restore, const char *group,
+		  int bitsize, const char *type)
+{
+  struct target_desc *tdesc = (struct target_desc *) feature;
+
+  while (VEC_length (tdesc_reg_p, tdesc->reg_defs) < regnum)
+    {
+      struct reg *reg = XCNEW (struct reg);
+
+      reg->name = "";
+      reg->size = 0;
+      VEC_safe_push (tdesc_reg_p, tdesc->reg_defs, reg);
+    }
+
+  gdb_assert (regnum == 0
+	      || regnum == VEC_length (tdesc_reg_p, tdesc->reg_defs));
+
+  struct reg *reg = XCNEW (struct reg);
+
+  reg->name = name;
+  reg->size = bitsize;
+  VEC_safe_push (tdesc_reg_p, tdesc->reg_defs, reg);
+}
+
+struct tdesc_type *
+tdesc_create_vector (struct tdesc_feature *feature, const char *name,
+		     struct tdesc_type *field_type, int count)
+{
+  return NULL;
+}
+
+void
+tdesc_add_bitfield (struct tdesc_type *type, const char *field_name,
+		    int start, int end)
+{}
+
+void
+tdesc_add_field (struct tdesc_type *type, const char *field_name,
+		 struct tdesc_type *field_type)
+{}
+
+void
+tdesc_set_struct_size (struct tdesc_type *type, int size)
+{
+}
diff --git a/gdb/gdbserver/tdesc.h b/gdb/gdbserver/tdesc.h
index 424a2fd..2d4cbfa 100644
--- a/gdb/gdbserver/tdesc.h
+++ b/gdb/gdbserver/tdesc.h
@@ -38,13 +38,28 @@ struct target_desc
 #ifndef IN_PROCESS_AGENT
   /* An array of register names.  These are the "expedite" registers:
      registers whose values are sent along with stop replies.  */
-  const char **expedite_regs;
+  const char **expedite_regs = NULL;
 
   /* Defines what to return when looking for the "target.xml" file in
      response to qXfer:features:read.  Its contents can either be
      verbatim XML code (prefixed with a '@') or else the name of the
      actual XML file to be used in place of "target.xml".  */
-  const char *xmltarget;
+  const char *xmltarget = NULL;
+
+public:
+  target_desc ()
+    : reg_defs (NULL), registers_size (0)
+  {}
+
+  ~target_desc ()
+  {
+    int i;
+    struct reg *reg;
+
+    for (i = 0; VEC_iterate (tdesc_reg_p, reg_defs, i, reg); i++)
+      xfree (reg);
+    VEC_free (tdesc_reg_p, reg_defs);
+  }
 #endif
 };
 
@@ -62,4 +77,43 @@ void init_target_desc (struct target_desc *tdesc);
 
 const struct target_desc *current_target_desc (void);
 
+#ifndef IN_PROCESS_AGENT
+#endif
+
+#define tdesc_feature target_desc
+
+struct tdesc_type;
+
+struct tdesc_feature *tdesc_create_feature (struct target_desc *tdesc,
+					    const char *name);
+
+struct tdesc_type *tdesc_create_flags (struct tdesc_feature *feature,
+				       const char *name, int size);
+
+void tdesc_add_flag (struct tdesc_type *type, int start,
+		     const char *flag_name);
+
+struct tdesc_type *tdesc_named_type (const struct tdesc_feature *feature,
+				     const char *id);
+
+#define tdesc_create_union tdesc_named_type
+#define tdesc_create_struct tdesc_named_type
+
+void tdesc_add_field (struct tdesc_type *type, const char *field_name,
+		      struct tdesc_type *field_type);
+
+void tdesc_set_struct_size (struct tdesc_type *type, int size);
+
+void tdesc_add_bitfield (struct tdesc_type *type, const char *field_name,
+			 int start, int end);
+
+void tdesc_create_reg (struct tdesc_feature *feature, const char *name,
+		       int regnum, int save_restore, const char *group,
+		       int bitsize, const char *type);
+
+struct tdesc_type *tdesc_create_vector (struct tdesc_feature *feature,
+					const char *name,
+					struct tdesc_type *field_type,
+					int count);
+
 #endif /* TDESC_H */
diff --git a/gdb/regformats/regdat.sh b/gdb/regformats/regdat.sh
index 236cd93..66449cc 100755
--- a/gdb/regformats/regdat.sh
+++ b/gdb/regformats/regdat.sh
@@ -131,7 +131,6 @@ do
     echo "{"
     echo "  static struct target_desc tdesc_${name}_s;"
     echo "  struct target_desc *result = &tdesc_${name}_s;"
-    echo "  memset (result, 0, sizeof (*result));"
 
     continue
   elif test "${type}" = "xmltarget"; then
@@ -150,12 +149,9 @@ do
     echo "$0: $1 does not specify \`\`name''." 1>&2
     exit 1
   else
-    echo "  {struct reg *reg = XCNEW (struct reg);"
-    echo "  reg->name = \"${entry}\";"
-    echo "  reg->offset = ${offset};"
-    echo "  reg->size = ${type};"
-    echo "  VEC_safe_push (tdesc_reg_p, result->reg_defs, reg);"
-    echo "  };"
+    echo "  tdesc_create_reg ((struct tdesc_feature *) result, \"${entry}\","
+    echo "  0, 0, NULL, ${type}, NULL);"
+
     offset=`expr ${offset} + ${type}`
     i=`expr $i + 1`
   fi
diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
index 2b3083a..38e28d3 100644
--- a/gdb/target-descriptions.c
+++ b/gdb/target-descriptions.c
@@ -2166,9 +2166,13 @@ public:
 
   void visit (const target_desc *e) override
   {
+    printf_unfiltered ("#ifdef GDBSERVER\n");
+    printf_unfiltered ("#include \"tdesc.h\"\n");
+    printf_unfiltered ("#else\n");
     printf_unfiltered ("#include \"defs.h\"\n");
     printf_unfiltered ("#include \"osabi.h\"\n");
     printf_unfiltered ("#include \"target-descriptions.h\"\n");
+    printf_unfiltered ("#endif\n");
     printf_unfiltered ("\n");
   }
 
-- 
1.9.1

^ permalink raw reply	[flat|nested] 82+ messages in thread

* [PATCH 17/25] Remove features/i386/i386-*linux.c
  2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
                   ` (7 preceding siblings ...)
  2017-06-12  8:42 ` [PATCH 05/25] Use visitor pattern for "maint print c-tdesc" Yao Qi
@ 2017-06-12  8:42 ` Yao Qi
  2017-06-12  8:42 ` [PATCH 23/25] [GDBserver] Convert amd64-linux target descriptions Yao Qi
                   ` (17 subsequent siblings)
  26 siblings, 0 replies; 82+ messages in thread
From: Yao Qi @ 2017-06-12  8:42 UTC (permalink / raw)
  To: gdb-patches

Now, features/i386/i386-XXX-linux.c are not used, remove them.

gdb:

2017-05-26  Yao Qi  <yao.qi@linaro.org>

	* features/Makefile (XMLTOC): Remove i386/i386-XX-linux.xml.
	* features/i386/i386-avx-avx512-linux.c: Remove.
	* features/i386/i386-avx-linux.c: Remove.
	* features/i386/i386-avx-mpx-avx512-pku-linux.c: Remove.
	* features/i386/i386-avx-mpx-linux.c: Remove.
	* features/i386/i386-linux.c: Remove.
	* features/i386/i386-mmx-linux.c: Remove.
	* features/i386/i386-mpx-linux.c: Remove.
---
 gdb/features/Makefile                             |   7 -
 gdb/features/i386/i386-avx-avx512-linux.c         | 170 -----------------
 gdb/features/i386/i386-avx-linux.c                | 149 ---------------
 gdb/features/i386/i386-avx-mpx-avx512-pku-linux.c | 211 ----------------------
 gdb/features/i386/i386-avx-mpx-linux.c            | 187 -------------------
 gdb/features/i386/i386-linux.c                    | 139 --------------
 gdb/features/i386/i386-mmx-linux.c                |  78 --------
 gdb/features/i386/i386-mpx-linux.c                | 177 ------------------
 8 files changed, 1118 deletions(-)
 delete mode 100644 gdb/features/i386/i386-avx-avx512-linux.c
 delete mode 100644 gdb/features/i386/i386-avx-linux.c
 delete mode 100644 gdb/features/i386/i386-avx-mpx-avx512-pku-linux.c
 delete mode 100644 gdb/features/i386/i386-avx-mpx-linux.c
 delete mode 100644 gdb/features/i386/i386-linux.c
 delete mode 100644 gdb/features/i386/i386-mmx-linux.c
 delete mode 100644 gdb/features/i386/i386-mpx-linux.c

diff --git a/gdb/features/Makefile b/gdb/features/Makefile
index 28a7e20..9fdaeba 100644
--- a/gdb/features/Makefile
+++ b/gdb/features/Makefile
@@ -150,18 +150,11 @@ XMLTOC = \
 	i386/amd64-avx-mpx-linux.xml \
 	i386/amd64-avx-mpx.xml \
 	i386/amd64.xml \
-	i386/i386-avx-linux.xml \
 	i386/i386-avx.xml \
-	i386/i386-avx-avx512-linux.xml \
 	i386/i386-avx-avx512.xml \
-	i386/i386-avx-mpx-avx512-pku-linux.xml \
 	i386/i386-avx-mpx-avx512-pku.xml \
-	i386/i386-linux.xml \
-	i386/i386-mmx-linux.xml \
 	i386/i386-mmx.xml \
-	i386/i386-mpx-linux.xml \
 	i386/i386-mpx.xml \
-	i386/i386-avx-mpx-linux.xml \
 	i386/i386-avx-mpx.xml \
 	i386/i386.xml \
 	i386/x32-avx-linux.xml \
diff --git a/gdb/features/i386/i386-avx-avx512-linux.c b/gdb/features/i386/i386-avx-avx512-linux.c
deleted file mode 100644
index 545149d..0000000
--- a/gdb/features/i386/i386-avx-avx512-linux.c
+++ /dev/null
@@ -1,170 +0,0 @@
-/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
-  Original: i386-avx-avx512-linux.xml */
-
-#include "defs.h"
-#include "osabi.h"
-#include "target-descriptions.h"
-
-struct target_desc *tdesc_i386_avx_avx512_linux;
-static void
-initialize_tdesc_i386_avx_avx512_linux (void)
-{
-  struct target_desc *result = allocate_target_description ();
-  set_tdesc_architecture (result, bfd_scan_arch ("i386"));
-
-  set_tdesc_osabi (result, osabi_from_tdesc_string ("GNU/Linux"));
-
-  struct tdesc_feature *feature;
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-  type = tdesc_create_flags (feature, "i386_eflags", 4);
-  tdesc_add_flag (type, 0, "CF");
-  tdesc_add_flag (type, 1, "");
-  tdesc_add_flag (type, 2, "PF");
-  tdesc_add_flag (type, 4, "AF");
-  tdesc_add_flag (type, 6, "ZF");
-  tdesc_add_flag (type, 7, "SF");
-  tdesc_add_flag (type, 8, "TF");
-  tdesc_add_flag (type, 9, "IF");
-  tdesc_add_flag (type, 10, "DF");
-  tdesc_add_flag (type, 11, "OF");
-  tdesc_add_flag (type, 14, "NT");
-  tdesc_add_flag (type, 16, "RF");
-  tdesc_add_flag (type, 17, "VM");
-  tdesc_add_flag (type, 18, "AC");
-  tdesc_add_flag (type, 19, "VIF");
-  tdesc_add_flag (type, 20, "VIP");
-  tdesc_add_flag (type, 21, "ID");
-
-  tdesc_create_reg (feature, "eax", 0, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ecx", 1, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "edx", 2, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ebx", 3, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "esp", 4, 1, NULL, 32, "data_ptr");
-  tdesc_create_reg (feature, "ebp", 5, 1, NULL, 32, "data_ptr");
-  tdesc_create_reg (feature, "esi", 6, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "edi", 7, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "eip", 8, 1, NULL, 32, "code_ptr");
-  tdesc_create_reg (feature, "eflags", 9, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 10, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 11, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 12, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 13, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 14, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 15, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "st0", 16, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st1", 17, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st2", 18, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st3", 19, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st4", 20, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st5", 21, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st6", 22, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st7", 23, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "fctrl", 24, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fstat", 25, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "ftag", 26, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fiseg", 27, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fioff", 28, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "foseg", 29, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fooff", 30, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fop", 31, 1, "float", 32, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.sse");
-  field_type = tdesc_named_type (feature, "ieee_single");
-  tdesc_create_vector (feature, "v4f", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "ieee_double");
-  tdesc_create_vector (feature, "v2d", field_type, 2);
-
-  field_type = tdesc_named_type (feature, "int8");
-  tdesc_create_vector (feature, "v16i8", field_type, 16);
-
-  field_type = tdesc_named_type (feature, "int16");
-  tdesc_create_vector (feature, "v8i16", field_type, 8);
-
-  field_type = tdesc_named_type (feature, "int32");
-  tdesc_create_vector (feature, "v4i32", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "int64");
-  tdesc_create_vector (feature, "v2i64", field_type, 2);
-
-  type = tdesc_create_union (feature, "vec128");
-  field_type = tdesc_named_type (feature, "v4f");
-  tdesc_add_field (type, "v4_float", field_type);
-  field_type = tdesc_named_type (feature, "v2d");
-  tdesc_add_field (type, "v2_double", field_type);
-  field_type = tdesc_named_type (feature, "v16i8");
-  tdesc_add_field (type, "v16_int8", field_type);
-  field_type = tdesc_named_type (feature, "v8i16");
-  tdesc_add_field (type, "v8_int16", field_type);
-  field_type = tdesc_named_type (feature, "v4i32");
-  tdesc_add_field (type, "v4_int32", field_type);
-  field_type = tdesc_named_type (feature, "v2i64");
-  tdesc_add_field (type, "v2_int64", field_type);
-  field_type = tdesc_named_type (feature, "uint128");
-  tdesc_add_field (type, "uint128", field_type);
-
-  type = tdesc_create_flags (feature, "i386_mxcsr", 4);
-  tdesc_add_flag (type, 0, "IE");
-  tdesc_add_flag (type, 1, "DE");
-  tdesc_add_flag (type, 2, "ZE");
-  tdesc_add_flag (type, 3, "OE");
-  tdesc_add_flag (type, 4, "UE");
-  tdesc_add_flag (type, 5, "PE");
-  tdesc_add_flag (type, 6, "DAZ");
-  tdesc_add_flag (type, 7, "IM");
-  tdesc_add_flag (type, 8, "DM");
-  tdesc_add_flag (type, 9, "ZM");
-  tdesc_add_flag (type, 10, "OM");
-  tdesc_add_flag (type, 11, "UM");
-  tdesc_add_flag (type, 12, "PM");
-  tdesc_add_flag (type, 15, "FZ");
-
-  tdesc_create_reg (feature, "xmm0", 32, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm1", 33, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm2", 34, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm3", 35, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm4", 36, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm5", 37, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm6", 38, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm7", 39, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "mxcsr", 40, 1, "vector", 32, "i386_mxcsr");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
-  tdesc_create_reg (feature, "orig_eax", 41, 1, NULL, 32, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx");
-  tdesc_create_reg (feature, "ymm0h", 42, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm1h", 43, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm2h", 44, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm3h", 45, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm4h", 46, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm5h", 47, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm6h", 48, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm7h", 49, 1, NULL, 128, "uint128");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx512");
-  field_type = tdesc_named_type (feature, "uint128");
-  tdesc_create_vector (feature, "v2ui128", field_type, 2);
-
-  tdesc_create_reg (feature, "k0", 50, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k1", 51, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k2", 52, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k3", 53, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k4", 54, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k5", 55, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k6", 56, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k7", 57, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "zmm0h", 58, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm1h", 59, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm2h", 60, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm3h", 61, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm4h", 62, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm5h", 63, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm6h", 64, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm7h", 65, 1, NULL, 256, "v2ui128");
-
-  tdesc_i386_avx_avx512_linux = result;
-}
diff --git a/gdb/features/i386/i386-avx-linux.c b/gdb/features/i386/i386-avx-linux.c
deleted file mode 100644
index 3ef087d..0000000
--- a/gdb/features/i386/i386-avx-linux.c
+++ /dev/null
@@ -1,149 +0,0 @@
-/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
-  Original: i386-avx-linux.xml */
-
-#include "defs.h"
-#include "osabi.h"
-#include "target-descriptions.h"
-
-struct target_desc *tdesc_i386_avx_linux;
-static void
-initialize_tdesc_i386_avx_linux (void)
-{
-  struct target_desc *result = allocate_target_description ();
-  set_tdesc_architecture (result, bfd_scan_arch ("i386"));
-
-  set_tdesc_osabi (result, osabi_from_tdesc_string ("GNU/Linux"));
-
-  struct tdesc_feature *feature;
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-  type = tdesc_create_flags (feature, "i386_eflags", 4);
-  tdesc_add_flag (type, 0, "CF");
-  tdesc_add_flag (type, 1, "");
-  tdesc_add_flag (type, 2, "PF");
-  tdesc_add_flag (type, 4, "AF");
-  tdesc_add_flag (type, 6, "ZF");
-  tdesc_add_flag (type, 7, "SF");
-  tdesc_add_flag (type, 8, "TF");
-  tdesc_add_flag (type, 9, "IF");
-  tdesc_add_flag (type, 10, "DF");
-  tdesc_add_flag (type, 11, "OF");
-  tdesc_add_flag (type, 14, "NT");
-  tdesc_add_flag (type, 16, "RF");
-  tdesc_add_flag (type, 17, "VM");
-  tdesc_add_flag (type, 18, "AC");
-  tdesc_add_flag (type, 19, "VIF");
-  tdesc_add_flag (type, 20, "VIP");
-  tdesc_add_flag (type, 21, "ID");
-
-  tdesc_create_reg (feature, "eax", 0, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ecx", 1, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "edx", 2, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ebx", 3, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "esp", 4, 1, NULL, 32, "data_ptr");
-  tdesc_create_reg (feature, "ebp", 5, 1, NULL, 32, "data_ptr");
-  tdesc_create_reg (feature, "esi", 6, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "edi", 7, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "eip", 8, 1, NULL, 32, "code_ptr");
-  tdesc_create_reg (feature, "eflags", 9, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 10, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 11, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 12, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 13, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 14, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 15, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "st0", 16, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st1", 17, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st2", 18, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st3", 19, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st4", 20, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st5", 21, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st6", 22, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st7", 23, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "fctrl", 24, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fstat", 25, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "ftag", 26, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fiseg", 27, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fioff", 28, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "foseg", 29, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fooff", 30, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fop", 31, 1, "float", 32, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.sse");
-  field_type = tdesc_named_type (feature, "ieee_single");
-  tdesc_create_vector (feature, "v4f", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "ieee_double");
-  tdesc_create_vector (feature, "v2d", field_type, 2);
-
-  field_type = tdesc_named_type (feature, "int8");
-  tdesc_create_vector (feature, "v16i8", field_type, 16);
-
-  field_type = tdesc_named_type (feature, "int16");
-  tdesc_create_vector (feature, "v8i16", field_type, 8);
-
-  field_type = tdesc_named_type (feature, "int32");
-  tdesc_create_vector (feature, "v4i32", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "int64");
-  tdesc_create_vector (feature, "v2i64", field_type, 2);
-
-  type = tdesc_create_union (feature, "vec128");
-  field_type = tdesc_named_type (feature, "v4f");
-  tdesc_add_field (type, "v4_float", field_type);
-  field_type = tdesc_named_type (feature, "v2d");
-  tdesc_add_field (type, "v2_double", field_type);
-  field_type = tdesc_named_type (feature, "v16i8");
-  tdesc_add_field (type, "v16_int8", field_type);
-  field_type = tdesc_named_type (feature, "v8i16");
-  tdesc_add_field (type, "v8_int16", field_type);
-  field_type = tdesc_named_type (feature, "v4i32");
-  tdesc_add_field (type, "v4_int32", field_type);
-  field_type = tdesc_named_type (feature, "v2i64");
-  tdesc_add_field (type, "v2_int64", field_type);
-  field_type = tdesc_named_type (feature, "uint128");
-  tdesc_add_field (type, "uint128", field_type);
-
-  type = tdesc_create_flags (feature, "i386_mxcsr", 4);
-  tdesc_add_flag (type, 0, "IE");
-  tdesc_add_flag (type, 1, "DE");
-  tdesc_add_flag (type, 2, "ZE");
-  tdesc_add_flag (type, 3, "OE");
-  tdesc_add_flag (type, 4, "UE");
-  tdesc_add_flag (type, 5, "PE");
-  tdesc_add_flag (type, 6, "DAZ");
-  tdesc_add_flag (type, 7, "IM");
-  tdesc_add_flag (type, 8, "DM");
-  tdesc_add_flag (type, 9, "ZM");
-  tdesc_add_flag (type, 10, "OM");
-  tdesc_add_flag (type, 11, "UM");
-  tdesc_add_flag (type, 12, "PM");
-  tdesc_add_flag (type, 15, "FZ");
-
-  tdesc_create_reg (feature, "xmm0", 32, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm1", 33, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm2", 34, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm3", 35, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm4", 36, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm5", 37, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm6", 38, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm7", 39, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "mxcsr", 40, 1, "vector", 32, "i386_mxcsr");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
-  tdesc_create_reg (feature, "orig_eax", 41, 1, NULL, 32, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx");
-  tdesc_create_reg (feature, "ymm0h", 42, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm1h", 43, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm2h", 44, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm3h", 45, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm4h", 46, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm5h", 47, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm6h", 48, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm7h", 49, 1, NULL, 128, "uint128");
-
-  tdesc_i386_avx_linux = result;
-}
diff --git a/gdb/features/i386/i386-avx-mpx-avx512-pku-linux.c b/gdb/features/i386/i386-avx-mpx-avx512-pku-linux.c
deleted file mode 100644
index e6eebf1..0000000
--- a/gdb/features/i386/i386-avx-mpx-avx512-pku-linux.c
+++ /dev/null
@@ -1,211 +0,0 @@
-/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
-  Original: i386-avx-mpx-avx512-pku-linux.xml */
-
-#include "defs.h"
-#include "osabi.h"
-#include "target-descriptions.h"
-
-struct target_desc *tdesc_i386_avx_mpx_avx512_pku_linux;
-static void
-initialize_tdesc_i386_avx_mpx_avx512_pku_linux (void)
-{
-  struct target_desc *result = allocate_target_description ();
-  set_tdesc_architecture (result, bfd_scan_arch ("i386"));
-
-  set_tdesc_osabi (result, osabi_from_tdesc_string ("GNU/Linux"));
-
-  struct tdesc_feature *feature;
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-  type = tdesc_create_flags (feature, "i386_eflags", 4);
-  tdesc_add_flag (type, 0, "CF");
-  tdesc_add_flag (type, 1, "");
-  tdesc_add_flag (type, 2, "PF");
-  tdesc_add_flag (type, 4, "AF");
-  tdesc_add_flag (type, 6, "ZF");
-  tdesc_add_flag (type, 7, "SF");
-  tdesc_add_flag (type, 8, "TF");
-  tdesc_add_flag (type, 9, "IF");
-  tdesc_add_flag (type, 10, "DF");
-  tdesc_add_flag (type, 11, "OF");
-  tdesc_add_flag (type, 14, "NT");
-  tdesc_add_flag (type, 16, "RF");
-  tdesc_add_flag (type, 17, "VM");
-  tdesc_add_flag (type, 18, "AC");
-  tdesc_add_flag (type, 19, "VIF");
-  tdesc_add_flag (type, 20, "VIP");
-  tdesc_add_flag (type, 21, "ID");
-
-  tdesc_create_reg (feature, "eax", 0, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ecx", 1, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "edx", 2, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ebx", 3, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "esp", 4, 1, NULL, 32, "data_ptr");
-  tdesc_create_reg (feature, "ebp", 5, 1, NULL, 32, "data_ptr");
-  tdesc_create_reg (feature, "esi", 6, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "edi", 7, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "eip", 8, 1, NULL, 32, "code_ptr");
-  tdesc_create_reg (feature, "eflags", 9, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 10, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 11, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 12, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 13, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 14, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 15, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "st0", 16, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st1", 17, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st2", 18, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st3", 19, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st4", 20, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st5", 21, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st6", 22, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st7", 23, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "fctrl", 24, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fstat", 25, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "ftag", 26, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fiseg", 27, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fioff", 28, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "foseg", 29, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fooff", 30, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fop", 31, 1, "float", 32, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.sse");
-  field_type = tdesc_named_type (feature, "ieee_single");
-  tdesc_create_vector (feature, "v4f", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "ieee_double");
-  tdesc_create_vector (feature, "v2d", field_type, 2);
-
-  field_type = tdesc_named_type (feature, "int8");
-  tdesc_create_vector (feature, "v16i8", field_type, 16);
-
-  field_type = tdesc_named_type (feature, "int16");
-  tdesc_create_vector (feature, "v8i16", field_type, 8);
-
-  field_type = tdesc_named_type (feature, "int32");
-  tdesc_create_vector (feature, "v4i32", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "int64");
-  tdesc_create_vector (feature, "v2i64", field_type, 2);
-
-  type = tdesc_create_union (feature, "vec128");
-  field_type = tdesc_named_type (feature, "v4f");
-  tdesc_add_field (type, "v4_float", field_type);
-  field_type = tdesc_named_type (feature, "v2d");
-  tdesc_add_field (type, "v2_double", field_type);
-  field_type = tdesc_named_type (feature, "v16i8");
-  tdesc_add_field (type, "v16_int8", field_type);
-  field_type = tdesc_named_type (feature, "v8i16");
-  tdesc_add_field (type, "v8_int16", field_type);
-  field_type = tdesc_named_type (feature, "v4i32");
-  tdesc_add_field (type, "v4_int32", field_type);
-  field_type = tdesc_named_type (feature, "v2i64");
-  tdesc_add_field (type, "v2_int64", field_type);
-  field_type = tdesc_named_type (feature, "uint128");
-  tdesc_add_field (type, "uint128", field_type);
-
-  type = tdesc_create_flags (feature, "i386_mxcsr", 4);
-  tdesc_add_flag (type, 0, "IE");
-  tdesc_add_flag (type, 1, "DE");
-  tdesc_add_flag (type, 2, "ZE");
-  tdesc_add_flag (type, 3, "OE");
-  tdesc_add_flag (type, 4, "UE");
-  tdesc_add_flag (type, 5, "PE");
-  tdesc_add_flag (type, 6, "DAZ");
-  tdesc_add_flag (type, 7, "IM");
-  tdesc_add_flag (type, 8, "DM");
-  tdesc_add_flag (type, 9, "ZM");
-  tdesc_add_flag (type, 10, "OM");
-  tdesc_add_flag (type, 11, "UM");
-  tdesc_add_flag (type, 12, "PM");
-  tdesc_add_flag (type, 15, "FZ");
-
-  tdesc_create_reg (feature, "xmm0", 32, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm1", 33, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm2", 34, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm3", 35, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm4", 36, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm5", 37, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm6", 38, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm7", 39, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "mxcsr", 40, 1, "vector", 32, "i386_mxcsr");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
-  tdesc_create_reg (feature, "orig_eax", 41, 1, NULL, 32, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx");
-  tdesc_create_reg (feature, "ymm0h", 42, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm1h", 43, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm2h", 44, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm3h", 45, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm4h", 46, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm5h", 47, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm6h", 48, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm7h", 49, 1, NULL, 128, "uint128");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.mpx");
-  type = tdesc_create_struct (feature, "br128");
-  field_type = tdesc_named_type (feature, "uint64");
-  tdesc_add_field (type, "lbound", field_type);
-  field_type = tdesc_named_type (feature, "uint64");
-  tdesc_add_field (type, "ubound_raw", field_type);
-
-  type = tdesc_create_struct (feature, "_bndstatus");
-  tdesc_set_struct_size (type, 8);
-  tdesc_add_bitfield (type, "bde", 2, 31);
-  tdesc_add_bitfield (type, "error", 0, 1);
-
-  type = tdesc_create_union (feature, "status");
-  field_type = tdesc_named_type (feature, "data_ptr");
-  tdesc_add_field (type, "raw", field_type);
-  field_type = tdesc_named_type (feature, "_bndstatus");
-  tdesc_add_field (type, "status", field_type);
-
-  type = tdesc_create_struct (feature, "_bndcfgu");
-  tdesc_set_struct_size (type, 8);
-  tdesc_add_bitfield (type, "base", 12, 31);
-  tdesc_add_bitfield (type, "reserved", 2, 11);
-  tdesc_add_bitfield (type, "preserved", 1, 1);
-  tdesc_add_bitfield (type, "enabled", 0, 0);
-
-  type = tdesc_create_union (feature, "cfgu");
-  field_type = tdesc_named_type (feature, "data_ptr");
-  tdesc_add_field (type, "raw", field_type);
-  field_type = tdesc_named_type (feature, "_bndcfgu");
-  tdesc_add_field (type, "config", field_type);
-
-  tdesc_create_reg (feature, "bnd0raw", 50, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd1raw", 51, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd2raw", 52, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd3raw", 53, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bndcfgu", 54, 1, NULL, 64, "cfgu");
-  tdesc_create_reg (feature, "bndstatus", 55, 1, NULL, 64, "status");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx512");
-  field_type = tdesc_named_type (feature, "uint128");
-  tdesc_create_vector (feature, "v2ui128", field_type, 2);
-
-  tdesc_create_reg (feature, "k0", 56, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k1", 57, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k2", 58, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k3", 59, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k4", 60, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k5", 61, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k6", 62, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k7", 63, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "zmm0h", 64, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm1h", 65, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm2h", 66, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm3h", 67, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm4h", 68, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm5h", 69, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm6h", 70, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm7h", 71, 1, NULL, 256, "v2ui128");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.pkeys");
-  tdesc_create_reg (feature, "pkru", 72, 1, NULL, 32, "uint32");
-
-  tdesc_i386_avx_mpx_avx512_pku_linux = result;
-}
diff --git a/gdb/features/i386/i386-avx-mpx-linux.c b/gdb/features/i386/i386-avx-mpx-linux.c
deleted file mode 100644
index f62c487..0000000
--- a/gdb/features/i386/i386-avx-mpx-linux.c
+++ /dev/null
@@ -1,187 +0,0 @@
-/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
-  Original: i386-avx-mpx-linux.xml */
-
-#include "defs.h"
-#include "osabi.h"
-#include "target-descriptions.h"
-
-struct target_desc *tdesc_i386_avx_mpx_linux;
-static void
-initialize_tdesc_i386_avx_mpx_linux (void)
-{
-  struct target_desc *result = allocate_target_description ();
-  set_tdesc_architecture (result, bfd_scan_arch ("i386"));
-
-  set_tdesc_osabi (result, osabi_from_tdesc_string ("GNU/Linux"));
-
-  struct tdesc_feature *feature;
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-  type = tdesc_create_flags (feature, "i386_eflags", 4);
-  tdesc_add_flag (type, 0, "CF");
-  tdesc_add_flag (type, 1, "");
-  tdesc_add_flag (type, 2, "PF");
-  tdesc_add_flag (type, 4, "AF");
-  tdesc_add_flag (type, 6, "ZF");
-  tdesc_add_flag (type, 7, "SF");
-  tdesc_add_flag (type, 8, "TF");
-  tdesc_add_flag (type, 9, "IF");
-  tdesc_add_flag (type, 10, "DF");
-  tdesc_add_flag (type, 11, "OF");
-  tdesc_add_flag (type, 14, "NT");
-  tdesc_add_flag (type, 16, "RF");
-  tdesc_add_flag (type, 17, "VM");
-  tdesc_add_flag (type, 18, "AC");
-  tdesc_add_flag (type, 19, "VIF");
-  tdesc_add_flag (type, 20, "VIP");
-  tdesc_add_flag (type, 21, "ID");
-
-  tdesc_create_reg (feature, "eax", 0, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ecx", 1, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "edx", 2, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ebx", 3, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "esp", 4, 1, NULL, 32, "data_ptr");
-  tdesc_create_reg (feature, "ebp", 5, 1, NULL, 32, "data_ptr");
-  tdesc_create_reg (feature, "esi", 6, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "edi", 7, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "eip", 8, 1, NULL, 32, "code_ptr");
-  tdesc_create_reg (feature, "eflags", 9, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 10, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 11, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 12, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 13, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 14, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 15, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "st0", 16, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st1", 17, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st2", 18, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st3", 19, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st4", 20, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st5", 21, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st6", 22, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st7", 23, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "fctrl", 24, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fstat", 25, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "ftag", 26, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fiseg", 27, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fioff", 28, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "foseg", 29, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fooff", 30, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fop", 31, 1, "float", 32, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.sse");
-  field_type = tdesc_named_type (feature, "ieee_single");
-  tdesc_create_vector (feature, "v4f", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "ieee_double");
-  tdesc_create_vector (feature, "v2d", field_type, 2);
-
-  field_type = tdesc_named_type (feature, "int8");
-  tdesc_create_vector (feature, "v16i8", field_type, 16);
-
-  field_type = tdesc_named_type (feature, "int16");
-  tdesc_create_vector (feature, "v8i16", field_type, 8);
-
-  field_type = tdesc_named_type (feature, "int32");
-  tdesc_create_vector (feature, "v4i32", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "int64");
-  tdesc_create_vector (feature, "v2i64", field_type, 2);
-
-  type = tdesc_create_union (feature, "vec128");
-  field_type = tdesc_named_type (feature, "v4f");
-  tdesc_add_field (type, "v4_float", field_type);
-  field_type = tdesc_named_type (feature, "v2d");
-  tdesc_add_field (type, "v2_double", field_type);
-  field_type = tdesc_named_type (feature, "v16i8");
-  tdesc_add_field (type, "v16_int8", field_type);
-  field_type = tdesc_named_type (feature, "v8i16");
-  tdesc_add_field (type, "v8_int16", field_type);
-  field_type = tdesc_named_type (feature, "v4i32");
-  tdesc_add_field (type, "v4_int32", field_type);
-  field_type = tdesc_named_type (feature, "v2i64");
-  tdesc_add_field (type, "v2_int64", field_type);
-  field_type = tdesc_named_type (feature, "uint128");
-  tdesc_add_field (type, "uint128", field_type);
-
-  type = tdesc_create_flags (feature, "i386_mxcsr", 4);
-  tdesc_add_flag (type, 0, "IE");
-  tdesc_add_flag (type, 1, "DE");
-  tdesc_add_flag (type, 2, "ZE");
-  tdesc_add_flag (type, 3, "OE");
-  tdesc_add_flag (type, 4, "UE");
-  tdesc_add_flag (type, 5, "PE");
-  tdesc_add_flag (type, 6, "DAZ");
-  tdesc_add_flag (type, 7, "IM");
-  tdesc_add_flag (type, 8, "DM");
-  tdesc_add_flag (type, 9, "ZM");
-  tdesc_add_flag (type, 10, "OM");
-  tdesc_add_flag (type, 11, "UM");
-  tdesc_add_flag (type, 12, "PM");
-  tdesc_add_flag (type, 15, "FZ");
-
-  tdesc_create_reg (feature, "xmm0", 32, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm1", 33, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm2", 34, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm3", 35, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm4", 36, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm5", 37, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm6", 38, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm7", 39, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "mxcsr", 40, 1, "vector", 32, "i386_mxcsr");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
-  tdesc_create_reg (feature, "orig_eax", 41, 1, NULL, 32, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx");
-  tdesc_create_reg (feature, "ymm0h", 42, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm1h", 43, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm2h", 44, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm3h", 45, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm4h", 46, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm5h", 47, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm6h", 48, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm7h", 49, 1, NULL, 128, "uint128");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.mpx");
-  type = tdesc_create_struct (feature, "br128");
-  field_type = tdesc_named_type (feature, "uint64");
-  tdesc_add_field (type, "lbound", field_type);
-  field_type = tdesc_named_type (feature, "uint64");
-  tdesc_add_field (type, "ubound_raw", field_type);
-
-  type = tdesc_create_struct (feature, "_bndstatus");
-  tdesc_set_struct_size (type, 8);
-  tdesc_add_bitfield (type, "bde", 2, 31);
-  tdesc_add_bitfield (type, "error", 0, 1);
-
-  type = tdesc_create_union (feature, "status");
-  field_type = tdesc_named_type (feature, "data_ptr");
-  tdesc_add_field (type, "raw", field_type);
-  field_type = tdesc_named_type (feature, "_bndstatus");
-  tdesc_add_field (type, "status", field_type);
-
-  type = tdesc_create_struct (feature, "_bndcfgu");
-  tdesc_set_struct_size (type, 8);
-  tdesc_add_bitfield (type, "base", 12, 31);
-  tdesc_add_bitfield (type, "reserved", 2, 11);
-  tdesc_add_bitfield (type, "preserved", 1, 1);
-  tdesc_add_bitfield (type, "enabled", 0, 0);
-
-  type = tdesc_create_union (feature, "cfgu");
-  field_type = tdesc_named_type (feature, "data_ptr");
-  tdesc_add_field (type, "raw", field_type);
-  field_type = tdesc_named_type (feature, "_bndcfgu");
-  tdesc_add_field (type, "config", field_type);
-
-  tdesc_create_reg (feature, "bnd0raw", 50, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd1raw", 51, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd2raw", 52, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd3raw", 53, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bndcfgu", 54, 1, NULL, 64, "cfgu");
-  tdesc_create_reg (feature, "bndstatus", 55, 1, NULL, 64, "status");
-
-  tdesc_i386_avx_mpx_linux = result;
-}
diff --git a/gdb/features/i386/i386-linux.c b/gdb/features/i386/i386-linux.c
deleted file mode 100644
index 0394842..0000000
--- a/gdb/features/i386/i386-linux.c
+++ /dev/null
@@ -1,139 +0,0 @@
-/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
-  Original: i386-linux.xml */
-
-#include "defs.h"
-#include "osabi.h"
-#include "target-descriptions.h"
-
-struct target_desc *tdesc_i386_linux;
-static void
-initialize_tdesc_i386_linux (void)
-{
-  struct target_desc *result = allocate_target_description ();
-  set_tdesc_architecture (result, bfd_scan_arch ("i386"));
-
-  set_tdesc_osabi (result, osabi_from_tdesc_string ("GNU/Linux"));
-
-  struct tdesc_feature *feature;
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-  type = tdesc_create_flags (feature, "i386_eflags", 4);
-  tdesc_add_flag (type, 0, "CF");
-  tdesc_add_flag (type, 1, "");
-  tdesc_add_flag (type, 2, "PF");
-  tdesc_add_flag (type, 4, "AF");
-  tdesc_add_flag (type, 6, "ZF");
-  tdesc_add_flag (type, 7, "SF");
-  tdesc_add_flag (type, 8, "TF");
-  tdesc_add_flag (type, 9, "IF");
-  tdesc_add_flag (type, 10, "DF");
-  tdesc_add_flag (type, 11, "OF");
-  tdesc_add_flag (type, 14, "NT");
-  tdesc_add_flag (type, 16, "RF");
-  tdesc_add_flag (type, 17, "VM");
-  tdesc_add_flag (type, 18, "AC");
-  tdesc_add_flag (type, 19, "VIF");
-  tdesc_add_flag (type, 20, "VIP");
-  tdesc_add_flag (type, 21, "ID");
-
-  tdesc_create_reg (feature, "eax", 0, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ecx", 1, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "edx", 2, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ebx", 3, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "esp", 4, 1, NULL, 32, "data_ptr");
-  tdesc_create_reg (feature, "ebp", 5, 1, NULL, 32, "data_ptr");
-  tdesc_create_reg (feature, "esi", 6, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "edi", 7, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "eip", 8, 1, NULL, 32, "code_ptr");
-  tdesc_create_reg (feature, "eflags", 9, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 10, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 11, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 12, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 13, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 14, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 15, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "st0", 16, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st1", 17, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st2", 18, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st3", 19, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st4", 20, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st5", 21, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st6", 22, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st7", 23, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "fctrl", 24, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fstat", 25, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "ftag", 26, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fiseg", 27, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fioff", 28, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "foseg", 29, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fooff", 30, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fop", 31, 1, "float", 32, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.sse");
-  field_type = tdesc_named_type (feature, "ieee_single");
-  tdesc_create_vector (feature, "v4f", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "ieee_double");
-  tdesc_create_vector (feature, "v2d", field_type, 2);
-
-  field_type = tdesc_named_type (feature, "int8");
-  tdesc_create_vector (feature, "v16i8", field_type, 16);
-
-  field_type = tdesc_named_type (feature, "int16");
-  tdesc_create_vector (feature, "v8i16", field_type, 8);
-
-  field_type = tdesc_named_type (feature, "int32");
-  tdesc_create_vector (feature, "v4i32", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "int64");
-  tdesc_create_vector (feature, "v2i64", field_type, 2);
-
-  type = tdesc_create_union (feature, "vec128");
-  field_type = tdesc_named_type (feature, "v4f");
-  tdesc_add_field (type, "v4_float", field_type);
-  field_type = tdesc_named_type (feature, "v2d");
-  tdesc_add_field (type, "v2_double", field_type);
-  field_type = tdesc_named_type (feature, "v16i8");
-  tdesc_add_field (type, "v16_int8", field_type);
-  field_type = tdesc_named_type (feature, "v8i16");
-  tdesc_add_field (type, "v8_int16", field_type);
-  field_type = tdesc_named_type (feature, "v4i32");
-  tdesc_add_field (type, "v4_int32", field_type);
-  field_type = tdesc_named_type (feature, "v2i64");
-  tdesc_add_field (type, "v2_int64", field_type);
-  field_type = tdesc_named_type (feature, "uint128");
-  tdesc_add_field (type, "uint128", field_type);
-
-  type = tdesc_create_flags (feature, "i386_mxcsr", 4);
-  tdesc_add_flag (type, 0, "IE");
-  tdesc_add_flag (type, 1, "DE");
-  tdesc_add_flag (type, 2, "ZE");
-  tdesc_add_flag (type, 3, "OE");
-  tdesc_add_flag (type, 4, "UE");
-  tdesc_add_flag (type, 5, "PE");
-  tdesc_add_flag (type, 6, "DAZ");
-  tdesc_add_flag (type, 7, "IM");
-  tdesc_add_flag (type, 8, "DM");
-  tdesc_add_flag (type, 9, "ZM");
-  tdesc_add_flag (type, 10, "OM");
-  tdesc_add_flag (type, 11, "UM");
-  tdesc_add_flag (type, 12, "PM");
-  tdesc_add_flag (type, 15, "FZ");
-
-  tdesc_create_reg (feature, "xmm0", 32, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm1", 33, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm2", 34, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm3", 35, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm4", 36, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm5", 37, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm6", 38, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm7", 39, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "mxcsr", 40, 1, "vector", 32, "i386_mxcsr");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
-  tdesc_create_reg (feature, "orig_eax", 41, 1, NULL, 32, "int");
-
-  tdesc_i386_linux = result;
-}
diff --git a/gdb/features/i386/i386-mmx-linux.c b/gdb/features/i386/i386-mmx-linux.c
deleted file mode 100644
index 1577972..0000000
--- a/gdb/features/i386/i386-mmx-linux.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
-  Original: i386-mmx-linux.xml */
-
-#include "defs.h"
-#include "osabi.h"
-#include "target-descriptions.h"
-
-struct target_desc *tdesc_i386_mmx_linux;
-static void
-initialize_tdesc_i386_mmx_linux (void)
-{
-  struct target_desc *result = allocate_target_description ();
-  set_tdesc_architecture (result, bfd_scan_arch ("i386"));
-
-  set_tdesc_osabi (result, osabi_from_tdesc_string ("GNU/Linux"));
-
-  struct tdesc_feature *feature;
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-  type = tdesc_create_flags (feature, "i386_eflags", 4);
-  tdesc_add_flag (type, 0, "CF");
-  tdesc_add_flag (type, 1, "");
-  tdesc_add_flag (type, 2, "PF");
-  tdesc_add_flag (type, 4, "AF");
-  tdesc_add_flag (type, 6, "ZF");
-  tdesc_add_flag (type, 7, "SF");
-  tdesc_add_flag (type, 8, "TF");
-  tdesc_add_flag (type, 9, "IF");
-  tdesc_add_flag (type, 10, "DF");
-  tdesc_add_flag (type, 11, "OF");
-  tdesc_add_flag (type, 14, "NT");
-  tdesc_add_flag (type, 16, "RF");
-  tdesc_add_flag (type, 17, "VM");
-  tdesc_add_flag (type, 18, "AC");
-  tdesc_add_flag (type, 19, "VIF");
-  tdesc_add_flag (type, 20, "VIP");
-  tdesc_add_flag (type, 21, "ID");
-
-  tdesc_create_reg (feature, "eax", 0, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ecx", 1, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "edx", 2, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ebx", 3, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "esp", 4, 1, NULL, 32, "data_ptr");
-  tdesc_create_reg (feature, "ebp", 5, 1, NULL, 32, "data_ptr");
-  tdesc_create_reg (feature, "esi", 6, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "edi", 7, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "eip", 8, 1, NULL, 32, "code_ptr");
-  tdesc_create_reg (feature, "eflags", 9, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 10, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 11, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 12, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 13, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 14, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 15, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "st0", 16, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st1", 17, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st2", 18, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st3", 19, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st4", 20, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st5", 21, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st6", 22, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st7", 23, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "fctrl", 24, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fstat", 25, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "ftag", 26, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fiseg", 27, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fioff", 28, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "foseg", 29, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fooff", 30, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fop", 31, 1, "float", 32, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
-  tdesc_create_reg (feature, "orig_eax", 41, 1, NULL, 32, "int");
-
-  tdesc_i386_mmx_linux = result;
-}
diff --git a/gdb/features/i386/i386-mpx-linux.c b/gdb/features/i386/i386-mpx-linux.c
deleted file mode 100644
index 6dea8e0..0000000
--- a/gdb/features/i386/i386-mpx-linux.c
+++ /dev/null
@@ -1,177 +0,0 @@
-/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
-  Original: i386-mpx-linux.xml */
-
-#include "defs.h"
-#include "osabi.h"
-#include "target-descriptions.h"
-
-struct target_desc *tdesc_i386_mpx_linux;
-static void
-initialize_tdesc_i386_mpx_linux (void)
-{
-  struct target_desc *result = allocate_target_description ();
-  set_tdesc_architecture (result, bfd_scan_arch ("i386"));
-
-  set_tdesc_osabi (result, osabi_from_tdesc_string ("GNU/Linux"));
-
-  struct tdesc_feature *feature;
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-  type = tdesc_create_flags (feature, "i386_eflags", 4);
-  tdesc_add_flag (type, 0, "CF");
-  tdesc_add_flag (type, 1, "");
-  tdesc_add_flag (type, 2, "PF");
-  tdesc_add_flag (type, 4, "AF");
-  tdesc_add_flag (type, 6, "ZF");
-  tdesc_add_flag (type, 7, "SF");
-  tdesc_add_flag (type, 8, "TF");
-  tdesc_add_flag (type, 9, "IF");
-  tdesc_add_flag (type, 10, "DF");
-  tdesc_add_flag (type, 11, "OF");
-  tdesc_add_flag (type, 14, "NT");
-  tdesc_add_flag (type, 16, "RF");
-  tdesc_add_flag (type, 17, "VM");
-  tdesc_add_flag (type, 18, "AC");
-  tdesc_add_flag (type, 19, "VIF");
-  tdesc_add_flag (type, 20, "VIP");
-  tdesc_add_flag (type, 21, "ID");
-
-  tdesc_create_reg (feature, "eax", 0, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ecx", 1, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "edx", 2, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ebx", 3, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "esp", 4, 1, NULL, 32, "data_ptr");
-  tdesc_create_reg (feature, "ebp", 5, 1, NULL, 32, "data_ptr");
-  tdesc_create_reg (feature, "esi", 6, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "edi", 7, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "eip", 8, 1, NULL, 32, "code_ptr");
-  tdesc_create_reg (feature, "eflags", 9, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 10, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 11, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 12, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 13, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 14, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 15, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "st0", 16, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st1", 17, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st2", 18, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st3", 19, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st4", 20, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st5", 21, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st6", 22, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st7", 23, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "fctrl", 24, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fstat", 25, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "ftag", 26, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fiseg", 27, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fioff", 28, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "foseg", 29, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fooff", 30, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fop", 31, 1, "float", 32, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.sse");
-  field_type = tdesc_named_type (feature, "ieee_single");
-  tdesc_create_vector (feature, "v4f", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "ieee_double");
-  tdesc_create_vector (feature, "v2d", field_type, 2);
-
-  field_type = tdesc_named_type (feature, "int8");
-  tdesc_create_vector (feature, "v16i8", field_type, 16);
-
-  field_type = tdesc_named_type (feature, "int16");
-  tdesc_create_vector (feature, "v8i16", field_type, 8);
-
-  field_type = tdesc_named_type (feature, "int32");
-  tdesc_create_vector (feature, "v4i32", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "int64");
-  tdesc_create_vector (feature, "v2i64", field_type, 2);
-
-  type = tdesc_create_union (feature, "vec128");
-  field_type = tdesc_named_type (feature, "v4f");
-  tdesc_add_field (type, "v4_float", field_type);
-  field_type = tdesc_named_type (feature, "v2d");
-  tdesc_add_field (type, "v2_double", field_type);
-  field_type = tdesc_named_type (feature, "v16i8");
-  tdesc_add_field (type, "v16_int8", field_type);
-  field_type = tdesc_named_type (feature, "v8i16");
-  tdesc_add_field (type, "v8_int16", field_type);
-  field_type = tdesc_named_type (feature, "v4i32");
-  tdesc_add_field (type, "v4_int32", field_type);
-  field_type = tdesc_named_type (feature, "v2i64");
-  tdesc_add_field (type, "v2_int64", field_type);
-  field_type = tdesc_named_type (feature, "uint128");
-  tdesc_add_field (type, "uint128", field_type);
-
-  type = tdesc_create_flags (feature, "i386_mxcsr", 4);
-  tdesc_add_flag (type, 0, "IE");
-  tdesc_add_flag (type, 1, "DE");
-  tdesc_add_flag (type, 2, "ZE");
-  tdesc_add_flag (type, 3, "OE");
-  tdesc_add_flag (type, 4, "UE");
-  tdesc_add_flag (type, 5, "PE");
-  tdesc_add_flag (type, 6, "DAZ");
-  tdesc_add_flag (type, 7, "IM");
-  tdesc_add_flag (type, 8, "DM");
-  tdesc_add_flag (type, 9, "ZM");
-  tdesc_add_flag (type, 10, "OM");
-  tdesc_add_flag (type, 11, "UM");
-  tdesc_add_flag (type, 12, "PM");
-  tdesc_add_flag (type, 15, "FZ");
-
-  tdesc_create_reg (feature, "xmm0", 32, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm1", 33, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm2", 34, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm3", 35, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm4", 36, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm5", 37, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm6", 38, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm7", 39, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "mxcsr", 40, 1, "vector", 32, "i386_mxcsr");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
-  tdesc_create_reg (feature, "orig_eax", 41, 1, NULL, 32, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.mpx");
-  type = tdesc_create_struct (feature, "br128");
-  field_type = tdesc_named_type (feature, "uint64");
-  tdesc_add_field (type, "lbound", field_type);
-  field_type = tdesc_named_type (feature, "uint64");
-  tdesc_add_field (type, "ubound_raw", field_type);
-
-  type = tdesc_create_struct (feature, "_bndstatus");
-  tdesc_set_struct_size (type, 8);
-  tdesc_add_bitfield (type, "bde", 2, 31);
-  tdesc_add_bitfield (type, "error", 0, 1);
-
-  type = tdesc_create_union (feature, "status");
-  field_type = tdesc_named_type (feature, "data_ptr");
-  tdesc_add_field (type, "raw", field_type);
-  field_type = tdesc_named_type (feature, "_bndstatus");
-  tdesc_add_field (type, "status", field_type);
-
-  type = tdesc_create_struct (feature, "_bndcfgu");
-  tdesc_set_struct_size (type, 8);
-  tdesc_add_bitfield (type, "base", 12, 31);
-  tdesc_add_bitfield (type, "reserved", 2, 11);
-  tdesc_add_bitfield (type, "preserved", 1, 1);
-  tdesc_add_bitfield (type, "enabled", 0, 0);
-
-  type = tdesc_create_union (feature, "cfgu");
-  field_type = tdesc_named_type (feature, "data_ptr");
-  tdesc_add_field (type, "raw", field_type);
-  field_type = tdesc_named_type (feature, "_bndcfgu");
-  tdesc_add_field (type, "config", field_type);
-
-  tdesc_create_reg (feature, "bnd0raw", 42, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd1raw", 43, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd2raw", 44, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd3raw", 45, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bndcfgu", 46, 1, NULL, 64, "cfgu");
-  tdesc_create_reg (feature, "bndstatus", 47, 1, NULL, 64, "status");
-
-  tdesc_i386_mpx_linux = result;
-}
-- 
1.9.1

^ permalink raw reply	[flat|nested] 82+ messages in thread

* [PATCH 20/25] Centralize amd64-linux target descriptions
  2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
                   ` (10 preceding siblings ...)
  2017-06-12  8:42 ` [PATCH 15/25] [RFC] GDBserver unit test to i386_tdesc Yao Qi
@ 2017-06-12  8:42 ` Yao Qi
  2017-06-12  8:42 ` [PATCH 02/25] Adjust the order of 32bit-linux.xml and 32bit-sse.xml in i386/i386-linux.xml Yao Qi
                   ` (14 subsequent siblings)
  26 siblings, 0 replies; 82+ messages in thread
From: Yao Qi @ 2017-06-12  8:42 UTC (permalink / raw)
  To: gdb-patches

This patch adds a new function amd64_linux_read_description, which
creates amd64-linux target descriptions according to its two
arguments, xcr0 and is_x32.

gdb:

2017-06-07  Yao Qi  <yao.qi@linaro.org>

	* amd64-linux-tdep.c (amd64_linux_read_description): New
	function.
	(amd64_linux_core_read_description): Call
	amd64_linux_read_description.
	(amd64_linux_init_abi): Likewise.
	(amd64_x32_linux_init_abi): Likewise.
	* amd64-linux-tdep.h (amd64_linux_read_description): Declare.
	* x86-linux-nat.c (x86_linux_read_description): Call
	amd64_linux_read_description.
---
 gdb/amd64-linux-tdep.c | 51 +++++++++++++++++++++++++++-----------------------
 gdb/amd64-linux-tdep.h |  6 ++++++
 gdb/x86-linux-nat.c    | 35 +---------------------------------
 3 files changed, 35 insertions(+), 57 deletions(-)

diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
index 0e2f285..b9f624d 100644
--- a/gdb/amd64-linux-tdep.c
+++ b/gdb/amd64-linux-tdep.c
@@ -1575,54 +1575,59 @@ amd64_linux_record_signal (struct gdbarch *gdbarch,
   return 0;
 }
 
-/* Get Linux/x86 target description from core dump.  */
-
-static const struct target_desc *
-amd64_linux_core_read_description (struct gdbarch *gdbarch,
-				  struct target_ops *target,
-				  bfd *abfd)
+const target_desc *
+amd64_linux_read_description (uint64_t xcr0_features_bit, bool is_x32)
 {
-  /* Linux/x86-64.  */
-  uint64_t xcr0 = i386_linux_core_read_xcr0 (abfd);
-
-  switch (xcr0 & X86_XSTATE_ALL_MASK)
+  switch (xcr0_features_bit)
     {
     case X86_XSTATE_AVX_MPX_AVX512_PKU_MASK:
-      if (gdbarch_ptr_bit (gdbarch) == 32)
-	  /* No MPX on x32, fallback to AVX-AVX512.  */
+      if (is_x32)
+	/* No MPX, PKU on x32, fall back to AVX-AVX512.  */
 	return tdesc_x32_avx_avx512_linux;
       else
 	return tdesc_amd64_avx_mpx_avx512_pku_linux;
     case X86_XSTATE_AVX_AVX512_MASK:
-      if (gdbarch_ptr_bit (gdbarch) == 32)
+      if (is_x32)
 	return tdesc_x32_avx_avx512_linux;
       else
 	return tdesc_amd64_avx_avx512_linux;
     case X86_XSTATE_MPX_MASK:
-      if (gdbarch_ptr_bit (gdbarch) == 32)
-	  /* No MPX on x32, fallback to AVX-AVX512.  */
-	return tdesc_x32_avx_linux;
+      if (is_x32)
+	return tdesc_x32_avx_linux; /* No MPX on x32 using AVX.  */
       else
 	return tdesc_amd64_mpx_linux;
     case X86_XSTATE_AVX_MPX_MASK:
-      if (gdbarch_ptr_bit (gdbarch) == 32)
-	  /* No MPX on x32, fallback to AVX-AVX512.  */
-	return tdesc_x32_avx_linux;
+      if (is_x32)
+	return tdesc_x32_avx_linux; /* No MPX on x32 using AVX.  */
       else
 	return tdesc_amd64_avx_mpx_linux;
     case X86_XSTATE_AVX_MASK:
-      if (gdbarch_ptr_bit (gdbarch) == 32)
+      if (is_x32)
 	return tdesc_x32_avx_linux;
       else
 	return tdesc_amd64_avx_linux;
     default:
-      if (gdbarch_ptr_bit (gdbarch) == 32)
+      if (is_x32)
 	return tdesc_x32_linux;
       else
 	return tdesc_amd64_linux;
     }
 }
 
+/* Get Linux/x86 target description from core dump.  */
+
+static const struct target_desc *
+amd64_linux_core_read_description (struct gdbarch *gdbarch,
+				  struct target_ops *target,
+				  bfd *abfd)
+{
+  /* Linux/x86-64.  */
+  uint64_t xcr0 = i386_linux_core_read_xcr0 (abfd);
+
+  return amd64_linux_read_description (xcr0 & X86_XSTATE_ALL_MASK,
+				       gdbarch_ptr_bit (gdbarch) == 32);
+}
+
 /* Similar to amd64_supply_fpregset, but use XSAVE extended state.  */
 
 static void
@@ -1883,7 +1888,7 @@ amd64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   set_gdbarch_num_regs (gdbarch, AMD64_LINUX_NUM_REGS);
 
   if (! tdesc_has_registers (tdesc))
-    tdesc = tdesc_amd64_linux;
+    tdesc = amd64_linux_read_description (X86_XSTATE_SSE_MASK, false);
   tdep->tdesc = tdesc;
 
   feature = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.linux");
@@ -2100,7 +2105,7 @@ amd64_x32_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   set_gdbarch_num_regs (gdbarch, AMD64_LINUX_NUM_REGS);
 
   if (! tdesc_has_registers (tdesc))
-    tdesc = tdesc_x32_linux;
+    tdesc = amd64_linux_read_description (X86_XSTATE_SSE_MASK, true);
   tdep->tdesc = tdesc;
 
   feature = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.linux");
diff --git a/gdb/amd64-linux-tdep.h b/gdb/amd64-linux-tdep.h
index 7453408..ab134a4 100644
--- a/gdb/amd64-linux-tdep.h
+++ b/gdb/amd64-linux-tdep.h
@@ -43,6 +43,12 @@ extern struct target_desc *tdesc_x32_linux;
 extern struct target_desc *tdesc_x32_avx_linux;
 extern struct target_desc *tdesc_x32_avx_avx512_linux;
 
+/* Return the right amd64-linux target descriptions according to
+   XCR0_FEATURES_BIT and IS_X32.  */
+
+const target_desc *amd64_linux_read_description (uint64_t xcr0_features_bit,
+						 bool is_x32);
+
 /* Enum that defines the syscall identifiers for amd64 linux.
    Used for process record/replay, these will be translated into
    a gdb-canonical set of syscall ids in linux-record.c.  */
diff --git a/gdb/x86-linux-nat.c b/gdb/x86-linux-nat.c
index 2c4afb1..4611527 100644
--- a/gdb/x86-linux-nat.c
+++ b/gdb/x86-linux-nat.c
@@ -192,40 +192,7 @@ x86_linux_read_description (struct target_ops *ops)
   if (is_64bit)
     {
 #ifdef __x86_64__
-      switch (xcr0_features_bits)
-	{
-	case X86_XSTATE_AVX_MPX_AVX512_PKU_MASK:
-	  if (is_x32)
-	    /* No MPX, PKU on x32, fall back to AVX-AVX512.  */
-	    return tdesc_x32_avx_avx512_linux;
-	  else
-	    return tdesc_amd64_avx_mpx_avx512_pku_linux;
-	case X86_XSTATE_AVX_AVX512_MASK:
-	  if (is_x32)
-	    return tdesc_x32_avx_avx512_linux;
-	  else
-	    return tdesc_amd64_avx_avx512_linux;
-	case X86_XSTATE_MPX_MASK:
-	  if (is_x32)
-	    return tdesc_x32_avx_linux; /* No MPX on x32 using AVX.  */
-	  else
-	    return tdesc_amd64_mpx_linux;
-	case X86_XSTATE_AVX_MPX_MASK:
-	  if (is_x32)
-	    return tdesc_x32_avx_linux; /* No MPX on x32 using AVX.  */
-	  else
-	    return tdesc_amd64_avx_mpx_linux;
-	case X86_XSTATE_AVX_MASK:
-	  if (is_x32)
-	    return tdesc_x32_avx_linux;
-	  else
-	    return tdesc_amd64_avx_linux;
-	default:
-	  if (is_x32)
-	    return tdesc_x32_linux;
-	  else
-	    return tdesc_amd64_linux;
-	}
+      return amd64_linux_read_description (xcr0_features_bits, is_x32);
 #endif
     }
   else
-- 
1.9.1

^ permalink raw reply	[flat|nested] 82+ messages in thread

* [PATCH 06/25] Generate c for feature instead of tdesc
  2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
  2017-06-12  8:42 ` [PATCH 04/25] Centralize i386 linux target descriptions Yao Qi
@ 2017-06-12  8:42 ` Yao Qi
  2017-06-12 14:48   ` Eli Zaretskii
                     ` (2 more replies)
  2017-06-12  8:42 ` [PATCH 18/25] [GDBserver] Use pre-generated tdesc as test Yao Qi
                   ` (24 subsequent siblings)
  26 siblings, 3 replies; 82+ messages in thread
From: Yao Qi @ 2017-06-12  8:42 UTC (permalink / raw)
  To: gdb-patches

This patch changes Makefile and command "maint print c-files" so
that GDB can print c files for features instead target description.
Previously, we feed GDB a target description xml file, which generate
c files including multiple features.

With this patch, in Makefile, we wrap each feature xml file, and
create a temp target description which include only one feature.
Then, adjust the target description printer for them, and print
a c function for each given feature, so that we can use these
c functions later to create target description in a flexible way.

Before GDB prints c-tdesc, we need to set tdesc.  However, this involves
some validations in each gdbarch on these target descriptions, and this
make troubles to generate c file for each target feature when we feed GDB
a target description only including an optional feature (without some
mandatory feature), GDB just reject it, and don't print the c file.

What we need here is to translate xml file to object target_desc, and
translate the object target_desc to c file.  We don't have to involve
gdbarch validation in this process at all, so I modify command
"maint print c-tdesc" to have an optional argument which is the filename
of xml target description.  If the file name is provided, parse the
xml target description, create target_desc object, and print c file from
it.

gdb:

2017-05-22  Yao Qi  <yao.qi@linaro.org>

	* features/Makefile (FEATURE_XMLFILES): New.
	(FEATURE_CFILES): New.
	New rules.
	* features/i386/32bit-avx.c: Generated.
 	* features/i386/32bit-avx512.c: Generated.
 	* features/i386/32bit-core.c: Generated.
 	* features/i386/32bit-linux.c: Generated.
 	* features/i386/32bit-mpx.c: Generated.
 	* features/i386/32bit-pkeys.c: Generated.
 	* features/i386/32bit-sse.c: Generated.
 	* target-descriptions.c: Include algorithm.
	(tdesc_element_visitor): Add method visit_end.
	(print_c_tdesc): Implement visit_end.
	(print_c_tdesc:: m_filename_after_features): Move it to
	protected.
	(print_c_feature): New class.
	(maint_print_c_tdesc_cmd): Use print_c_feature if XML file
	name starts with "i386/32bit-".

gdb/doc:

2017-06-08  Yao Qi  <yao.qi@linaro.org>

	* gdb.texinfo (Maintenance Commands): Document optional
	argument of "maint print c-tdesc".
---
 gdb/doc/gdb.texinfo              |  10 ++--
 gdb/features/Makefile            |  31 ++++++++++-
 gdb/features/i386/32bit-avx.c    |  23 ++++++++
 gdb/features/i386/32bit-avx512.c |  35 ++++++++++++
 gdb/features/i386/32bit-core.c   |  68 +++++++++++++++++++++++
 gdb/features/i386/32bit-linux.c  |  16 ++++++
 gdb/features/i386/32bit-mpx.c    |  53 ++++++++++++++++++
 gdb/features/i386/32bit-pkeys.c  |  16 ++++++
 gdb/features/i386/32bit-sse.c    |  76 ++++++++++++++++++++++++++
 gdb/target-descriptions.c        | 114 +++++++++++++++++++++++++++++++++++----
 10 files changed, 425 insertions(+), 17 deletions(-)
 create mode 100644 gdb/features/i386/32bit-avx.c
 create mode 100644 gdb/features/i386/32bit-avx512.c
 create mode 100644 gdb/features/i386/32bit-core.c
 create mode 100644 gdb/features/i386/32bit-linux.c
 create mode 100644 gdb/features/i386/32bit-mpx.c
 create mode 100644 gdb/features/i386/32bit-pkeys.c
 create mode 100644 gdb/features/i386/32bit-sse.c

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 9fb70f6..eb35b43 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -34676,11 +34676,13 @@ checksum.
 Print the entire architecture configuration.  The optional argument
 @var{file} names the file where the output goes.
 
-@kindex maint print c-tdesc
+@kindex maint print c-tdesc @r{[}@var{file}@r{]}
 @item maint print c-tdesc
-Print the current target description (@pxref{Target Descriptions}) as
-a C source file.  The created source file can be used in @value{GDBN}
-when an XML parser is not available to parse the description.
+Print the target description (@pxref{Target Descriptions}) as
+a C source file.  The target description is got from the optional
+argument @var{file} or the current target description.  The created
+source file can be used in @value{GDBN} when an XML parser is not
+available to parse the description.
 
 @kindex maint print dummy-frames
 @item maint print dummy-frames
diff --git a/gdb/features/Makefile b/gdb/features/Makefile
index 3bc8b5a..28a7e20 100644
--- a/gdb/features/Makefile
+++ b/gdb/features/Makefile
@@ -252,12 +252,39 @@ $(outdir)/%.dat: %.xml number-regs.xsl sort-regs.xsl gdbserver-regs.xsl
 	  $(XSLTPROC) gdbserver-regs.xsl - >> $(outdir)/$*.tmp
 	sh ../../move-if-change $(outdir)/$*.tmp $(outdir)/$*.dat
 
-cfiles: $(CFILES)
-%.c: %.xml
+FEATURE_XMLFILES = i386/32bit-core.xml \
+	i386/32bit-sse.xml \
+	i386/32bit-linux.xml \
+	i386/32bit-avx.xml \
+	i386/32bit-mpx.xml \
+	i386/32bit-avx512.xml \
+	i386/32bit-pkeys.xml
+
+FEATURE_CFILES = $(patsubst %.xml,%.c,$(FEATURE_XMLFILES))
+
+cfiles: $(CFILES) $(FEATURE_CFILES)
+
+$(CFILES): %.c: %.xml
 	$(GDB) -nx -q -batch \
 	  -ex "set tdesc filename $<" -ex 'maint print c-tdesc' > $@.tmp
 	sh ../../move-if-change $@.tmp $@
 
+$(FEATURE_CFILES): %.c: %.xml.tmp
+	$(GDB) -nx -q -batch \
+	  -ex 'maint print c-tdesc $<' > $@.tmp
+	sh ../../move-if-change $@.tmp $@
+	rm $<
+
+%.xml.tmp: %.xml
+	echo "<?xml version=\"1.0\"?>" > $@
+	echo "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">" >> $@
+	echo "<target>" >> $@
+	echo "  <architecture>" >> $@
+	if test $(findstring i386/32bit-,$@); then echo "i386" >> $@ ; fi;
+	echo "  </architecture>" >> $@
+	echo "  <xi:include href=\"$(notdir $<)\"/>" >> $@
+	echo "</target>" >> $@
+
 # Other dependencies.
 $(outdir)/arm/arm-with-iwmmxt.dat: arm/arm-core.xml arm/xscale-iwmmxt.xml
 $(outdir)/i386/i386.dat: i386/32bit-core.xml i386/32bit-sse.xml
diff --git a/gdb/features/i386/32bit-avx.c b/gdb/features/i386/32bit-avx.c
new file mode 100644
index 0000000..53a939b
--- /dev/null
+++ b/gdb/features/i386/32bit-avx.c
@@ -0,0 +1,23 @@
+/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
+  Original: 32bit-avx.xml.tmp */
+
+#include "defs.h"
+#include "osabi.h"
+#include "target-descriptions.h"
+
+static int
+create_feature_i386_32bit_avx (struct target_desc *result, long regnum)
+{
+  struct tdesc_feature *feature;
+
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx");
+  tdesc_create_reg (feature, "ymm0h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm1h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm2h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm3h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm4h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm5h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm6h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm7h", regnum++, 1, NULL, 128, "uint128");
+  return regnum;
+}
diff --git a/gdb/features/i386/32bit-avx512.c b/gdb/features/i386/32bit-avx512.c
new file mode 100644
index 0000000..9bbf392
--- /dev/null
+++ b/gdb/features/i386/32bit-avx512.c
@@ -0,0 +1,35 @@
+/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
+  Original: 32bit-avx512.xml.tmp */
+
+#include "defs.h"
+#include "osabi.h"
+#include "target-descriptions.h"
+
+static int
+create_feature_i386_32bit_avx512 (struct target_desc *result, long regnum)
+{
+  struct tdesc_feature *feature;
+
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx512");
+  struct tdesc_type *field_type;
+  field_type = tdesc_named_type (feature, "uint128");
+  tdesc_create_vector (feature, "v2ui128", field_type, 2);
+
+  tdesc_create_reg (feature, "k0", regnum++, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k1", regnum++, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k2", regnum++, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k3", regnum++, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k4", regnum++, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k5", regnum++, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k6", regnum++, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k7", regnum++, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "zmm0h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm1h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm2h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm3h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm4h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm5h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm6h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm7h", regnum++, 1, NULL, 256, "v2ui128");
+  return regnum;
+}
diff --git a/gdb/features/i386/32bit-core.c b/gdb/features/i386/32bit-core.c
new file mode 100644
index 0000000..c5f0fca
--- /dev/null
+++ b/gdb/features/i386/32bit-core.c
@@ -0,0 +1,68 @@
+/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
+  Original: 32bit-core.xml.tmp */
+
+#include "defs.h"
+#include "osabi.h"
+#include "target-descriptions.h"
+
+static int
+create_feature_i386_32bit_core (struct target_desc *result, long regnum)
+{
+  struct tdesc_feature *feature;
+
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
+  type = tdesc_create_flags (feature, "i386_eflags", 4);
+  tdesc_add_flag (type, 0, "CF");
+  tdesc_add_flag (type, 1, "");
+  tdesc_add_flag (type, 2, "PF");
+  tdesc_add_flag (type, 4, "AF");
+  tdesc_add_flag (type, 6, "ZF");
+  tdesc_add_flag (type, 7, "SF");
+  tdesc_add_flag (type, 8, "TF");
+  tdesc_add_flag (type, 9, "IF");
+  tdesc_add_flag (type, 10, "DF");
+  tdesc_add_flag (type, 11, "OF");
+  tdesc_add_flag (type, 14, "NT");
+  tdesc_add_flag (type, 16, "RF");
+  tdesc_add_flag (type, 17, "VM");
+  tdesc_add_flag (type, 18, "AC");
+  tdesc_add_flag (type, 19, "VIF");
+  tdesc_add_flag (type, 20, "VIP");
+  tdesc_add_flag (type, 21, "ID");
+
+  tdesc_create_reg (feature, "eax", regnum++, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "ecx", regnum++, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "edx", regnum++, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "ebx", regnum++, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "esp", regnum++, 1, NULL, 32, "data_ptr");
+  tdesc_create_reg (feature, "ebp", regnum++, 1, NULL, 32, "data_ptr");
+  tdesc_create_reg (feature, "esi", regnum++, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "edi", regnum++, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "eip", regnum++, 1, NULL, 32, "code_ptr");
+  tdesc_create_reg (feature, "eflags", regnum++, 1, NULL, 32, "i386_eflags");
+  tdesc_create_reg (feature, "cs", regnum++, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "ss", regnum++, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "ds", regnum++, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "es", regnum++, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "fs", regnum++, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "gs", regnum++, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "st0", regnum++, 1, NULL, 80, "i387_ext");
+  tdesc_create_reg (feature, "st1", regnum++, 1, NULL, 80, "i387_ext");
+  tdesc_create_reg (feature, "st2", regnum++, 1, NULL, 80, "i387_ext");
+  tdesc_create_reg (feature, "st3", regnum++, 1, NULL, 80, "i387_ext");
+  tdesc_create_reg (feature, "st4", regnum++, 1, NULL, 80, "i387_ext");
+  tdesc_create_reg (feature, "st5", regnum++, 1, NULL, 80, "i387_ext");
+  tdesc_create_reg (feature, "st6", regnum++, 1, NULL, 80, "i387_ext");
+  tdesc_create_reg (feature, "st7", regnum++, 1, NULL, 80, "i387_ext");
+  tdesc_create_reg (feature, "fctrl", regnum++, 1, "float", 32, "int");
+  tdesc_create_reg (feature, "fstat", regnum++, 1, "float", 32, "int");
+  tdesc_create_reg (feature, "ftag", regnum++, 1, "float", 32, "int");
+  tdesc_create_reg (feature, "fiseg", regnum++, 1, "float", 32, "int");
+  tdesc_create_reg (feature, "fioff", regnum++, 1, "float", 32, "int");
+  tdesc_create_reg (feature, "foseg", regnum++, 1, "float", 32, "int");
+  tdesc_create_reg (feature, "fooff", regnum++, 1, "float", 32, "int");
+  tdesc_create_reg (feature, "fop", regnum++, 1, "float", 32, "int");
+  return regnum;
+}
diff --git a/gdb/features/i386/32bit-linux.c b/gdb/features/i386/32bit-linux.c
new file mode 100644
index 0000000..3f7bfe7
--- /dev/null
+++ b/gdb/features/i386/32bit-linux.c
@@ -0,0 +1,16 @@
+/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
+  Original: 32bit-linux.xml.tmp */
+
+#include "defs.h"
+#include "osabi.h"
+#include "target-descriptions.h"
+
+static int
+create_feature_i386_32bit_linux (struct target_desc *result, long regnum)
+{
+  struct tdesc_feature *feature;
+
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
+  tdesc_create_reg (feature, "orig_eax", regnum++, 1, NULL, 32, "int");
+  return regnum;
+}
diff --git a/gdb/features/i386/32bit-mpx.c b/gdb/features/i386/32bit-mpx.c
new file mode 100644
index 0000000..50b627e
--- /dev/null
+++ b/gdb/features/i386/32bit-mpx.c
@@ -0,0 +1,53 @@
+/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
+  Original: 32bit-mpx.xml.tmp */
+
+#include "defs.h"
+#include "osabi.h"
+#include "target-descriptions.h"
+
+static int
+create_feature_i386_32bit_mpx (struct target_desc *result, long regnum)
+{
+  struct tdesc_feature *feature;
+
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.mpx");
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
+  type = tdesc_create_struct (feature, "br128");
+  field_type = tdesc_named_type (feature, "uint64");
+  tdesc_add_field (type, "lbound", field_type);
+  field_type = tdesc_named_type (feature, "uint64");
+  tdesc_add_field (type, "ubound_raw", field_type);
+
+  type = tdesc_create_struct (feature, "_bndstatus");
+  tdesc_set_struct_size (type, 8);
+  tdesc_add_bitfield (type, "bde", 2, 31);
+  tdesc_add_bitfield (type, "error", 0, 1);
+
+  type = tdesc_create_union (feature, "status");
+  field_type = tdesc_named_type (feature, "data_ptr");
+  tdesc_add_field (type, "raw", field_type);
+  field_type = tdesc_named_type (feature, "_bndstatus");
+  tdesc_add_field (type, "status", field_type);
+
+  type = tdesc_create_struct (feature, "_bndcfgu");
+  tdesc_set_struct_size (type, 8);
+  tdesc_add_bitfield (type, "base", 12, 31);
+  tdesc_add_bitfield (type, "reserved", 2, 11);
+  tdesc_add_bitfield (type, "preserved", 1, 1);
+  tdesc_add_bitfield (type, "enabled", 0, 0);
+
+  type = tdesc_create_union (feature, "cfgu");
+  field_type = tdesc_named_type (feature, "data_ptr");
+  tdesc_add_field (type, "raw", field_type);
+  field_type = tdesc_named_type (feature, "_bndcfgu");
+  tdesc_add_field (type, "config", field_type);
+
+  tdesc_create_reg (feature, "bnd0raw", regnum++, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd1raw", regnum++, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd2raw", regnum++, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd3raw", regnum++, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bndcfgu", regnum++, 1, NULL, 64, "cfgu");
+  tdesc_create_reg (feature, "bndstatus", regnum++, 1, NULL, 64, "status");
+  return regnum;
+}
diff --git a/gdb/features/i386/32bit-pkeys.c b/gdb/features/i386/32bit-pkeys.c
new file mode 100644
index 0000000..afb4958
--- /dev/null
+++ b/gdb/features/i386/32bit-pkeys.c
@@ -0,0 +1,16 @@
+/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
+  Original: 32bit-pkeys.xml.tmp */
+
+#include "defs.h"
+#include "osabi.h"
+#include "target-descriptions.h"
+
+static int
+create_feature_i386_32bit_pkeys (struct target_desc *result, long regnum)
+{
+  struct tdesc_feature *feature;
+
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.pkeys");
+  tdesc_create_reg (feature, "pkru", regnum++, 1, NULL, 32, "uint32");
+  return regnum;
+}
diff --git a/gdb/features/i386/32bit-sse.c b/gdb/features/i386/32bit-sse.c
new file mode 100644
index 0000000..9aa7d3e
--- /dev/null
+++ b/gdb/features/i386/32bit-sse.c
@@ -0,0 +1,76 @@
+/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
+  Original: 32bit-sse.xml.tmp */
+
+#include "defs.h"
+#include "osabi.h"
+#include "target-descriptions.h"
+
+static int
+create_feature_i386_32bit_sse (struct target_desc *result, long regnum)
+{
+  struct tdesc_feature *feature;
+
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.sse");
+  struct tdesc_type *field_type;
+  field_type = tdesc_named_type (feature, "ieee_single");
+  tdesc_create_vector (feature, "v4f", field_type, 4);
+
+  field_type = tdesc_named_type (feature, "ieee_double");
+  tdesc_create_vector (feature, "v2d", field_type, 2);
+
+  field_type = tdesc_named_type (feature, "int8");
+  tdesc_create_vector (feature, "v16i8", field_type, 16);
+
+  field_type = tdesc_named_type (feature, "int16");
+  tdesc_create_vector (feature, "v8i16", field_type, 8);
+
+  field_type = tdesc_named_type (feature, "int32");
+  tdesc_create_vector (feature, "v4i32", field_type, 4);
+
+  field_type = tdesc_named_type (feature, "int64");
+  tdesc_create_vector (feature, "v2i64", field_type, 2);
+
+  struct tdesc_type *type;
+  type = tdesc_create_union (feature, "vec128");
+  field_type = tdesc_named_type (feature, "v4f");
+  tdesc_add_field (type, "v4_float", field_type);
+  field_type = tdesc_named_type (feature, "v2d");
+  tdesc_add_field (type, "v2_double", field_type);
+  field_type = tdesc_named_type (feature, "v16i8");
+  tdesc_add_field (type, "v16_int8", field_type);
+  field_type = tdesc_named_type (feature, "v8i16");
+  tdesc_add_field (type, "v8_int16", field_type);
+  field_type = tdesc_named_type (feature, "v4i32");
+  tdesc_add_field (type, "v4_int32", field_type);
+  field_type = tdesc_named_type (feature, "v2i64");
+  tdesc_add_field (type, "v2_int64", field_type);
+  field_type = tdesc_named_type (feature, "uint128");
+  tdesc_add_field (type, "uint128", field_type);
+
+  type = tdesc_create_flags (feature, "i386_mxcsr", 4);
+  tdesc_add_flag (type, 0, "IE");
+  tdesc_add_flag (type, 1, "DE");
+  tdesc_add_flag (type, 2, "ZE");
+  tdesc_add_flag (type, 3, "OE");
+  tdesc_add_flag (type, 4, "UE");
+  tdesc_add_flag (type, 5, "PE");
+  tdesc_add_flag (type, 6, "DAZ");
+  tdesc_add_flag (type, 7, "IM");
+  tdesc_add_flag (type, 8, "DM");
+  tdesc_add_flag (type, 9, "ZM");
+  tdesc_add_flag (type, 10, "OM");
+  tdesc_add_flag (type, 11, "UM");
+  tdesc_add_flag (type, 12, "PM");
+  tdesc_add_flag (type, 15, "FZ");
+
+  tdesc_create_reg (feature, "xmm0", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm1", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm2", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm3", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm4", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm5", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm6", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm7", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "mxcsr", regnum++, 1, "vector", 32, "i386_mxcsr");
+  return regnum;
+}
diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
index ac19792..fceab5f 100644
--- a/gdb/target-descriptions.c
+++ b/gdb/target-descriptions.c
@@ -34,6 +34,7 @@
 #include "gdb_obstack.h"
 #include "hashtab.h"
 #include "inferior.h"
+#include <algorithm>
 
 class tdesc_element_visitor
 {
@@ -42,6 +43,8 @@ public:
   virtual void visit_end (const target_desc *e) = 0;
 
   virtual void visit (const tdesc_feature *e) = 0;
+  virtual void visit_end (const tdesc_feature *e) = 0;
+
   virtual void visit (const tdesc_type *e) = 0;
   virtual void visit (const tdesc_reg *e) = 0;
 };
@@ -309,8 +312,9 @@ public:
       {
 	reg->accept (v);
       }
-  }
 
+    v.visit_end (this);
+  }
 } *tdesc_feature_p;
 DEF_VEC_P(tdesc_feature_p);
 
@@ -1875,6 +1879,9 @@ public:
 		       e->name);
   }
 
+  void visit_end (const tdesc_feature *e) override
+  {}
+
   void visit_end (const target_desc *e) override
   {
     printf_unfiltered ("\n  tdesc_%s = result;\n", m_function);
@@ -2033,38 +2040,123 @@ public:
     printf_unfiltered ("%d, \"%s\");\n", reg->bitsize, reg->type);
   }
 
+protected:
+  std::string m_filename_after_features;
+
 private:
   char *m_function;
-  std::string m_filename_after_features;
   bool m_printed_field_type = false;
   bool m_printed_type = false;
 };
 
+class print_c_feature : public print_c_tdesc
+{
+public:
+  print_c_feature (std::string &file)
+    : print_c_tdesc (file)
+  {
+    /* Trim ".tmp".  */
+    auto const pos = m_filename_after_features.find_last_of ('.');
+
+    m_filename_after_features = m_filename_after_features.substr (0, pos);
+  }
+
+  void visit (const target_desc *e) override
+  {
+    printf_unfiltered ("#include \"defs.h\"\n");
+    printf_unfiltered ("#include \"osabi.h\"\n");
+    printf_unfiltered ("#include \"target-descriptions.h\"\n");
+    printf_unfiltered ("\n");
+  }
+
+  void visit_end (const target_desc *e) override
+  {}
+
+  void visit (const tdesc_feature *e) override
+  {
+    std::string name (m_filename_after_features);
+
+    auto pos = name.find_first_of ('.');
+
+    name = name.substr (0, pos);
+    std::replace (name.begin (), name.end (), '/', '_');
+    std::replace (name.begin (), name.end (), '-', '_');
+
+    printf_unfiltered ("static int\n");
+    printf_unfiltered ("create_feature_%s ", name.c_str ());
+    printf_unfiltered ("(struct target_desc *result, long regnum)\n");
+
+    printf_unfiltered ("{\n");
+    printf_unfiltered ("  struct tdesc_feature *feature;\n");
+    printf_unfiltered ("\n  feature = tdesc_create_feature (result, \"%s\");\n",
+		       e->name);
+  }
+
+  void visit_end (const tdesc_feature *e) override
+  {
+    printf_unfiltered ("  return regnum;\n");
+    printf_unfiltered ("}\n");
+  }
+
+  void visit (const tdesc_reg *reg) override
+  {
+    printf_unfiltered ("  tdesc_create_reg (feature, \"%s\", regnum++, %d, ",
+		       reg->name, reg->save_restore);
+    if (reg->group)
+      printf_unfiltered ("\"%s\", ", reg->group);
+    else
+      printf_unfiltered ("NULL, ");
+    printf_unfiltered ("%d, \"%s\");\n", reg->bitsize, reg->type);
+  }
+
+};
+
 static void
 maint_print_c_tdesc_cmd (char *args, int from_tty)
 {
   const struct target_desc *tdesc;
+  const char *filename;
+
+  if (args == NULL)
+    {
+      /* Use the global target-supplied description, not the current
+	 architecture's.  This lets a GDB for one architecture generate C
+	 for another architecture's description, even though the gdbarch
+	 initialization code will reject the new description.  */
+      tdesc = current_target_desc;
+      filename = target_description_filename;
+    }
+  else
+    {
+      /* Use the target description from the XML file.  */
+      filename = args;
+      tdesc = file_read_description_xml (filename);
+    }
 
-  /* Use the global target-supplied description, not the current
-     architecture's.  This lets a GDB for one architecture generate C
-     for another architecture's description, even though the gdbarch
-     initialization code will reject the new description.  */
-  tdesc = current_target_desc;
   if (tdesc == NULL)
     error (_("There is no target description to print."));
 
-  if (target_description_filename == NULL)
+  if (filename == NULL)
     error (_("The current target description did not come from an XML file."));
 
-  std::string filename_after_features (target_description_filename);
+  std::string filename_after_features (filename);
   auto loc = filename_after_features.rfind ("/features/");
 
   if (loc != std::string::npos)
     filename_after_features = filename_after_features.substr (loc + 10);
 
-  print_c_tdesc v (filename_after_features);
+  if (strncmp (filename_after_features.c_str(), "i386/32bit-", 11) == 0)
+    {
+      print_c_feature v (filename_after_features);
+
+      tdesc->accept (v);
+    }
+  else
+    {
+      print_c_tdesc v (filename_after_features);
 
-  tdesc->accept (v);
+      tdesc->accept (v);
+    }
 }
 
 /* Provide a prototype to silence -Wmissing-prototypes.  */
-- 
1.9.1

^ permalink raw reply	[flat|nested] 82+ messages in thread

* [PATCH 12/25] [GDBserver] Centralize tdesc for i386-linux
  2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
                   ` (2 preceding siblings ...)
  2017-06-12  8:42 ` [PATCH 18/25] [GDBserver] Use pre-generated tdesc as test Yao Qi
@ 2017-06-12  8:42 ` Yao Qi
  2017-06-12  8:42 ` [PATCH 25/25] Remove features/i386/amd64-*linux.c and features/i386/x32-*linux.c Yao Qi
                   ` (22 subsequent siblings)
  26 siblings, 0 replies; 82+ messages in thread
From: Yao Qi @ 2017-06-12  8:42 UTC (permalink / raw)
  To: gdb-patches

tdesc_i386_XXX_linux is spread in linux-x86-low.c and this patch adds
a new function i386_get_ipa_tdesc to return the right tdesc according to
tdesc index.  Note that GDB has a similar function returning tdesc, but
with different argument.  Ultimately, GDB and GDBserver should share
this function.

gdb/gdbserver:

2017-06-07  Yao Qi  <yao.qi@linaro.org>

	* configure.srv (srv_tgtobj): Append linux-x86-tdesc.o.
	(ipa_obj): Likewise.
	* linux-i386-ipa.c (get_ipa_tdesc): Move it to
	linux-x86-tdesc.c.
	(initialize_low_tracepoint): Don't call  init_registers_XXX
	functions, call initialize_low_tdesc instead.
	* linux-x86-low.c (x86_linux_read_description): Call
	i386_get_ipa_tdesc.
	(initialize_low_arch): Don't call init_registers_i386_XXX
	functions, call initialize_low_tdesc.
	* linux-x86-tdesc.c: New file.
	* linux-x86-tdesc.h (x86_linux_tdesc): New X86_TDESC_LAST.
	(i386_get_ipa_tdesc_idx): Declare.
	(i386_get_ipa_tdesc): Declare.
	(initialize_low_tdesc): Declare.
---
 gdb/gdbserver/configure.srv     |   6 ++-
 gdb/gdbserver/linux-i386-ipa.c  |  36 +------------
 gdb/gdbserver/linux-x86-low.c   |  44 +++++-----------
 gdb/gdbserver/linux-x86-tdesc.c | 111 ++++++++++++++++++++++++++++++++++++++++
 gdb/gdbserver/linux-x86-tdesc.h |  31 ++---------
 5 files changed, 135 insertions(+), 93 deletions(-)
 create mode 100644 gdb/gdbserver/linux-x86-tdesc.c

diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv
index d00d9e2..3662f05 100644
--- a/gdb/gdbserver/configure.srv
+++ b/gdb/gdbserver/configure.srv
@@ -122,13 +122,14 @@ case "${target}" in
 			    srv_tgtobj="amd64-linux-siginfo.o"
 			fi
 			srv_tgtobj="${srv_tgtobj} $srv_linux_obj linux-x86-low.o x86-low.o x86-dregs.o i387-fp.o"
+			srv_tgtobj="${srv_tgtobj} linux-x86-tdesc.o"
 			srv_tgtobj="${srv_tgtobj} linux-btrace.o x86-linux.o"
 			srv_tgtobj="${srv_tgtobj} x86-linux-dregs.o"
 			srv_linux_usrregs=yes
 			srv_linux_regsets=yes
 			srv_linux_thread_db=yes
 			srv_linux_btrace=yes
-			ipa_obj="${ipa_i386_linux_regobj} linux-i386-ipa.o"
+			ipa_obj="${ipa_i386_linux_regobj} linux-i386-ipa.o linux-x86-tdesc-ipa.o"
 			;;
   i[34567]86-*-lynxos*)	srv_regobj="i386.o"
 			srv_tgtobj="lynx-low.o lynx-i386-low.o"
@@ -356,6 +357,7 @@ case "${target}" in
 			;;
   x86_64-*-linux*)	srv_regobj="$srv_amd64_linux_regobj $srv_i386_linux_regobj"
 			srv_tgtobj="$srv_linux_obj linux-x86-low.o x86-low.o x86-dregs.o i387-fp.o"
+			srv_tgtobj="${srv_tgtobj} linux-x86-tdesc.o"
 			srv_tgtobj="${srv_tgtobj} linux-btrace.o x86-linux.o"
 			srv_tgtobj="${srv_tgtobj} x86-linux-dregs.o"
 			srv_tgtobj="${srv_tgtobj} amd64-linux-siginfo.o"
@@ -369,7 +371,7 @@ case "${target}" in
 			else
 			    ipa_obj="${ipa_amd64_linux_regobj}"
 			fi
-			ipa_obj="${ipa_obj} linux-amd64-ipa.o"
+			ipa_obj="${ipa_obj} linux-amd64-ipa.o linux-x86-tdesc-ipa.o"
 			;;
   x86_64-*-mingw*)	srv_regobj="$srv_amd64_regobj"
 			srv_tgtobj="x86-low.o x86-dregs.o i387-fp.o win32-low.o win32-i386-low.o"
diff --git a/gdb/gdbserver/linux-i386-ipa.c b/gdb/gdbserver/linux-i386-ipa.c
index e9ac78b..bca3fdb 100644
--- a/gdb/gdbserver/linux-i386-ipa.c
+++ b/gdb/gdbserver/linux-i386-ipa.c
@@ -244,35 +244,6 @@ initialize_fast_tracepoint_trampoline_buffer (void)
     }
 }
 
-/* Return target_desc to use for IPA, given the tdesc index passed by
-   gdbserver.  */
-
-const struct target_desc *
-get_ipa_tdesc (int idx)
-{
-  switch (idx)
-    {
-    case X86_TDESC_MMX:
-      return tdesc_i386_mmx_linux;
-    case X86_TDESC_SSE:
-      return tdesc_i386_linux;
-    case X86_TDESC_AVX:
-      return tdesc_i386_avx_linux;
-    case X86_TDESC_MPX:
-      return tdesc_i386_mpx_linux;
-    case X86_TDESC_AVX_MPX:
-      return tdesc_i386_avx_mpx_linux;
-    case X86_TDESC_AVX_AVX512:
-      return tdesc_i386_avx_avx512_linux;
-    case X86_TDESC_AVX_MPX_AVX512_PKU:
-      return tdesc_i386_avx_mpx_avx512_pku_linux;
-    default:
-      internal_error (__FILE__, __LINE__,
-		      "unknown ipa tdesc index: %d", idx);
-      return tdesc_i386_linux;
-    }
-}
-
 /* Allocate buffer for the jump pads.  On i386, we can reach an arbitrary
    address with a jump instruction, so just allocate normally.  */
 
@@ -291,12 +262,7 @@ alloc_jump_pad_buffer (size_t size)
 void
 initialize_low_tracepoint (void)
 {
-  init_registers_i386_mmx_linux ();
-  init_registers_i386_linux ();
-  init_registers_i386_avx_linux ();
-  init_registers_i386_mpx_linux ();
-  init_registers_i386_avx_avx512_linux ();
-  init_registers_i386_avx_mpx_avx512_pku_linux ();
+  initialize_low_tdesc ();
 
   initialize_fast_tracepoint_trampoline_buffer ();
 }
diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c
index b39026c..f5d4aa1 100644
--- a/gdb/gdbserver/linux-x86-low.c
+++ b/gdb/gdbserver/linux-x86-low.c
@@ -757,7 +757,7 @@ x86_linux_read_description (void)
 	{
 	  have_ptrace_getfpxregs = 0;
 	  have_ptrace_getregset = 0;
-	  return tdesc_i386_mmx_linux;
+	  return i386_get_ipa_tdesc (X86_TDESC_MMX);
 	}
       else
 	have_ptrace_getfpxregs = 1;
@@ -878,26 +878,26 @@ x86_linux_read_description (void)
 	  switch (xcr0 & X86_XSTATE_ALL_MASK)
 	    {
 	    case X86_XSTATE_AVX_MPX_AVX512_PKU_MASK:
-	      return tdesc_i386_avx_mpx_avx512_pku_linux;
+	      return i386_get_ipa_tdesc (X86_TDESC_AVX_MPX_AVX512_PKU);
 
 	    case (X86_XSTATE_AVX_AVX512_MASK):
-	      return tdesc_i386_avx_avx512_linux;
+	      return i386_get_ipa_tdesc (X86_TDESC_AVX_AVX512);
 
 	    case (X86_XSTATE_MPX_MASK):
-	      return tdesc_i386_mpx_linux;
+	      return i386_get_ipa_tdesc (X86_TDESC_MPX);
 
 	    case (X86_XSTATE_AVX_MPX_MASK):
-	      return tdesc_i386_avx_mpx_linux;
+	      return i386_get_ipa_tdesc (X86_TDESC_AVX_MPX);
 
 	    case (X86_XSTATE_AVX_MASK):
-	      return tdesc_i386_avx_linux;
+	      return i386_get_ipa_tdesc (X86_TDESC_AVX);
 
 	    default:
-	      return tdesc_i386_linux;
+	      return i386_get_ipa_tdesc (X86_TDESC_SSE);
 	    }
 	}
       else
-	return tdesc_i386_linux;
+	return i386_get_ipa_tdesc (X86_TDESC_SSE);
     }
 
   gdb_assert_not_reached ("failed to return tdesc");
@@ -2912,22 +2912,10 @@ x86_get_ipa_tdesc_idx (void)
     return X86_TDESC_AVX_AVX512;
 #endif
 
-  if (tdesc == tdesc_i386_mmx_linux)
-    return X86_TDESC_MMX;
-  if (tdesc == tdesc_i386_linux || tdesc == tdesc_i386_linux_no_xml)
+  if (tdesc == tdesc_i386_linux_no_xml)
     return X86_TDESC_SSE;
-  if (tdesc == tdesc_i386_avx_linux)
-    return X86_TDESC_AVX;
-  if (tdesc == tdesc_i386_mpx_linux)
-    return X86_TDESC_MPX;
-  if (tdesc == tdesc_i386_avx_mpx_linux)
-    return X86_TDESC_AVX_MPX;
-  if (tdesc == tdesc_i386_avx_mpx_avx512_pku_linux)
-    return X86_TDESC_AVX_MPX_AVX512_PKU;
-  if (tdesc == tdesc_i386_avx_avx512_linux)
-    return X86_TDESC_AVX_AVX512;
 
-  return 0;
+  return i386_get_ipa_tdesc_idx (tdesc);
 }
 
 /* This is initialized assuming an amd64 target.
@@ -2996,16 +2984,12 @@ initialize_low_arch (void)
   copy_target_description (tdesc_amd64_linux_no_xml, tdesc_amd64_linux);
   tdesc_amd64_linux_no_xml->xmltarget = xmltarget_amd64_linux_no_xml;
 #endif
-  init_registers_i386_linux ();
-  init_registers_i386_mmx_linux ();
-  init_registers_i386_avx_linux ();
-  init_registers_i386_mpx_linux ();
-  init_registers_i386_avx_mpx_linux ();
-  init_registers_i386_avx_avx512_linux ();
-  init_registers_i386_avx_mpx_avx512_pku_linux ();
+
+  initialize_low_tdesc ();
 
   tdesc_i386_linux_no_xml = XNEW (struct target_desc);
-  copy_target_description (tdesc_i386_linux_no_xml, tdesc_i386_linux);
+  copy_target_description (tdesc_i386_linux_no_xml,
+			   i386_get_ipa_tdesc (X86_TDESC_SSE));
   tdesc_i386_linux_no_xml->xmltarget = xmltarget_i386_linux_no_xml;
 
   initialize_regsets_info (&x86_regsets_info);
diff --git a/gdb/gdbserver/linux-x86-tdesc.c b/gdb/gdbserver/linux-x86-tdesc.c
new file mode 100644
index 0000000..e294a98
--- /dev/null
+++ b/gdb/gdbserver/linux-x86-tdesc.c
@@ -0,0 +1,111 @@
+/* GNU/Linux/x86-64 specific target description, for the remote server
+   for GDB.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "server.h"
+#include "linux-x86-tdesc.h"
+
+#if defined __i386__ || !defined IN_PROCESS_AGENT
+/* Defined in auto-generated file i386-linux.c.  */
+void init_registers_i386_linux (void);
+extern const struct target_desc *tdesc_i386_linux;
+
+/* Defined in auto-generated file i386-mmx-linux.c.  */
+void init_registers_i386_mmx_linux (void);
+extern const struct target_desc *tdesc_i386_mmx_linux;
+
+/* Defined in auto-generated file i386-avx-linux.c.  */
+void init_registers_i386_avx_linux (void);
+extern const struct target_desc *tdesc_i386_avx_linux;
+
+/* Defined in auto-generated file i386-avx-mpx-linux.c.  */
+void init_registers_i386_avx_mpx_linux (void);
+extern const struct target_desc *tdesc_i386_avx_mpx_linux;
+
+/* Defined in auto-generated file i386-avx-avx512-linux.c.  */
+void init_registers_i386_avx_avx512_linux (void);
+extern const struct target_desc *tdesc_i386_avx_avx512_linux;
+
+/* Defined in auto-generated file i386-avx-mpx-avx512-linux.c.  */
+void init_registers_i386_avx_mpx_avx512_pku_linux (void);
+extern const struct target_desc *tdesc_i386_avx_mpx_avx512_pku_linux;
+
+/* Defined in auto-generated file i386-mpx-linux.c.  */
+void init_registers_i386_mpx_linux (void);
+extern const struct target_desc *tdesc_i386_mpx_linux;
+#endif
+
+static const struct target_desc *i386_tdescs[X86_TDESC_LAST] = { };
+
+void
+initialize_low_tdesc ()
+{
+#if defined __i386__ || !defined IN_PROCESS_AGENT
+  init_registers_i386_linux ();
+  init_registers_i386_mmx_linux ();
+  init_registers_i386_avx_linux ();
+  init_registers_i386_mpx_linux ();
+  init_registers_i386_avx_mpx_linux ();
+  init_registers_i386_avx_avx512_linux ();
+  init_registers_i386_avx_mpx_avx512_pku_linux ();
+
+  i386_tdescs[X86_TDESC_MMX] = tdesc_i386_mmx_linux;
+  i386_tdescs[X86_TDESC_SSE] = tdesc_i386_linux;
+  i386_tdescs[X86_TDESC_AVX] = tdesc_i386_avx_linux;
+  i386_tdescs[X86_TDESC_MPX] = tdesc_i386_mpx_linux;
+  i386_tdescs[X86_TDESC_AVX_MPX] = tdesc_i386_avx_mpx_linux;
+  i386_tdescs[X86_TDESC_AVX_AVX512] = tdesc_i386_avx_avx512_linux;
+  i386_tdescs[X86_TDESC_AVX_MPX_AVX512_PKU]
+    = tdesc_i386_avx_mpx_avx512_pku_linux;
+#endif
+}
+
+const struct target_desc *
+i386_get_ipa_tdesc (int idx)
+{
+  if (idx >= X86_TDESC_LAST)
+    internal_error (__FILE__, __LINE__,
+		    "unknown ipa tdesc index: %d", idx);
+
+  return i386_tdescs[idx];
+}
+
+#ifdef IN_PROCESS_AGENT
+
+#if defined __i386__
+const struct target_desc *
+get_ipa_tdesc (int idx)
+{
+return i386_get_ipa_tdesc (idx);
+}
+#endif
+
+#else
+int
+i386_get_ipa_tdesc_idx (const struct target_desc *tdesc)
+{
+  for (int i = 0; i < X86_TDESC_LAST; i++)
+    {
+      if (tdesc == i386_tdescs[i])
+	return i;
+    }
+
+  return 0;
+}
+
+#endif
diff --git a/gdb/gdbserver/linux-x86-tdesc.h b/gdb/gdbserver/linux-x86-tdesc.h
index bbe4078..894cf4e 100644
--- a/gdb/gdbserver/linux-x86-tdesc.h
+++ b/gdb/gdbserver/linux-x86-tdesc.h
@@ -30,6 +30,7 @@ enum x86_linux_tdesc {
   X86_TDESC_AVX_MPX = 4,
   X86_TDESC_AVX_AVX512 = 5,
   X86_TDESC_AVX_MPX_AVX512_PKU = 6,
+  X86_TDESC_LAST = 7,
 };
 
 #ifdef __x86_64__
@@ -77,31 +78,9 @@ extern const struct target_desc *tdesc_x32_avx_avx512_linux;
 #endif
 
 #if defined __i386__ || !defined IN_PROCESS_AGENT
-/* Defined in auto-generated file i386-linux.c.  */
-void init_registers_i386_linux (void);
-extern const struct target_desc *tdesc_i386_linux;
-
-/* Defined in auto-generated file i386-mmx-linux.c.  */
-void init_registers_i386_mmx_linux (void);
-extern const struct target_desc *tdesc_i386_mmx_linux;
-
-/* Defined in auto-generated file i386-avx-linux.c.  */
-void init_registers_i386_avx_linux (void);
-extern const struct target_desc *tdesc_i386_avx_linux;
-
-/* Defined in auto-generated file i386-avx-mpx-linux.c.  */
-void init_registers_i386_avx_mpx_linux (void);
-extern const struct target_desc *tdesc_i386_avx_mpx_linux;
-
-/* Defined in auto-generated file i386-avx-avx512-linux.c.  */
-void init_registers_i386_avx_avx512_linux (void);
-extern const struct target_desc *tdesc_i386_avx_avx512_linux;
+int i386_get_ipa_tdesc_idx (const struct target_desc *tdesc);
+#endif
 
-/* Defined in auto-generated file i386-avx-mpx-avx512-linux.c.  */
-void init_registers_i386_avx_mpx_avx512_pku_linux (void);
-extern const struct target_desc *tdesc_i386_avx_mpx_avx512_pku_linux;
+const struct target_desc *i386_get_ipa_tdesc (int idx);
 
-/* Defined in auto-generated file i386-mpx-linux.c.  */
-void init_registers_i386_mpx_linux (void);
-extern const struct target_desc *tdesc_i386_mpx_linux;
-#endif
+void initialize_low_tdesc ();
-- 
1.9.1

^ permalink raw reply	[flat|nested] 82+ messages in thread

* [PATCH 21/25] Lazily and dynamically create amd64-linux target descriptions
  2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
                   ` (20 preceding siblings ...)
  2017-06-12  8:42 ` [PATCH 22/25] Regenerate two regformats/i386/.dat files Yao Qi
@ 2017-06-12  8:42 ` Yao Qi
  2017-06-12  8:42 ` [PATCH 13/25] Dynamically create tdesc in GDBserver Yao Qi
                   ` (4 subsequent siblings)
  26 siblings, 0 replies; 82+ messages in thread
From: Yao Qi @ 2017-06-12  8:42 UTC (permalink / raw)
  To: gdb-patches

This patch starts to use the generate c feature files to dynamically
create amd64-linux target descriptions.

gdb:

2017-06-08  Yao Qi  <yao.qi@linaro.org>

	* amd64-linux-tdep.c: Don't include amd64-XXX-linux and
	x32-XXX-linux.c.  Include 64bit-XX.c and x32-XX.c.
	(amd64_linux_read_description): Create target descriptions.
	(_initialize_amd64_linux_tdep): Don't call initialize_tdesc_XXX
	functions.  Add unit tests.
	* features/Makefile (FEATURE_XMLFILES): Append 64bit-XXX.xml and
	x32-core.xml.  Echo the right architecture for amd64 and x32.
	* features/i386/64bit-avx.c: Generated.
	* features/XXXX
	* target-descriptions.c (maint_print_c_tdesc_cmd): Print feature
	c files for amd64-linux and x32-linux.
---
 gdb/amd64-linux-tdep.c             | 148 ++++++++++++++++++++++++-------------
 gdb/features/Makefile              |  16 +++-
 gdb/features/i386/64bit-avx.c      |  35 +++++++++
 gdb/features/i386/64bit-avx512.c   | 130 ++++++++++++++++++++++++++++++++
 gdb/features/i386/64bit-core.c     |  80 ++++++++++++++++++++
 gdb/features/i386/64bit-linux.c    |  21 ++++++
 gdb/features/i386/64bit-mpx.c      |  57 ++++++++++++++
 gdb/features/i386/64bit-pkeys.c    |  20 +++++
 gdb/features/i386/64bit-segments.c |  21 ++++++
 gdb/features/i386/64bit-sse.c      |  89 ++++++++++++++++++++++
 gdb/features/i386/x32-core.c       |  80 ++++++++++++++++++++
 gdb/target-descriptions.c          |   4 +-
 12 files changed, 646 insertions(+), 55 deletions(-)
 create mode 100644 gdb/features/i386/64bit-avx.c
 create mode 100644 gdb/features/i386/64bit-avx512.c
 create mode 100644 gdb/features/i386/64bit-core.c
 create mode 100644 gdb/features/i386/64bit-linux.c
 create mode 100644 gdb/features/i386/64bit-mpx.c
 create mode 100644 gdb/features/i386/64bit-pkeys.c
 create mode 100644 gdb/features/i386/64bit-segments.c
 create mode 100644 gdb/features/i386/64bit-sse.c
 create mode 100644 gdb/features/i386/x32-core.c

diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
index b9f624d..801ea79 100644
--- a/gdb/amd64-linux-tdep.c
+++ b/gdb/amd64-linux-tdep.c
@@ -40,16 +40,16 @@
 #include "xml-syscall.h"
 #include "glibc-tdep.h"
 
-#include "features/i386/amd64-linux.c"
-#include "features/i386/amd64-avx-linux.c"
-#include "features/i386/amd64-mpx-linux.c"
-#include "features/i386/amd64-avx-mpx-linux.c"
-#include "features/i386/amd64-avx-avx512-linux.c"
-#include "features/i386/amd64-avx-mpx-avx512-pku-linux.c"
+#include "features/i386/64bit-avx.c"
+#include "features/i386/64bit-avx512.c"
+#include "features/i386/64bit-core.c"
+#include "features/i386/64bit-linux.c"
+#include "features/i386/64bit-mpx.c"
+#include "features/i386/64bit-pkeys.c"
+#include "features/i386/64bit-segments.c"
+#include "features/i386/64bit-sse.c"
 
-#include "features/i386/x32-linux.c"
-#include "features/i386/x32-avx-linux.c"
-#include "features/i386/x32-avx-avx512-linux.c"
+#include "features/i386/x32-core.c"
 
 /* The syscall's XML filename for i386.  */
 #define XML_SYSCALL_FILENAME_AMD64 "syscalls/amd64-linux.xml"
@@ -1578,40 +1578,72 @@ amd64_linux_record_signal (struct gdbarch *gdbarch,
 const target_desc *
 amd64_linux_read_description (uint64_t xcr0_features_bit, bool is_x32)
 {
-  switch (xcr0_features_bit)
+  static target_desc *amd64_linux_tdescs \
+    [2/*AVX*/][2/*MPX*/][2/*AVX512*/][2/*PKRU*/] = {};
+  static target_desc *x32_linux_tdescs[2/*AVX*/][2/*AVX512*/] = {};
+
+  target_desc **tdesc;
+
+  if (is_x32)
     {
-    case X86_XSTATE_AVX_MPX_AVX512_PKU_MASK:
-      if (is_x32)
-	/* No MPX, PKU on x32, fall back to AVX-AVX512.  */
-	return tdesc_x32_avx_avx512_linux;
-      else
-	return tdesc_amd64_avx_mpx_avx512_pku_linux;
-    case X86_XSTATE_AVX_AVX512_MASK:
-      if (is_x32)
-	return tdesc_x32_avx_avx512_linux;
-      else
-	return tdesc_amd64_avx_avx512_linux;
-    case X86_XSTATE_MPX_MASK:
-      if (is_x32)
-	return tdesc_x32_avx_linux; /* No MPX on x32 using AVX.  */
-      else
-	return tdesc_amd64_mpx_linux;
-    case X86_XSTATE_AVX_MPX_MASK:
-      if (is_x32)
-	return tdesc_x32_avx_linux; /* No MPX on x32 using AVX.  */
-      else
-	return tdesc_amd64_avx_mpx_linux;
-    case X86_XSTATE_AVX_MASK:
-      if (is_x32)
-	return tdesc_x32_avx_linux;
-      else
-	return tdesc_amd64_avx_linux;
-    default:
-      if (is_x32)
-	return tdesc_x32_linux;
-      else
-	return tdesc_amd64_linux;
+      tdesc = &x32_linux_tdescs[(xcr0_features_bit & X86_XSTATE_AVX) ? 1 : 0 ]
+	[(xcr0_features_bit & X86_XSTATE_AVX512) ? 1 : 0];
+
+      if (*tdesc == NULL)
+	{
+	  *tdesc = allocate_target_description ();
+	  set_tdesc_architecture (*tdesc, bfd_scan_arch ("i386:x64-32"));
+	  set_tdesc_osabi (*tdesc, osabi_from_tdesc_string ("GNU/Linux"));
+
+	  long regnum = 0;
+
+	  regnum = create_feature_i386_x32_core (*tdesc, regnum);
+	  regnum = create_feature_i386_64bit_sse (*tdesc, regnum);
+	  regnum = create_feature_i386_64bit_linux (*tdesc, regnum);
+	  regnum = create_feature_i386_64bit_segments (*tdesc, regnum);
+
+	  if (xcr0_features_bit & X86_XSTATE_AVX)
+	    regnum = create_feature_i386_64bit_avx (*tdesc, regnum);
+
+	  if (xcr0_features_bit & X86_XSTATE_AVX512)
+	    regnum = create_feature_i386_64bit_avx512 (*tdesc, regnum);
+	}
     }
+  else
+    {
+      tdesc = &amd64_linux_tdescs[(xcr0_features_bit & X86_XSTATE_AVX) ? 1 : 0]
+	[(xcr0_features_bit & X86_XSTATE_MPX) ? 1 : 0]
+	[(xcr0_features_bit & X86_XSTATE_AVX512) ? 1 : 0]
+	[(xcr0_features_bit & X86_XSTATE_PKRU) ? 1 : 0];
+
+      if (*tdesc == NULL)
+	{
+	  *tdesc = allocate_target_description ();
+	  set_tdesc_architecture (*tdesc, bfd_scan_arch ("i386:x86-64"));
+	  set_tdesc_osabi (*tdesc, osabi_from_tdesc_string ("GNU/Linux"));
+
+	  long regnum = 0;
+
+	  regnum = create_feature_i386_64bit_core (*tdesc, regnum);
+	  regnum = create_feature_i386_64bit_sse (*tdesc, regnum);
+	  regnum = create_feature_i386_64bit_linux (*tdesc, regnum);
+	  regnum = create_feature_i386_64bit_segments (*tdesc, regnum);
+
+	  if (xcr0_features_bit & X86_XSTATE_AVX)
+	    regnum = create_feature_i386_64bit_avx (*tdesc, regnum);
+
+	  if (xcr0_features_bit & X86_XSTATE_MPX)
+	    regnum = create_feature_i386_64bit_mpx (*tdesc, regnum);
+
+	  if (xcr0_features_bit & X86_XSTATE_AVX512)
+	    regnum = create_feature_i386_64bit_avx512 (*tdesc, regnum);
+
+	  if (xcr0_features_bit & X86_XSTATE_PKRU)
+	    regnum = create_feature_i386_64bit_pkeys (*tdesc, regnum);
+	}
+    }
+
+  return *tdesc;
 }
 
 /* Get Linux/x86 target description from core dump.  */
@@ -2305,15 +2337,27 @@ _initialize_amd64_linux_tdep (void)
   gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x64_32,
 			  GDB_OSABI_LINUX, amd64_x32_linux_init_abi);
 
-  /* Initialize the Linux target description.  */
-  initialize_tdesc_amd64_linux ();
-  initialize_tdesc_amd64_avx_linux ();
-  initialize_tdesc_amd64_mpx_linux ();
-  initialize_tdesc_amd64_avx_mpx_linux ();
-  initialize_tdesc_amd64_avx_avx512_linux ();
-  initialize_tdesc_amd64_avx_mpx_avx512_pku_linux ();
-
-  initialize_tdesc_x32_linux ();
-  initialize_tdesc_x32_avx_linux ();
-  initialize_tdesc_x32_avx_avx512_linux ();
+#if GDB_SELF_TEST
+  std::pair<const char *, uint64_t> xml_masks[] = {
+    { "i386/amd64-linux.xml", X86_XSTATE_SSE_MASK },
+    { "i386/amd64-avx-linux.xml", X86_XSTATE_AVX_MASK },
+    { "i386/amd64-mpx-linux.xml", X86_XSTATE_MPX_MASK },
+    { "i386/amd64-avx-mpx-linux.xml", X86_XSTATE_AVX_MPX_MASK },
+    { "i386/amd64-avx-avx512-linux.xml", X86_XSTATE_AVX_AVX512_MASK },
+    { "i386/amd64-avx-mpx-avx512-pku-linux.xml",
+      X86_XSTATE_AVX_MPX_AVX512_PKU_MASK },
+    { "i386/x32-linux.xml", X86_XSTATE_SSE_MASK },
+    { "i386/x32-avx-linux.xml", X86_XSTATE_AVX_MASK },
+    { "i386/x32-avx-avx512-linux.xml", X86_XSTATE_AVX_AVX512_MASK },
+  };
+
+  for (auto &a : xml_masks)
+    {
+      auto tdesc =
+	amd64_linux_read_description (a.second,
+				      strncmp (a.first, "i386/x32", 8) == 0);
+
+      selftests::record_xml_tdesc (a.first, tdesc);
+    }
+#endif /* GDB_SELF_TEST */
 }
diff --git a/gdb/features/Makefile b/gdb/features/Makefile
index 9fdaeba..0f43565 100644
--- a/gdb/features/Makefile
+++ b/gdb/features/Makefile
@@ -251,7 +251,16 @@ FEATURE_XMLFILES = i386/32bit-core.xml \
 	i386/32bit-avx.xml \
 	i386/32bit-mpx.xml \
 	i386/32bit-avx512.xml \
-	i386/32bit-pkeys.xml
+	i386/32bit-pkeys.xml \
+	i386/64bit-avx512.xml \
+	i386/64bit-core.xml \
+	i386/64bit-mpx.xml \
+	i386/64bit-segments.xml \
+	i386/64bit-avx.xml \
+	i386/64bit-linux.xml \
+	i386/64bit-pkeys.xml \
+	i386/64bit-sse.xml \
+	i386/x32-core.xml
 
 FEATURE_CFILES = $(patsubst %.xml,%.c,$(FEATURE_XMLFILES))
 
@@ -273,7 +282,10 @@ $(FEATURE_CFILES): %.c: %.xml.tmp
 	echo "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">" >> $@
 	echo "<target>" >> $@
 	echo "  <architecture>" >> $@
-	if test $(findstring i386/32bit-,$@); then echo "i386" >> $@ ; fi;
+	if test $(findstring i386/32bit-,$@); then echo "i386" >> $@ ; \
+	elif test $(findstring i386/64bit-,$@); then echo "i386:x86-64" >> $@; \
+	elif test $(findstring i386/x32-,$@); then echo "i386:x64-32" >> $@; \
+	fi;
 	echo "  </architecture>" >> $@
 	echo "  <xi:include href=\"$(notdir $<)\"/>" >> $@
 	echo "</target>" >> $@
diff --git a/gdb/features/i386/64bit-avx.c b/gdb/features/i386/64bit-avx.c
new file mode 100644
index 0000000..3edb3e8
--- /dev/null
+++ b/gdb/features/i386/64bit-avx.c
@@ -0,0 +1,35 @@
+/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
+  Original: 64bit-avx.xml.tmp */
+
+#ifdef GDBSERVER
+#include "tdesc.h"
+#else
+#include "defs.h"
+#include "osabi.h"
+#include "target-descriptions.h"
+#endif
+
+static int
+create_feature_i386_64bit_avx (struct target_desc *result, long regnum)
+{
+  struct tdesc_feature *feature;
+
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx", "64bit-avx.xml");
+  tdesc_create_reg (feature, "ymm0h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm1h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm2h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm3h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm4h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm5h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm6h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm7h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm8h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm9h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm10h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm11h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm12h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm13h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm14h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm15h", regnum++, 1, NULL, 128, "uint128");
+  return regnum;
+}
diff --git a/gdb/features/i386/64bit-avx512.c b/gdb/features/i386/64bit-avx512.c
new file mode 100644
index 0000000..57c9a2a
--- /dev/null
+++ b/gdb/features/i386/64bit-avx512.c
@@ -0,0 +1,130 @@
+/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
+  Original: 64bit-avx512.xml.tmp */
+
+#ifdef GDBSERVER
+#include "tdesc.h"
+#else
+#include "defs.h"
+#include "osabi.h"
+#include "target-descriptions.h"
+#endif
+
+static int
+create_feature_i386_64bit_avx512 (struct target_desc *result, long regnum)
+{
+  struct tdesc_feature *feature;
+
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx512", "64bit-avx512.xml");
+  struct tdesc_type *field_type;
+  field_type = tdesc_named_type (feature, "ieee_single");
+  tdesc_create_vector (feature, "v4f", field_type, 4);
+
+  field_type = tdesc_named_type (feature, "ieee_double");
+  tdesc_create_vector (feature, "v2d", field_type, 2);
+
+  field_type = tdesc_named_type (feature, "int8");
+  tdesc_create_vector (feature, "v16i8", field_type, 16);
+
+  field_type = tdesc_named_type (feature, "int16");
+  tdesc_create_vector (feature, "v8i16", field_type, 8);
+
+  field_type = tdesc_named_type (feature, "int32");
+  tdesc_create_vector (feature, "v4i32", field_type, 4);
+
+  field_type = tdesc_named_type (feature, "int64");
+  tdesc_create_vector (feature, "v2i64", field_type, 2);
+
+  struct tdesc_type *type;
+  type = tdesc_create_union (feature, "vec128");
+  field_type = tdesc_named_type (feature, "v4f");
+  tdesc_add_field (type, "v4_float", field_type);
+  field_type = tdesc_named_type (feature, "v2d");
+  tdesc_add_field (type, "v2_double", field_type);
+  field_type = tdesc_named_type (feature, "v16i8");
+  tdesc_add_field (type, "v16_int8", field_type);
+  field_type = tdesc_named_type (feature, "v8i16");
+  tdesc_add_field (type, "v8_int16", field_type);
+  field_type = tdesc_named_type (feature, "v4i32");
+  tdesc_add_field (type, "v4_int32", field_type);
+  field_type = tdesc_named_type (feature, "v2i64");
+  tdesc_add_field (type, "v2_int64", field_type);
+  field_type = tdesc_named_type (feature, "uint128");
+  tdesc_add_field (type, "uint128", field_type);
+
+  field_type = tdesc_named_type (feature, "uint128");
+  tdesc_create_vector (feature, "v2ui128", field_type, 2);
+
+  tdesc_create_reg (feature, "xmm16", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm17", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm18", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm19", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm20", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm21", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm22", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm23", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm24", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm25", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm26", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm27", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm28", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm29", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm30", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm31", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "ymm16h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm17h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm18h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm19h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm20h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm21h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm22h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm23h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm24h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm25h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm26h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm27h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm28h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm29h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm30h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm31h", regnum++, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "k0", regnum++, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k1", regnum++, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k2", regnum++, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k3", regnum++, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k4", regnum++, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k5", regnum++, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k6", regnum++, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k7", regnum++, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "zmm0h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm1h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm2h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm3h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm4h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm5h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm6h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm7h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm8h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm9h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm10h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm11h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm12h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm13h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm14h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm15h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm16h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm17h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm18h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm19h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm20h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm21h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm22h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm23h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm24h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm25h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm26h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm27h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm28h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm29h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm30h", regnum++, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm31h", regnum++, 1, NULL, 256, "v2ui128");
+  return regnum;
+}
diff --git a/gdb/features/i386/64bit-core.c b/gdb/features/i386/64bit-core.c
new file mode 100644
index 0000000..4b7fae0
--- /dev/null
+++ b/gdb/features/i386/64bit-core.c
@@ -0,0 +1,80 @@
+/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
+  Original: 64bit-core.xml.tmp */
+
+#ifdef GDBSERVER
+#include "tdesc.h"
+#else
+#include "defs.h"
+#include "osabi.h"
+#include "target-descriptions.h"
+#endif
+
+static int
+create_feature_i386_64bit_core (struct target_desc *result, long regnum)
+{
+  struct tdesc_feature *feature;
+
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core", "64bit-core.xml");
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
+  type = tdesc_create_flags (feature, "i386_eflags", 4);
+  tdesc_add_flag (type, 0, "CF");
+  tdesc_add_flag (type, 1, "");
+  tdesc_add_flag (type, 2, "PF");
+  tdesc_add_flag (type, 4, "AF");
+  tdesc_add_flag (type, 6, "ZF");
+  tdesc_add_flag (type, 7, "SF");
+  tdesc_add_flag (type, 8, "TF");
+  tdesc_add_flag (type, 9, "IF");
+  tdesc_add_flag (type, 10, "DF");
+  tdesc_add_flag (type, 11, "OF");
+  tdesc_add_flag (type, 14, "NT");
+  tdesc_add_flag (type, 16, "RF");
+  tdesc_add_flag (type, 17, "VM");
+  tdesc_add_flag (type, 18, "AC");
+  tdesc_add_flag (type, 19, "VIF");
+  tdesc_add_flag (type, 20, "VIP");
+  tdesc_add_flag (type, 21, "ID");
+
+  tdesc_create_reg (feature, "rax", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "rbx", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "rcx", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "rdx", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "rsi", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "rdi", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "rbp", regnum++, 1, NULL, 64, "data_ptr");
+  tdesc_create_reg (feature, "rsp", regnum++, 1, NULL, 64, "data_ptr");
+  tdesc_create_reg (feature, "r8", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "r9", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "r10", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "r11", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "r12", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "r13", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "r14", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "r15", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "rip", regnum++, 1, NULL, 64, "code_ptr");
+  tdesc_create_reg (feature, "eflags", regnum++, 1, NULL, 32, "i386_eflags");
+  tdesc_create_reg (feature, "cs", regnum++, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "ss", regnum++, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "ds", regnum++, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "es", regnum++, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "fs", regnum++, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "gs", regnum++, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "st0", regnum++, 1, NULL, 80, "i387_ext");
+  tdesc_create_reg (feature, "st1", regnum++, 1, NULL, 80, "i387_ext");
+  tdesc_create_reg (feature, "st2", regnum++, 1, NULL, 80, "i387_ext");
+  tdesc_create_reg (feature, "st3", regnum++, 1, NULL, 80, "i387_ext");
+  tdesc_create_reg (feature, "st4", regnum++, 1, NULL, 80, "i387_ext");
+  tdesc_create_reg (feature, "st5", regnum++, 1, NULL, 80, "i387_ext");
+  tdesc_create_reg (feature, "st6", regnum++, 1, NULL, 80, "i387_ext");
+  tdesc_create_reg (feature, "st7", regnum++, 1, NULL, 80, "i387_ext");
+  tdesc_create_reg (feature, "fctrl", regnum++, 1, "float", 32, "int");
+  tdesc_create_reg (feature, "fstat", regnum++, 1, "float", 32, "int");
+  tdesc_create_reg (feature, "ftag", regnum++, 1, "float", 32, "int");
+  tdesc_create_reg (feature, "fiseg", regnum++, 1, "float", 32, "int");
+  tdesc_create_reg (feature, "fioff", regnum++, 1, "float", 32, "int");
+  tdesc_create_reg (feature, "foseg", regnum++, 1, "float", 32, "int");
+  tdesc_create_reg (feature, "fooff", regnum++, 1, "float", 32, "int");
+  tdesc_create_reg (feature, "fop", regnum++, 1, "float", 32, "int");
+  return regnum;
+}
diff --git a/gdb/features/i386/64bit-linux.c b/gdb/features/i386/64bit-linux.c
new file mode 100644
index 0000000..1e0b595
--- /dev/null
+++ b/gdb/features/i386/64bit-linux.c
@@ -0,0 +1,21 @@
+/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
+  Original: 64bit-linux.xml.tmp */
+
+#ifdef GDBSERVER
+#include "tdesc.h"
+#else
+#include "defs.h"
+#include "osabi.h"
+#include "target-descriptions.h"
+#endif
+
+static int
+create_feature_i386_64bit_linux (struct target_desc *result, long regnum)
+{
+  struct tdesc_feature *feature;
+
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux", "64bit-linux.xml");
+  regnum = 57;
+  tdesc_create_reg (feature, "orig_rax", regnum++, 1, NULL, 64, "int");
+  return regnum;
+}
diff --git a/gdb/features/i386/64bit-mpx.c b/gdb/features/i386/64bit-mpx.c
new file mode 100644
index 0000000..c7415f6
--- /dev/null
+++ b/gdb/features/i386/64bit-mpx.c
@@ -0,0 +1,57 @@
+/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
+  Original: 64bit-mpx.xml.tmp */
+
+#ifdef GDBSERVER
+#include "tdesc.h"
+#else
+#include "defs.h"
+#include "osabi.h"
+#include "target-descriptions.h"
+#endif
+
+static int
+create_feature_i386_64bit_mpx (struct target_desc *result, long regnum)
+{
+  struct tdesc_feature *feature;
+
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.mpx", "64bit-mpx.xml");
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
+  type = tdesc_create_struct (feature, "br128");
+  field_type = tdesc_named_type (feature, "uint64");
+  tdesc_add_field (type, "lbound", field_type);
+  field_type = tdesc_named_type (feature, "uint64");
+  tdesc_add_field (type, "ubound_raw", field_type);
+
+  type = tdesc_create_struct (feature, "_bndstatus");
+  tdesc_set_struct_size (type, 8);
+  tdesc_add_bitfield (type, "bde", 2, 63);
+  tdesc_add_bitfield (type, "error", 0, 1);
+
+  type = tdesc_create_union (feature, "status");
+  field_type = tdesc_named_type (feature, "data_ptr");
+  tdesc_add_field (type, "raw", field_type);
+  field_type = tdesc_named_type (feature, "_bndstatus");
+  tdesc_add_field (type, "status", field_type);
+
+  type = tdesc_create_struct (feature, "_bndcfgu");
+  tdesc_set_struct_size (type, 8);
+  tdesc_add_bitfield (type, "base", 12, 63);
+  tdesc_add_bitfield (type, "reserved", 2, 11);
+  tdesc_add_bitfield (type, "preserved", 1, 1);
+  tdesc_add_bitfield (type, "enabled", 0, 0);
+
+  type = tdesc_create_union (feature, "cfgu");
+  field_type = tdesc_named_type (feature, "data_ptr");
+  tdesc_add_field (type, "raw", field_type);
+  field_type = tdesc_named_type (feature, "_bndcfgu");
+  tdesc_add_field (type, "config", field_type);
+
+  tdesc_create_reg (feature, "bnd0raw", regnum++, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd1raw", regnum++, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd2raw", regnum++, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd3raw", regnum++, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bndcfgu", regnum++, 1, NULL, 64, "cfgu");
+  tdesc_create_reg (feature, "bndstatus", regnum++, 1, NULL, 64, "status");
+  return regnum;
+}
diff --git a/gdb/features/i386/64bit-pkeys.c b/gdb/features/i386/64bit-pkeys.c
new file mode 100644
index 0000000..66d3903
--- /dev/null
+++ b/gdb/features/i386/64bit-pkeys.c
@@ -0,0 +1,20 @@
+/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
+  Original: 64bit-pkeys.xml.tmp */
+
+#ifdef GDBSERVER
+#include "tdesc.h"
+#else
+#include "defs.h"
+#include "osabi.h"
+#include "target-descriptions.h"
+#endif
+
+static int
+create_feature_i386_64bit_pkeys (struct target_desc *result, long regnum)
+{
+  struct tdesc_feature *feature;
+
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.pkeys", "64bit-pkeys.xml");
+  tdesc_create_reg (feature, "pkru", regnum++, 1, NULL, 32, "uint32");
+  return regnum;
+}
diff --git a/gdb/features/i386/64bit-segments.c b/gdb/features/i386/64bit-segments.c
new file mode 100644
index 0000000..13f5a52
--- /dev/null
+++ b/gdb/features/i386/64bit-segments.c
@@ -0,0 +1,21 @@
+/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
+  Original: 64bit-segments.xml.tmp */
+
+#ifdef GDBSERVER
+#include "tdesc.h"
+#else
+#include "defs.h"
+#include "osabi.h"
+#include "target-descriptions.h"
+#endif
+
+static int
+create_feature_i386_64bit_segments (struct target_desc *result, long regnum)
+{
+  struct tdesc_feature *feature;
+
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments", "64bit-segments.xml");
+  tdesc_create_reg (feature, "fs_base", regnum++, 1, NULL, 64, "int");
+  tdesc_create_reg (feature, "gs_base", regnum++, 1, NULL, 64, "int");
+  return regnum;
+}
diff --git a/gdb/features/i386/64bit-sse.c b/gdb/features/i386/64bit-sse.c
new file mode 100644
index 0000000..d7eadd2
--- /dev/null
+++ b/gdb/features/i386/64bit-sse.c
@@ -0,0 +1,89 @@
+/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
+  Original: 64bit-sse.xml.tmp */
+
+#ifdef GDBSERVER
+#include "tdesc.h"
+#else
+#include "defs.h"
+#include "osabi.h"
+#include "target-descriptions.h"
+#endif
+
+static int
+create_feature_i386_64bit_sse (struct target_desc *result, long regnum)
+{
+  struct tdesc_feature *feature;
+
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.sse", "64bit-sse.xml");
+  struct tdesc_type *field_type;
+  field_type = tdesc_named_type (feature, "ieee_single");
+  tdesc_create_vector (feature, "v4f", field_type, 4);
+
+  field_type = tdesc_named_type (feature, "ieee_double");
+  tdesc_create_vector (feature, "v2d", field_type, 2);
+
+  field_type = tdesc_named_type (feature, "int8");
+  tdesc_create_vector (feature, "v16i8", field_type, 16);
+
+  field_type = tdesc_named_type (feature, "int16");
+  tdesc_create_vector (feature, "v8i16", field_type, 8);
+
+  field_type = tdesc_named_type (feature, "int32");
+  tdesc_create_vector (feature, "v4i32", field_type, 4);
+
+  field_type = tdesc_named_type (feature, "int64");
+  tdesc_create_vector (feature, "v2i64", field_type, 2);
+
+  struct tdesc_type *type;
+  type = tdesc_create_union (feature, "vec128");
+  field_type = tdesc_named_type (feature, "v4f");
+  tdesc_add_field (type, "v4_float", field_type);
+  field_type = tdesc_named_type (feature, "v2d");
+  tdesc_add_field (type, "v2_double", field_type);
+  field_type = tdesc_named_type (feature, "v16i8");
+  tdesc_add_field (type, "v16_int8", field_type);
+  field_type = tdesc_named_type (feature, "v8i16");
+  tdesc_add_field (type, "v8_int16", field_type);
+  field_type = tdesc_named_type (feature, "v4i32");
+  tdesc_add_field (type, "v4_int32", field_type);
+  field_type = tdesc_named_type (feature, "v2i64");
+  tdesc_add_field (type, "v2_int64", field_type);
+  field_type = tdesc_named_type (feature, "uint128");
+  tdesc_add_field (type, "uint128", field_type);
+
+  type = tdesc_create_flags (feature, "i386_mxcsr", 4);
+  tdesc_add_flag (type, 0, "IE");
+  tdesc_add_flag (type, 1, "DE");
+  tdesc_add_flag (type, 2, "ZE");
+  tdesc_add_flag (type, 3, "OE");
+  tdesc_add_flag (type, 4, "UE");
+  tdesc_add_flag (type, 5, "PE");
+  tdesc_add_flag (type, 6, "DAZ");
+  tdesc_add_flag (type, 7, "IM");
+  tdesc_add_flag (type, 8, "DM");
+  tdesc_add_flag (type, 9, "ZM");
+  tdesc_add_flag (type, 10, "OM");
+  tdesc_add_flag (type, 11, "UM");
+  tdesc_add_flag (type, 12, "PM");
+  tdesc_add_flag (type, 15, "FZ");
+
+  regnum = 40;
+  tdesc_create_reg (feature, "xmm0", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm1", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm2", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm3", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm4", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm5", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm6", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm7", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm8", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm9", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm10", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm11", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm12", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm13", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm14", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm15", regnum++, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "mxcsr", regnum++, 1, "vector", 32, "i386_mxcsr");
+  return regnum;
+}
diff --git a/gdb/features/i386/x32-core.c b/gdb/features/i386/x32-core.c
new file mode 100644
index 0000000..dc74313
--- /dev/null
+++ b/gdb/features/i386/x32-core.c
@@ -0,0 +1,80 @@
+/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
+  Original: x32-core.xml.tmp */
+
+#ifdef GDBSERVER
+#include "tdesc.h"
+#else
+#include "defs.h"
+#include "osabi.h"
+#include "target-descriptions.h"
+#endif
+
+static int
+create_feature_i386_x32_core (struct target_desc *result, long regnum)
+{
+  struct tdesc_feature *feature;
+
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core", "x32-core.xml");
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
+  type = tdesc_create_flags (feature, "i386_eflags", 4);
+  tdesc_add_flag (type, 0, "CF");
+  tdesc_add_flag (type, 1, "");
+  tdesc_add_flag (type, 2, "PF");
+  tdesc_add_flag (type, 4, "AF");
+  tdesc_add_flag (type, 6, "ZF");
+  tdesc_add_flag (type, 7, "SF");
+  tdesc_add_flag (type, 8, "TF");
+  tdesc_add_flag (type, 9, "IF");
+  tdesc_add_flag (type, 10, "DF");
+  tdesc_add_flag (type, 11, "OF");
+  tdesc_add_flag (type, 14, "NT");
+  tdesc_add_flag (type, 16, "RF");
+  tdesc_add_flag (type, 17, "VM");
+  tdesc_add_flag (type, 18, "AC");
+  tdesc_add_flag (type, 19, "VIF");
+  tdesc_add_flag (type, 20, "VIP");
+  tdesc_add_flag (type, 21, "ID");
+
+  tdesc_create_reg (feature, "rax", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "rbx", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "rcx", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "rdx", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "rsi", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "rdi", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "rbp", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "rsp", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "r8", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "r9", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "r10", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "r11", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "r12", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "r13", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "r14", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "r15", regnum++, 1, NULL, 64, "int64");
+  tdesc_create_reg (feature, "rip", regnum++, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "eflags", regnum++, 1, NULL, 32, "i386_eflags");
+  tdesc_create_reg (feature, "cs", regnum++, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "ss", regnum++, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "ds", regnum++, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "es", regnum++, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "fs", regnum++, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "gs", regnum++, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "st0", regnum++, 1, NULL, 80, "i387_ext");
+  tdesc_create_reg (feature, "st1", regnum++, 1, NULL, 80, "i387_ext");
+  tdesc_create_reg (feature, "st2", regnum++, 1, NULL, 80, "i387_ext");
+  tdesc_create_reg (feature, "st3", regnum++, 1, NULL, 80, "i387_ext");
+  tdesc_create_reg (feature, "st4", regnum++, 1, NULL, 80, "i387_ext");
+  tdesc_create_reg (feature, "st5", regnum++, 1, NULL, 80, "i387_ext");
+  tdesc_create_reg (feature, "st6", regnum++, 1, NULL, 80, "i387_ext");
+  tdesc_create_reg (feature, "st7", regnum++, 1, NULL, 80, "i387_ext");
+  tdesc_create_reg (feature, "fctrl", regnum++, 1, "float", 32, "int");
+  tdesc_create_reg (feature, "fstat", regnum++, 1, "float", 32, "int");
+  tdesc_create_reg (feature, "ftag", regnum++, 1, "float", 32, "int");
+  tdesc_create_reg (feature, "fiseg", regnum++, 1, "float", 32, "int");
+  tdesc_create_reg (feature, "fioff", regnum++, 1, "float", 32, "int");
+  tdesc_create_reg (feature, "foseg", regnum++, 1, "float", 32, "int");
+  tdesc_create_reg (feature, "fooff", regnum++, 1, "float", 32, "int");
+  tdesc_create_reg (feature, "fop", regnum++, 1, "float", 32, "int");
+  return regnum;
+}
diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
index a12fd7e..d9fb374 100644
--- a/gdb/target-descriptions.c
+++ b/gdb/target-descriptions.c
@@ -2266,7 +2266,9 @@ maint_print_c_tdesc_cmd (char *args, int from_tty)
   if (loc != std::string::npos)
     filename_after_features = filename_after_features.substr (loc + 10);
 
-  if (strncmp (filename_after_features.c_str(), "i386/32bit-", 11) == 0)
+  if (strncmp (filename_after_features.c_str(), "i386/32bit-", 11) == 0
+      || strncmp (filename_after_features.c_str(), "i386/64bit-", 11) == 0
+      || strncmp (filename_after_features.c_str(), "i386/x32-core.xml", 17) == 0)
     {
       print_c_feature v (filename_after_features);
 
-- 
1.9.1

^ permalink raw reply	[flat|nested] 82+ messages in thread

* [PATCH 23/25] [GDBserver] Convert amd64-linux target descriptions
  2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
                   ` (8 preceding siblings ...)
  2017-06-12  8:42 ` [PATCH 17/25] Remove features/i386/i386-*linux.c Yao Qi
@ 2017-06-12  8:42 ` Yao Qi
  2017-06-28 19:00   ` Pedro Alves
  2017-06-12  8:42 ` [PATCH 15/25] [RFC] GDBserver unit test to i386_tdesc Yao Qi
                   ` (16 subsequent siblings)
  26 siblings, 1 reply; 82+ messages in thread
From: Yao Qi @ 2017-06-12  8:42 UTC (permalink / raw)
  To: gdb-patches

This patch changes amd64-linux target descriptions so that they can be
dynamically generated.

gdb/gdbserver:

2017-06-09  Yao Qi  <yao.qi@linaro.org>

	* linux-amd64-ipa.c (get_ipa_tdesc): Remove.
	(initialize_low_tracepoint): Don't call init_registers_x32_XXX
	and init_registers_amd64_XXX.
	* linux-x86-low.c (x86_linux_read_description): Call
	amd64_get_ipa_tdesc.
	(x86_get_ipa_tdesc_idx): Likewise.
	(initialize_low_arch): Don't call init_registers_x32_XXX and
	init_registers_amd64_XXX.
	* linux-x86-tdesc-selftest.c: Declare init_registers_amd64_XXX
	and tdesc_amd64_XXX.
	[__x86_64__] (amd64_tdesc_test): New function.
	(initialize_low_tdesc) [__x86_64__]: Call init_registers_x32_XXX
	and init_registers_amd64_XXX.
	* linux-x86-tdesc.c: Include feature c files.
	(amd64_get_ipa_tdesc): New function.
	(get_ipa_tdesc): Call amd64_get_ipa_tdesc.
	(amd64_get_ipa_tdesc_idx): New function.
	* linux-x86-tdesc.h (amd64_get_ipa_tdesc_idx): Declare.
	(amd64_get_ipa_tdesc): Declare.
---
 gdb/gdbserver/linux-amd64-ipa.c          |  56 ---------------
 gdb/gdbserver/linux-x86-low.c            |  56 ++++++---------
 gdb/gdbserver/linux-x86-tdesc-selftest.c | 100 +++++++++++++++++++++++++++
 gdb/gdbserver/linux-x86-tdesc.c          | 114 ++++++++++++++++++++++++++++++-
 gdb/gdbserver/linux-x86-tdesc.h          |  50 ++------------
 5 files changed, 237 insertions(+), 139 deletions(-)

diff --git a/gdb/gdbserver/linux-amd64-ipa.c b/gdb/gdbserver/linux-amd64-ipa.c
index 67f36c2..c96e93c 100644
--- a/gdb/gdbserver/linux-amd64-ipa.c
+++ b/gdb/gdbserver/linux-amd64-ipa.c
@@ -168,50 +168,6 @@ supply_static_tracepoint_registers (struct regcache *regcache,
 
 #endif /* HAVE_UST */
 
-/* Return target_desc to use for IPA, given the tdesc index passed by
-   gdbserver.  */
-
-const struct target_desc *
-get_ipa_tdesc (int idx)
-{
-#if defined __ILP32__
-  switch (idx)
-    {
-    case X86_TDESC_SSE:
-      return tdesc_x32_linux;
-    case X86_TDESC_AVX:
-      return tdesc_x32_avx_linux;
-    case X86_TDESC_AVX512:
-      return tdesc_x32_avx512_linux;
-    default:
-      break;
-    }
-#else
-  switch (idx)
-    {
-    case X86_TDESC_SSE:
-      return tdesc_amd64_linux;
-    case X86_TDESC_AVX:
-      return tdesc_amd64_avx_linux;
-    case X86_TDESC_MPX:
-      return tdesc_amd64_mpx_linux;
-    case X86_TDESC_AVX_MPX:
-      return tdesc_amd64_avx_mpx_linux;
-    case X86_TDESC_AVX_MPX_AVX512_PKU:
-      return tdesc_amd64_avx_mpx_avx512_pku_linux;
-    case X86_TDESC_AVX_AVX512:
-      return tdesc_amd64_avx_avx512_linux;
-    default:
-      internal_error (__FILE__, __LINE__,
-		      "unknown ipa tdesc index: %d", idx);
-      return tdesc_amd64_linux;
-    }
-#endif
-
-  internal_error (__FILE__, __LINE__,
-		  "unknown ipa tdesc index: %d", idx);
-}
-
 /* Allocate buffer for the jump pads.  The branch instruction has a
    reach of +/- 31-bit, and the executable is loaded at low addresses.
 
@@ -276,16 +232,4 @@ alloc_jump_pad_buffer (size_t size)
 void
 initialize_low_tracepoint (void)
 {
-#if defined __ILP32__
-  init_registers_x32_linux ();
-  init_registers_x32_avx_linux ();
-  init_registers_x32_avx512_linux ();
-#else
-  init_registers_amd64_linux ();
-  init_registers_amd64_avx_linux ();
-  init_registers_amd64_mpx_linux ();
-  init_registers_amd64_avx_mpx_linux ();
-  init_registers_amd64_avx_avx512_linux ();
-  init_registers_amd64_avx_mpx_avx512_pku_linux ();
-#endif
 }
diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c
index 7744d3b..fceaba2 100644
--- a/gdb/gdbserver/linux-x86-low.c
+++ b/gdb/gdbserver/linux-x86-low.c
@@ -824,26 +824,28 @@ x86_linux_read_description (void)
 	      switch (xcr0 & X86_XSTATE_ALL_MASK)
 	        {
 		case X86_XSTATE_AVX_MPX_AVX512_PKU_MASK:
-		  return tdesc_amd64_avx_mpx_avx512_pku_linux;
+		  return amd64_get_ipa_tdesc (X86_TDESC_AVX_MPX_AVX512_PKU,
+					      !is_elf64);
 
 		case X86_XSTATE_AVX_AVX512_MASK:
-		  return tdesc_amd64_avx_avx512_linux;
+		  return amd64_get_ipa_tdesc (X86_TDESC_AVX_AVX512,
+					      !is_elf64);
 
 		case X86_XSTATE_AVX_MPX_MASK:
-		  return tdesc_amd64_avx_mpx_linux;
+		  return amd64_get_ipa_tdesc (X86_TDESC_AVX_MPX, !is_elf64);
 
 		case X86_XSTATE_MPX_MASK:
-		  return tdesc_amd64_mpx_linux;
+		  return amd64_get_ipa_tdesc (X86_TDESC_MPX, !is_elf64);
 
 		case X86_XSTATE_AVX_MASK:
-		  return tdesc_amd64_avx_linux;
+		  return amd64_get_ipa_tdesc (X86_TDESC_AVX, !is_elf64);
 
 		default:
-		  return tdesc_amd64_linux;
+		  return amd64_get_ipa_tdesc (X86_TDESC_SSE, !is_elf64);
 		}
 	    }
 	  else
-	    return tdesc_amd64_linux;
+	    return amd64_get_ipa_tdesc (X86_TDESC_SSE, !is_elf64);
 	}
       else
 	{
@@ -853,21 +855,23 @@ x86_linux_read_description (void)
 	        {
 		case X86_XSTATE_AVX_MPX_AVX512_PKU_MASK:
 		  /* No x32 MPX and PKU, fall back to avx_avx512.  */
-		  return tdesc_x32_avx_avx512_linux;
+		  return amd64_get_ipa_tdesc (X86_TDESC_AVX_AVX512,
+					      !is_elf64);
 
 		case X86_XSTATE_AVX_AVX512_MASK:
-		  return tdesc_x32_avx_avx512_linux;
+		  return amd64_get_ipa_tdesc (X86_TDESC_AVX_AVX512,
+					      !is_elf64);
 
 		case X86_XSTATE_MPX_MASK: /* No MPX on x32.  */
 		case X86_XSTATE_AVX_MASK:
-		  return tdesc_x32_avx_linux;
+		  return amd64_get_ipa_tdesc (X86_TDESC_AVX, !is_elf64);
 
 		default:
-		  return tdesc_x32_linux;
+		  return amd64_get_ipa_tdesc (X86_TDESC_SSE, !is_elf64);
 		}
 	    }
 	  else
-	    return tdesc_x32_linux;
+	    return amd64_get_ipa_tdesc (X86_TDESC_SSE, !is_elf64);;
 	}
 #endif
     }
@@ -2897,19 +2901,7 @@ x86_get_ipa_tdesc_idx (void)
   const struct target_desc *tdesc = regcache->tdesc;
 
 #ifdef __x86_64__
-  if (tdesc == tdesc_amd64_linux || tdesc == tdesc_amd64_linux_no_xml
-      || tdesc == tdesc_x32_linux)
-    return X86_TDESC_SSE;
-  if (tdesc == tdesc_amd64_avx_linux || tdesc == tdesc_x32_avx_linux)
-    return X86_TDESC_AVX;
-  if (tdesc == tdesc_amd64_mpx_linux)
-    return X86_TDESC_MPX;
-  if (tdesc == tdesc_amd64_avx_mpx_linux)
-    return X86_TDESC_AVX_MPX;
-  if (tdesc == tdesc_amd64_avx_mpx_avx512_pku_linux || tdesc == tdesc_x32_avx_avx512_linux)
-    return X86_TDESC_AVX_MPX_AVX512_PKU;
-  if (tdesc == tdesc_amd64_avx_avx512_linux)
-    return X86_TDESC_AVX_AVX512;
+  return amd64_get_ipa_tdesc_idx (tdesc);
 #endif
 
   if (tdesc == tdesc_i386_linux_no_xml)
@@ -2969,19 +2961,9 @@ initialize_low_arch (void)
 {
   /* Initialize the Linux target descriptions.  */
 #ifdef __x86_64__
-  init_registers_amd64_linux ();
-  init_registers_amd64_avx_linux ();
-  init_registers_amd64_mpx_linux ();
-  init_registers_amd64_avx_mpx_linux ();
-  init_registers_amd64_avx_avx512_linux ();
-  init_registers_amd64_avx_mpx_avx512_pku_linux ();
-
-  init_registers_x32_linux ();
-  init_registers_x32_avx_linux ();
-  init_registers_x32_avx_avx512_linux ();
-
   tdesc_amd64_linux_no_xml = XNEW (struct target_desc);
-  copy_target_description (tdesc_amd64_linux_no_xml, tdesc_amd64_linux);
+  copy_target_description (tdesc_amd64_linux_no_xml,
+			   amd64_get_ipa_tdesc (X86_TDESC_SSE, false));
   tdesc_amd64_linux_no_xml->xmltarget = xmltarget_amd64_linux_no_xml;
 #endif
 
diff --git a/gdb/gdbserver/linux-x86-tdesc-selftest.c b/gdb/gdbserver/linux-x86-tdesc-selftest.c
index 31f5240..2b61d86 100644
--- a/gdb/gdbserver/linux-x86-tdesc-selftest.c
+++ b/gdb/gdbserver/linux-x86-tdesc-selftest.c
@@ -48,6 +48,46 @@ extern const struct target_desc *tdesc_i386_avx_mpx_avx512_pku_linux;
 void init_registers_i386_mpx_linux (void);
 extern const struct target_desc *tdesc_i386_mpx_linux;
 
+#ifdef __x86_64__
+
+/* Defined in auto-generated file amd64-linux.c.  */
+void init_registers_amd64_linux (void);
+extern const struct target_desc *tdesc_amd64_linux;
+
+/* Defined in auto-generated file amd64-avx-linux.c.  */
+void init_registers_amd64_avx_linux (void);
+extern const struct target_desc *tdesc_amd64_avx_linux;
+
+/* Defined in auto-generated file amd64-avx-avx512-linux.c.  */
+void init_registers_amd64_avx_avx512_linux (void);
+extern const struct target_desc *tdesc_amd64_avx_avx512_linux;
+
+/* Defined in auto-generated file amd64-avx-mpx-avx512-pku-linux.c.  */
+void init_registers_amd64_avx_mpx_avx512_pku_linux (void);
+extern const struct target_desc *tdesc_amd64_avx_mpx_avx512_pku_linux;
+
+/* Defined in auto-generated file amd64-avx-mpx-linux.c.  */
+void init_registers_amd64_avx_mpx_linux (void);
+extern const struct target_desc *tdesc_amd64_avx_mpx_linux;
+
+/* Defined in auto-generated file amd64-mpx-linux.c.  */
+void init_registers_amd64_mpx_linux (void);
+extern const struct target_desc *tdesc_amd64_mpx_linux;
+
+/* Defined in auto-generated file x32-linux.c.  */
+void init_registers_x32_linux (void);
+extern const struct target_desc *tdesc_x32_linux;
+
+/* Defined in auto-generated file x32-avx-linux.c.  */
+void init_registers_x32_avx_linux (void);
+extern const struct target_desc *tdesc_x32_avx_linux;
+
+/* Defined in auto-generated file x32-avx-avx512-linux.c.  */
+void init_registers_x32_avx_avx512_linux (void);
+extern const struct target_desc *tdesc_x32_avx_avx512_linux;
+
+#endif
+
 namespace selftests {
 namespace gdbserver {
 static void
@@ -82,6 +122,51 @@ i386_tdesc_test ()
   SELF_CHECK (*tdesc == *tdesc_i386_avx_mpx_avx512_pku_linux);
   delete tdesc;
 }
+
+#ifdef __x86_64__
+
+static void
+amd64_tdesc_test ()
+{
+  const struct target_desc *tdesc = amd64_get_ipa_tdesc (X86_TDESC_SSE, false);
+
+  SELF_CHECK (*tdesc == *tdesc_amd64_linux);
+  delete tdesc;
+
+  tdesc = amd64_get_ipa_tdesc (X86_TDESC_AVX, false);
+  SELF_CHECK (*tdesc == *tdesc_amd64_avx_linux);
+  delete tdesc;
+
+  tdesc = amd64_get_ipa_tdesc (X86_TDESC_AVX_AVX512, false);
+  SELF_CHECK (*tdesc == *tdesc_amd64_avx_avx512_linux);
+  delete tdesc;
+
+  tdesc = amd64_get_ipa_tdesc (X86_TDESC_MPX, false);
+  SELF_CHECK (*tdesc == *tdesc_amd64_mpx_linux);
+  delete tdesc;
+
+  tdesc = amd64_get_ipa_tdesc (X86_TDESC_AVX_MPX, false);
+  SELF_CHECK (*tdesc == *tdesc_amd64_avx_mpx_linux);
+  delete tdesc;
+
+  tdesc = amd64_get_ipa_tdesc (X86_TDESC_AVX_MPX_AVX512_PKU, false);
+  SELF_CHECK (*tdesc == *tdesc_amd64_avx_mpx_avx512_pku_linux);
+  delete tdesc;
+
+  tdesc = amd64_get_ipa_tdesc (X86_TDESC_SSE, true);
+  SELF_CHECK (*tdesc == *tdesc_x32_linux);
+  delete tdesc;
+
+  tdesc = amd64_get_ipa_tdesc (X86_TDESC_AVX, true);
+  SELF_CHECK (*tdesc == *tdesc_x32_avx_linux);
+  delete tdesc;
+
+  tdesc = amd64_get_ipa_tdesc (X86_TDESC_AVX_AVX512, true);
+  SELF_CHECK (*tdesc == *tdesc_x32_avx_avx512_linux);
+  delete tdesc;
+}
+
+#endif
 }
 } // namespace selftests
 
@@ -97,4 +182,19 @@ initialize_low_tdesc ()
   init_registers_i386_avx_mpx_avx512_pku_linux ();
 
   register_self_test (selftests::gdbserver::i386_tdesc_test);
+
+#ifdef __x86_64__
+  init_registers_x32_linux ();
+  init_registers_x32_avx_linux ();
+  init_registers_x32_avx_avx512_linux ();
+
+  init_registers_amd64_linux ();
+  init_registers_amd64_avx_linux ();
+  init_registers_amd64_mpx_linux ();
+  init_registers_amd64_avx_mpx_linux ();
+  init_registers_amd64_avx_avx512_linux ();
+  init_registers_amd64_avx_mpx_avx512_pku_linux ();
+
+  register_self_test (selftests::gdbserver::amd64_tdesc_test);
+#endif
 }
diff --git a/gdb/gdbserver/linux-x86-tdesc.c b/gdb/gdbserver/linux-x86-tdesc.c
index 2e4079a..44faf5d 100644
--- a/gdb/gdbserver/linux-x86-tdesc.c
+++ b/gdb/gdbserver/linux-x86-tdesc.c
@@ -29,6 +29,19 @@
 #include "../features/i386/32bit-mpx.c"
 #include "../features/i386/32bit-pkeys.c"
 
+#ifdef __x86_64__
+#include "../features/i386/64bit-avx.c"
+#include "../features/i386/64bit-avx512.c"
+#include "../features/i386/64bit-core.c"
+#include "../features/i386/64bit-linux.c"
+#include "../features/i386/64bit-mpx.c"
+#include "../features/i386/64bit-pkeys.c"
+#include "../features/i386/64bit-segments.c"
+#include "../features/i386/64bit-sse.c"
+
+#include "../features/i386/x32-core.c"
+#endif
+
 static const struct target_desc *i386_tdescs[X86_TDESC_LAST] = { };
 
 const struct target_desc *
@@ -84,15 +97,91 @@ i386_get_ipa_tdesc (int idx)
   return *tdesc;;
 }
 
+#ifdef __x86_64__
+
+static const struct target_desc *amd64_tdescs[X86_TDESC_LAST] = { };
+static const struct target_desc *x32_tdescs[X86_TDESC_LAST] = { };
+
+const struct target_desc *
+amd64_get_ipa_tdesc (int idx, bool is_x32)
+{
+  if (idx >= X86_TDESC_LAST)
+    internal_error (__FILE__, __LINE__, "unknown ipa tdesc index: %d", idx);
+
+  struct target_desc **tdesc;
+
+  if (is_x32 && idx != X86_TDESC_SSE && idx != X86_TDESC_AVX
+      && idx != X86_TDESC_AVX_AVX512)
+    internal_error (__FILE__, __LINE__, "unknown ipa tdesc index: %d", idx);
+
+  if (is_x32)
+    tdesc = (struct target_desc **) &x32_tdescs[idx];
+  else
+    tdesc = (struct target_desc **) &amd64_tdescs[idx];
+
+  if (*tdesc == NULL)
+    {
+      *tdesc = new target_desc ();
+
+#ifndef IN_PROCESS_AGENT
+      set_tdesc_architecture (*tdesc, is_x32 ? "i386:x64-32" : "i386:x86-64");
+      set_tdesc_osabi (*tdesc, "GNU/Linux");
+#endif
+
+      long regnum = 0;
+
+      if (is_x32)
+	regnum = create_feature_i386_x32_core (*tdesc, regnum);
+      else
+	regnum = create_feature_i386_64bit_core (*tdesc, regnum);
+
+      regnum = create_feature_i386_64bit_sse (*tdesc, regnum);
+      regnum = create_feature_i386_64bit_linux (*tdesc, regnum);
+      regnum = create_feature_i386_64bit_segments (*tdesc, regnum);
+
+      if (idx == X86_TDESC_AVX || idx == X86_TDESC_AVX_MPX
+	  || idx == X86_TDESC_AVX_AVX512
+	  || idx == X86_TDESC_AVX_MPX_AVX512_PKU)
+	regnum = create_feature_i386_64bit_avx (*tdesc, regnum);
+
+      if (idx == X86_TDESC_MPX || idx == X86_TDESC_AVX_MPX
+	  || idx == X86_TDESC_AVX_MPX_AVX512_PKU)
+	regnum = create_feature_i386_64bit_mpx (*tdesc, regnum);
+
+      if (idx == X86_TDESC_AVX_AVX512
+	  || idx == X86_TDESC_AVX_MPX_AVX512_PKU)
+	regnum = create_feature_i386_64bit_avx512 (*tdesc, regnum);
+
+      if (idx == X86_TDESC_AVX_MPX_AVX512_PKU)
+	regnum = create_feature_i386_64bit_pkeys (*tdesc, regnum);
+
+      init_target_desc (*tdesc);
+
+#ifndef IN_PROCESS_AGENT
+      static const char *expedite_regs_amd64[] = { "rbp", "rsp", "rip", NULL };
+      (*tdesc)->expedite_regs = expedite_regs_amd64;
+#endif
+    }
+  return *tdesc;;
+}
+
+#endif
+
 #ifdef IN_PROCESS_AGENT
 
-#if defined __i386__
 const struct target_desc *
 get_ipa_tdesc (int idx)
 {
-return i386_get_ipa_tdesc (idx);
-}
+#if defined __i386__
+  return i386_get_ipa_tdesc (idx);
+#else
+#if defined __ILP32__
+  return amd64_get_ipa_tdesc (idx, true);
+#else
+  return amd64_get_ipa_tdesc (idx, false);
+#endif
 #endif
+}
 
 #else
 int
@@ -107,4 +196,23 @@ i386_get_ipa_tdesc_idx (const struct target_desc *tdesc)
   return 0;
 }
 
+#if defined __x86_64__
+int
+amd64_get_ipa_tdesc_idx (const struct target_desc *tdesc)
+{
+  for (int i = 0; i < X86_TDESC_LAST; i++)
+    {
+      if (tdesc == amd64_tdescs[i])
+	return i;
+    }
+  for (int i = 0; i < X86_TDESC_LAST; i++)
+    {
+      if (tdesc == x32_tdescs[i])
+	return i;
+    }
+
+  return 0;
+}
+
+#endif
 #endif
diff --git a/gdb/gdbserver/linux-x86-tdesc.h b/gdb/gdbserver/linux-x86-tdesc.h
index 894cf4e..2636efc 100644
--- a/gdb/gdbserver/linux-x86-tdesc.h
+++ b/gdb/gdbserver/linux-x86-tdesc.h
@@ -33,54 +33,18 @@ enum x86_linux_tdesc {
   X86_TDESC_LAST = 7,
 };
 
-#ifdef __x86_64__
-
-#if defined __LP64__  || !defined IN_PROCESS_AGENT
-/* Defined in auto-generated file amd64-linux.c.  */
-void init_registers_amd64_linux (void);
-extern const struct target_desc *tdesc_amd64_linux;
-
-/* Defined in auto-generated file amd64-avx-linux.c.  */
-void init_registers_amd64_avx_linux (void);
-extern const struct target_desc *tdesc_amd64_avx_linux;
-
-/* Defined in auto-generated file amd64-avx-avx512-linux.c.  */
-void init_registers_amd64_avx_avx512_linux (void);
-extern const struct target_desc *tdesc_amd64_avx_avx512_linux;
-
-/* Defined in auto-generated file amd64-avx-mpx-avx512-pku-linux.c.  */
-void init_registers_amd64_avx_mpx_avx512_pku_linux (void);
-extern const struct target_desc *tdesc_amd64_avx_mpx_avx512_pku_linux;
-
-/* Defined in auto-generated file amd64-avx-mpx-linux.c.  */
-void init_registers_amd64_avx_mpx_linux (void);
-extern const struct target_desc *tdesc_amd64_avx_mpx_linux;
-
-/* Defined in auto-generated file amd64-mpx-linux.c.  */
-void init_registers_amd64_mpx_linux (void);
-extern const struct target_desc *tdesc_amd64_mpx_linux;
+#if defined __i386__ || !defined IN_PROCESS_AGENT
+int i386_get_ipa_tdesc_idx (const struct target_desc *tdesc);
 #endif
 
-#if defined __ILP32__ || !defined IN_PROCESS_AGENT
-/* Defined in auto-generated file x32-linux.c.  */
-void init_registers_x32_linux (void);
-extern const struct target_desc *tdesc_x32_linux;
-
-/* Defined in auto-generated file x32-avx-linux.c.  */
-void init_registers_x32_avx_linux (void);
-extern const struct target_desc *tdesc_x32_avx_linux;
-
-/* Defined in auto-generated file x32-avx-avx512-linux.c.  */
-void init_registers_x32_avx_avx512_linux (void);
-extern const struct target_desc *tdesc_x32_avx_avx512_linux;
+#if defined __x86_64__ && !defined IN_PROCESS_AGENT
+int amd64_get_ipa_tdesc_idx (const struct target_desc *tdesc);
 #endif
 
-#endif
+const struct target_desc *i386_get_ipa_tdesc (int idx);
 
-#if defined __i386__ || !defined IN_PROCESS_AGENT
-int i386_get_ipa_tdesc_idx (const struct target_desc *tdesc);
+#ifdef __x86_64__
+const struct target_desc *amd64_get_ipa_tdesc (int idx, bool is_x32);
 #endif
 
-const struct target_desc *i386_get_ipa_tdesc (int idx);
-
 void initialize_low_tdesc ();
-- 
1.9.1

^ permalink raw reply	[flat|nested] 82+ messages in thread

* [PATCH 04/25] Centralize i386 linux target descriptions
  2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
@ 2017-06-12  8:42 ` Yao Qi
  2017-06-19 21:27   ` Simon Marchi
  2017-06-12  8:42 ` [PATCH 06/25] Generate c for feature instead of tdesc Yao Qi
                   ` (25 subsequent siblings)
  26 siblings, 1 reply; 82+ messages in thread
From: Yao Qi @ 2017-06-12  8:42 UTC (permalink / raw)
  To: gdb-patches

This patch moves all the tdesc_i386*_linux target descriptions to a
function i386_linux_read_description, which returns the right target
description according to xcr0.  This also remove the duplication in
getting target descriptions in corefile and native target.

gdb:

2017-04-27  Yao Qi  <yao.qi@linaro.org>

	* i386-linux-tdep.c (i386_linux_read_description): New function.
	(i386_linux_core_read_description): Call
	i386_linux_read_description.
	* i386-linux-tdep.h (i386_linux_read_description): Declare.
	(tdesc_i386_linux, tdesc_i386_mmx_linux): Remove declarations.
	(tdesc_i386_avx_linux, tdesc_i386_mpx_linux): Likewise
	(tdesc_i386_avx_mpx_linux, tdesc_i386_avx_avx512_linux): Likewise.
	(tdesc_i386_avx_mpx_avx512_pku_linux): Likewise.
	* x86-linux-nat.c (x86_linux_read_description): Call
	i386_linux_read_description.
---
 gdb/i386-linux-tdep.c | 34 ++++++++++++++++++++++------------
 gdb/i386-linux-tdep.h | 10 ++--------
 gdb/x86-linux-nat.c   | 24 ++++++++----------------
 3 files changed, 32 insertions(+), 36 deletions(-)

diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c
index 1909d61..1bc1a6f 100644
--- a/gdb/i386-linux-tdep.c
+++ b/gdb/i386-linux-tdep.c
@@ -678,16 +678,9 @@ i386_linux_core_read_xcr0 (bfd *abfd)
   return xcr0;
 }
 
-/* Get Linux/x86 target description from core dump.  */
-
-static const struct target_desc *
-i386_linux_core_read_description (struct gdbarch *gdbarch,
-				  struct target_ops *target,
-				  bfd *abfd)
+const struct target_desc *
+i386_linux_read_description (uint64_t xcr0)
 {
-  /* Linux/i386.  */
-  uint64_t xcr0 = i386_linux_core_read_xcr0 (abfd);
-
   switch ((xcr0 & X86_XSTATE_ALL_MASK))
     {
     case X86_XSTATE_AVX_MPX_AVX512_PKU_MASK:
@@ -708,10 +701,27 @@ i386_linux_core_read_description (struct gdbarch *gdbarch,
       break;
     }
 
+  return NULL;
+}
+
+/* Get Linux/x86 target description from core dump.  */
+
+static const struct target_desc *
+i386_linux_core_read_description (struct gdbarch *gdbarch,
+				  struct target_ops *target,
+				  bfd *abfd)
+{
+  /* Linux/i386.  */
+  uint64_t xcr0 = i386_linux_core_read_xcr0 (abfd);
+  const struct target_desc * tdesc = i386_linux_read_description (xcr0);
+
+  if (tdesc != NULL)
+    return tdesc;
+
   if (bfd_get_section_by_name (abfd, ".reg-xfp") != NULL)
-    return tdesc_i386_linux;
+    return i386_linux_read_description (X86_XSTATE_SSE_MASK);
   else
-    return tdesc_i386_mmx_linux;
+    return i386_linux_read_description (X86_XSTATE_X87_MASK);
 }
 
 /* Similar to i386_supply_fpregset, but use XSAVE extended state.  */
@@ -835,7 +845,7 @@ i386_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   set_gdbarch_num_regs (gdbarch, I386_LINUX_NUM_REGS);
 
   if (! tdesc_has_registers (tdesc))
-    tdesc = tdesc_i386_linux;
+    tdesc = i386_linux_read_description (X86_XSTATE_SSE_MASK);
   tdep->tdesc = tdesc;
 
   feature = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.linux");
diff --git a/gdb/i386-linux-tdep.h b/gdb/i386-linux-tdep.h
index 8d4c7ca..1ca8d6b 100644
--- a/gdb/i386-linux-tdep.h
+++ b/gdb/i386-linux-tdep.h
@@ -42,14 +42,8 @@ extern uint64_t i386_linux_core_read_xcr0 (bfd *abfd);
 extern void i386_linux_handle_segmentation_fault (struct gdbarch *gdbarch,
 						  struct ui_out *uiout);
 
-/* Linux target description.  */
-extern struct target_desc *tdesc_i386_linux;
-extern struct target_desc *tdesc_i386_mmx_linux;
-extern struct target_desc *tdesc_i386_avx_linux;
-extern struct target_desc *tdesc_i386_mpx_linux;
-extern struct target_desc *tdesc_i386_avx_mpx_linux;
-extern struct target_desc *tdesc_i386_avx_avx512_linux;
-extern struct target_desc *tdesc_i386_avx_mpx_avx512_pku_linux;
+/* Return the target description according to XCR0.  */
+extern const struct target_desc *i386_linux_read_description (uint64_t xcr0);
 
 /* Format of XSAVE extended state is:
  	struct
diff --git a/gdb/x86-linux-nat.c b/gdb/x86-linux-nat.c
index 7362282..2c4afb1 100644
--- a/gdb/x86-linux-nat.c
+++ b/gdb/x86-linux-nat.c
@@ -153,7 +153,7 @@ x86_linux_read_description (struct target_ops *ops)
 	{
 	  have_ptrace_getfpxregs = 0;
 	  have_ptrace_getregset = TRIBOOL_FALSE;
-	  return tdesc_i386_mmx_linux;
+	  return i386_linux_read_description (X86_XSTATE_X87_MASK);
 	}
     }
 #endif
@@ -230,21 +230,13 @@ x86_linux_read_description (struct target_ops *ops)
     }
   else
     {
-      switch (xcr0_features_bits)
-	{
-	case X86_XSTATE_AVX_MPX_AVX512_PKU_MASK:
-	  return tdesc_i386_avx_mpx_avx512_pku_linux;
-	case X86_XSTATE_AVX_AVX512_MASK:
-	  return tdesc_i386_avx_avx512_linux;
-	case X86_XSTATE_MPX_MASK:
-	  return tdesc_i386_mpx_linux;
-	case X86_XSTATE_AVX_MPX_MASK:
-	  return tdesc_i386_avx_mpx_linux;
-	case X86_XSTATE_AVX_MASK:
-	  return tdesc_i386_avx_linux;
-	default:
-	  return tdesc_i386_linux;
-	}
+      const struct target_desc * tdesc
+	= i386_linux_read_description (xcr0_features_bits);
+
+      if (tdesc == NULL)
+	tdesc = i386_linux_read_description (X86_XSTATE_SSE_MASK);
+
+      return tdesc;
     }
 
   gdb_assert_not_reached ("failed to return tdesc");
-- 
1.9.1

^ permalink raw reply	[flat|nested] 82+ messages in thread

* [PATCH 05/25] Use visitor pattern for "maint print c-tdesc"
  2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
                   ` (6 preceding siblings ...)
  2017-06-12  8:42 ` [PATCH 08/25] Add "maint check xml-descriptions" to test builtin xml target descriptions Yao Qi
@ 2017-06-12  8:42 ` Yao Qi
  2017-06-20 23:37   ` Simon Marchi
  2017-06-12  8:42 ` [PATCH 17/25] Remove features/i386/i386-*linux.c Yao Qi
                   ` (18 subsequent siblings)
  26 siblings, 1 reply; 82+ messages in thread
From: Yao Qi @ 2017-06-12  8:42 UTC (permalink / raw)
  To: gdb-patches

Target description can be modeled as a tree, the target description
is the root node, features are children nodes, registers and types are
grand-children nodes.  So command "maint print c-tdesc" in effect
traverse/visit each node, and print them in c.  This can be
implemented by visitor pattern, this is the first reason.  Secondly,
I want to this command prints c files in a different way for some
specific xml files, but still print c files the same way for the rest
of xml files.  Third, I even want to print xml files from target
descriptions, so that GDBserver can use it to reply GDB's query
qXfer:features:read:target.xml.

After this change, all features/*.c should be re-generated, but
this patch only includes part changes features/*.c files.

gdb:

2017-05-25  Yao Qi  <yao.qi@linaro.org>

	* target-descriptions.c (tdesc_element_visitor): New class.
	(tdesc_element): New class.
	(tdesc_reg): Inherit from tdesc_element.
	(tdesc_reg::accept): New function.
	(tdesc_type): Inherit from tdesc_element.
	(tdesc_type::accept): New function.
	(tdesc_feature): Inherit from tdesc_element.
	(tdesc_feature::accept): New function.
	(target_desc): Inherit from tdesc_element.
	(target_desc::target_desc): New.
	(target_desc::~target_desc): New.
	(target_desc::accept): New.
	(allocate_target_description): Use new.
	(free_target_description): Use delete.
	(print_c_tdesc): New class.
	(maint_print_c_tdesc_cmd): Adjust.

	* features/i386/i386-avx-avx512-linux.c: Re-generated.
	* features/i386/i386-avx-linux.c: Re-generated.
	* features/i386/i386-avx-mpx-avx512-pku-linux.c: Re-generated.
	* features/i386/i386-avx-mpx-linux.c: Re-generated.
	* features/i386/i386-linux.c: Re-generated.
	* features/i386/i386-mmx-linux.c: Re-generated.
---
 gdb/features/i386/i386-avx-avx512-linux.c         |   8 +-
 gdb/features/i386/i386-avx-avx512.c               |   8 +-
 gdb/features/i386/i386-avx-linux.c                |   8 +-
 gdb/features/i386/i386-avx-mpx-avx512-pku-linux.c |   8 +-
 gdb/features/i386/i386-avx-mpx-avx512-pku.c       |   8 +-
 gdb/features/i386/i386-avx-mpx-linux.c            |   8 +-
 gdb/features/i386/i386-avx-mpx.c                  |   8 +-
 gdb/features/i386/i386-avx.c                      |   8 +-
 gdb/features/i386/i386-linux.c                    |   8 +-
 gdb/features/i386/i386-mmx-linux.c                |   8 +-
 gdb/features/i386/i386-mmx.c                      |   8 +-
 gdb/features/i386/i386-mpx-linux.c                |   8 +-
 gdb/features/i386/i386-mpx.c                      |   8 +-
 gdb/features/i386/i386.c                          |   8 +-
 gdb/target-descriptions.c                         | 657 ++++++++++++----------
 15 files changed, 427 insertions(+), 342 deletions(-)

diff --git a/gdb/features/i386/i386-avx-avx512-linux.c b/gdb/features/i386/i386-avx-avx512-linux.c
index 81149d5..545149d 100644
--- a/gdb/features/i386/i386-avx-avx512-linux.c
+++ b/gdb/features/i386/i386-avx-avx512-linux.c
@@ -10,15 +10,15 @@ static void
 initialize_tdesc_i386_avx_avx512_linux (void)
 {
   struct target_desc *result = allocate_target_description ();
-  struct tdesc_feature *feature;
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-
   set_tdesc_architecture (result, bfd_scan_arch ("i386"));
 
   set_tdesc_osabi (result, osabi_from_tdesc_string ("GNU/Linux"));
 
+  struct tdesc_feature *feature;
+
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
   type = tdesc_create_flags (feature, "i386_eflags", 4);
   tdesc_add_flag (type, 0, "CF");
   tdesc_add_flag (type, 1, "");
diff --git a/gdb/features/i386/i386-avx-avx512.c b/gdb/features/i386/i386-avx-avx512.c
index 1075ca0..585a0ac 100644
--- a/gdb/features/i386/i386-avx-avx512.c
+++ b/gdb/features/i386/i386-avx-avx512.c
@@ -10,13 +10,13 @@ static void
 initialize_tdesc_i386_avx_avx512 (void)
 {
   struct target_desc *result = allocate_target_description ();
-  struct tdesc_feature *feature;
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-
   set_tdesc_architecture (result, bfd_scan_arch ("i386"));
 
+  struct tdesc_feature *feature;
+
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
   type = tdesc_create_flags (feature, "i386_eflags", 4);
   tdesc_add_flag (type, 0, "CF");
   tdesc_add_flag (type, 1, "");
diff --git a/gdb/features/i386/i386-avx-linux.c b/gdb/features/i386/i386-avx-linux.c
index 4a8c6b5..3ef087d 100644
--- a/gdb/features/i386/i386-avx-linux.c
+++ b/gdb/features/i386/i386-avx-linux.c
@@ -10,15 +10,15 @@ static void
 initialize_tdesc_i386_avx_linux (void)
 {
   struct target_desc *result = allocate_target_description ();
-  struct tdesc_feature *feature;
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-
   set_tdesc_architecture (result, bfd_scan_arch ("i386"));
 
   set_tdesc_osabi (result, osabi_from_tdesc_string ("GNU/Linux"));
 
+  struct tdesc_feature *feature;
+
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
   type = tdesc_create_flags (feature, "i386_eflags", 4);
   tdesc_add_flag (type, 0, "CF");
   tdesc_add_flag (type, 1, "");
diff --git a/gdb/features/i386/i386-avx-mpx-avx512-pku-linux.c b/gdb/features/i386/i386-avx-mpx-avx512-pku-linux.c
index f90c834..e6eebf1 100644
--- a/gdb/features/i386/i386-avx-mpx-avx512-pku-linux.c
+++ b/gdb/features/i386/i386-avx-mpx-avx512-pku-linux.c
@@ -10,15 +10,15 @@ static void
 initialize_tdesc_i386_avx_mpx_avx512_pku_linux (void)
 {
   struct target_desc *result = allocate_target_description ();
-  struct tdesc_feature *feature;
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-
   set_tdesc_architecture (result, bfd_scan_arch ("i386"));
 
   set_tdesc_osabi (result, osabi_from_tdesc_string ("GNU/Linux"));
 
+  struct tdesc_feature *feature;
+
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
   type = tdesc_create_flags (feature, "i386_eflags", 4);
   tdesc_add_flag (type, 0, "CF");
   tdesc_add_flag (type, 1, "");
diff --git a/gdb/features/i386/i386-avx-mpx-avx512-pku.c b/gdb/features/i386/i386-avx-mpx-avx512-pku.c
index 08d9b4b..d7dd3bb 100644
--- a/gdb/features/i386/i386-avx-mpx-avx512-pku.c
+++ b/gdb/features/i386/i386-avx-mpx-avx512-pku.c
@@ -10,13 +10,13 @@ static void
 initialize_tdesc_i386_avx_mpx_avx512_pku (void)
 {
   struct target_desc *result = allocate_target_description ();
-  struct tdesc_feature *feature;
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-
   set_tdesc_architecture (result, bfd_scan_arch ("i386"));
 
+  struct tdesc_feature *feature;
+
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
   type = tdesc_create_flags (feature, "i386_eflags", 4);
   tdesc_add_flag (type, 0, "CF");
   tdesc_add_flag (type, 1, "");
diff --git a/gdb/features/i386/i386-avx-mpx-linux.c b/gdb/features/i386/i386-avx-mpx-linux.c
index 4b27bfc..f62c487 100644
--- a/gdb/features/i386/i386-avx-mpx-linux.c
+++ b/gdb/features/i386/i386-avx-mpx-linux.c
@@ -10,15 +10,15 @@ static void
 initialize_tdesc_i386_avx_mpx_linux (void)
 {
   struct target_desc *result = allocate_target_description ();
-  struct tdesc_feature *feature;
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-
   set_tdesc_architecture (result, bfd_scan_arch ("i386"));
 
   set_tdesc_osabi (result, osabi_from_tdesc_string ("GNU/Linux"));
 
+  struct tdesc_feature *feature;
+
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
   type = tdesc_create_flags (feature, "i386_eflags", 4);
   tdesc_add_flag (type, 0, "CF");
   tdesc_add_flag (type, 1, "");
diff --git a/gdb/features/i386/i386-avx-mpx.c b/gdb/features/i386/i386-avx-mpx.c
index b27b40a..f479bda 100644
--- a/gdb/features/i386/i386-avx-mpx.c
+++ b/gdb/features/i386/i386-avx-mpx.c
@@ -10,13 +10,13 @@ static void
 initialize_tdesc_i386_avx_mpx (void)
 {
   struct target_desc *result = allocate_target_description ();
-  struct tdesc_feature *feature;
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-
   set_tdesc_architecture (result, bfd_scan_arch ("i386"));
 
+  struct tdesc_feature *feature;
+
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
   type = tdesc_create_flags (feature, "i386_eflags", 4);
   tdesc_add_flag (type, 0, "CF");
   tdesc_add_flag (type, 1, "");
diff --git a/gdb/features/i386/i386-avx.c b/gdb/features/i386/i386-avx.c
index 1cb0f9e..f888335 100644
--- a/gdb/features/i386/i386-avx.c
+++ b/gdb/features/i386/i386-avx.c
@@ -10,13 +10,13 @@ static void
 initialize_tdesc_i386_avx (void)
 {
   struct target_desc *result = allocate_target_description ();
-  struct tdesc_feature *feature;
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-
   set_tdesc_architecture (result, bfd_scan_arch ("i386"));
 
+  struct tdesc_feature *feature;
+
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
   type = tdesc_create_flags (feature, "i386_eflags", 4);
   tdesc_add_flag (type, 0, "CF");
   tdesc_add_flag (type, 1, "");
diff --git a/gdb/features/i386/i386-linux.c b/gdb/features/i386/i386-linux.c
index c7796c3..0394842 100644
--- a/gdb/features/i386/i386-linux.c
+++ b/gdb/features/i386/i386-linux.c
@@ -10,15 +10,15 @@ static void
 initialize_tdesc_i386_linux (void)
 {
   struct target_desc *result = allocate_target_description ();
-  struct tdesc_feature *feature;
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-
   set_tdesc_architecture (result, bfd_scan_arch ("i386"));
 
   set_tdesc_osabi (result, osabi_from_tdesc_string ("GNU/Linux"));
 
+  struct tdesc_feature *feature;
+
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
   type = tdesc_create_flags (feature, "i386_eflags", 4);
   tdesc_add_flag (type, 0, "CF");
   tdesc_add_flag (type, 1, "");
diff --git a/gdb/features/i386/i386-mmx-linux.c b/gdb/features/i386/i386-mmx-linux.c
index e53b55f..1577972 100644
--- a/gdb/features/i386/i386-mmx-linux.c
+++ b/gdb/features/i386/i386-mmx-linux.c
@@ -10,15 +10,15 @@ static void
 initialize_tdesc_i386_mmx_linux (void)
 {
   struct target_desc *result = allocate_target_description ();
-  struct tdesc_feature *feature;
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-
   set_tdesc_architecture (result, bfd_scan_arch ("i386"));
 
   set_tdesc_osabi (result, osabi_from_tdesc_string ("GNU/Linux"));
 
+  struct tdesc_feature *feature;
+
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
   type = tdesc_create_flags (feature, "i386_eflags", 4);
   tdesc_add_flag (type, 0, "CF");
   tdesc_add_flag (type, 1, "");
diff --git a/gdb/features/i386/i386-mmx.c b/gdb/features/i386/i386-mmx.c
index 74f67ed..02aee89 100644
--- a/gdb/features/i386/i386-mmx.c
+++ b/gdb/features/i386/i386-mmx.c
@@ -10,13 +10,13 @@ static void
 initialize_tdesc_i386_mmx (void)
 {
   struct target_desc *result = allocate_target_description ();
-  struct tdesc_feature *feature;
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-
   set_tdesc_architecture (result, bfd_scan_arch ("i386"));
 
+  struct tdesc_feature *feature;
+
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
   type = tdesc_create_flags (feature, "i386_eflags", 4);
   tdesc_add_flag (type, 0, "CF");
   tdesc_add_flag (type, 1, "");
diff --git a/gdb/features/i386/i386-mpx-linux.c b/gdb/features/i386/i386-mpx-linux.c
index 43ea192..6dea8e0 100644
--- a/gdb/features/i386/i386-mpx-linux.c
+++ b/gdb/features/i386/i386-mpx-linux.c
@@ -10,15 +10,15 @@ static void
 initialize_tdesc_i386_mpx_linux (void)
 {
   struct target_desc *result = allocate_target_description ();
-  struct tdesc_feature *feature;
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-
   set_tdesc_architecture (result, bfd_scan_arch ("i386"));
 
   set_tdesc_osabi (result, osabi_from_tdesc_string ("GNU/Linux"));
 
+  struct tdesc_feature *feature;
+
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
   type = tdesc_create_flags (feature, "i386_eflags", 4);
   tdesc_add_flag (type, 0, "CF");
   tdesc_add_flag (type, 1, "");
diff --git a/gdb/features/i386/i386-mpx.c b/gdb/features/i386/i386-mpx.c
index e832d2e..d08441b 100644
--- a/gdb/features/i386/i386-mpx.c
+++ b/gdb/features/i386/i386-mpx.c
@@ -10,13 +10,13 @@ static void
 initialize_tdesc_i386_mpx (void)
 {
   struct target_desc *result = allocate_target_description ();
-  struct tdesc_feature *feature;
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-
   set_tdesc_architecture (result, bfd_scan_arch ("i386"));
 
+  struct tdesc_feature *feature;
+
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
   type = tdesc_create_flags (feature, "i386_eflags", 4);
   tdesc_add_flag (type, 0, "CF");
   tdesc_add_flag (type, 1, "");
diff --git a/gdb/features/i386/i386.c b/gdb/features/i386/i386.c
index ede73fc..eb9a266 100644
--- a/gdb/features/i386/i386.c
+++ b/gdb/features/i386/i386.c
@@ -10,13 +10,13 @@ static void
 initialize_tdesc_i386 (void)
 {
   struct target_desc *result = allocate_target_description ();
-  struct tdesc_feature *feature;
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-
   set_tdesc_architecture (result, bfd_scan_arch ("i386"));
 
+  struct tdesc_feature *feature;
+
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
   type = tdesc_create_flags (feature, "i386_eflags", 4);
   tdesc_add_flag (type, 0, "CF");
   tdesc_add_flag (type, 1, "");
diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
index e2dcd1d..ac19792 100644
--- a/gdb/target-descriptions.c
+++ b/gdb/target-descriptions.c
@@ -35,6 +35,23 @@
 #include "hashtab.h"
 #include "inferior.h"
 
+class tdesc_element_visitor
+{
+public:
+  virtual void visit (const target_desc *e) = 0;
+  virtual void visit_end (const target_desc *e) = 0;
+
+  virtual void visit (const tdesc_feature *e) = 0;
+  virtual void visit (const tdesc_type *e) = 0;
+  virtual void visit (const tdesc_reg *e) = 0;
+};
+
+class tdesc_element
+{
+public:
+  virtual void accept (tdesc_element_visitor &v) const = 0;
+};
+
 /* Types.  */
 
 typedef struct property
@@ -46,7 +63,7 @@ DEF_VEC_O(property_s);
 
 /* An individual register from a target description.  */
 
-typedef struct tdesc_reg
+typedef struct tdesc_reg : tdesc_element
 {
 public:
   tdesc_reg (struct tdesc_feature *feature, const char *name_,
@@ -63,7 +80,7 @@ public:
     tdesc_type = tdesc_named_type (feature, type);
   }
 
-  ~tdesc_reg ()
+  virtual ~tdesc_reg ()
   {
     xfree (name);
     xfree (type);
@@ -107,6 +124,12 @@ public:
 
   /* The target-described type corresponding to TYPE, if found.  */
   struct tdesc_type *tdesc_type;
+
+  void accept (tdesc_element_visitor &v) const override
+  {
+    v.visit (this);
+  }
+
 } *tdesc_reg_p;
 DEF_VEC_P(tdesc_reg_p);
 
@@ -152,7 +175,7 @@ enum tdesc_type_kind
   TDESC_TYPE_ENUM
 };
 
-typedef struct tdesc_type
+typedef struct tdesc_type : tdesc_element
 {
 public:
   tdesc_type (const char *name_, enum tdesc_type_kind kind_)
@@ -161,7 +184,7 @@ public:
     memset (&u, 0, sizeof (u));
   }
 
-  ~tdesc_type ()
+  virtual ~tdesc_type ()
   {
     switch (kind)
       {
@@ -216,20 +239,25 @@ public:
       int size;
     } u;
   } u;
+  void accept (tdesc_element_visitor &v) const override
+  {
+    v.visit (this);
+  }
+
 } *tdesc_type_p;
 DEF_VEC_P(tdesc_type_p);
 
 /* A feature from a target description.  Each feature is a collection
    of other elements, e.g. registers and types.  */
 
-typedef struct tdesc_feature
+typedef struct tdesc_feature : tdesc_element
 {
 public:
   tdesc_feature (const char *name_)
     : name (xstrdup (name_))
   {}
 
-  ~tdesc_feature ()
+  virtual ~tdesc_feature ()
   {
     struct tdesc_reg *reg;
     struct tdesc_type *type;
@@ -259,6 +287,30 @@ public:
 
   /* The types associated with this feature.  */
   VEC(tdesc_type_p) *types = NULL;
+
+  void accept (tdesc_element_visitor &v) const override
+  {
+    v.visit (this);
+
+    struct tdesc_type *type;
+
+    for (int ix = 0;
+	 VEC_iterate (tdesc_type_p, types, ix, type);
+	 ix++)
+      {
+	type->accept (v);
+      }
+
+    struct tdesc_reg *reg;
+
+    for (int ix = 0;
+	 VEC_iterate (tdesc_reg_p, registers, ix, reg);
+	 ix++)
+      {
+	reg->accept (v);
+      }
+  }
+
 } *tdesc_feature_p;
 DEF_VEC_P(tdesc_feature_p);
 
@@ -268,23 +320,67 @@ DEF_VEC_P(arch_p);
 
 /* A target description.  */
 
-struct target_desc
+struct target_desc : tdesc_element
 {
+public:
+  target_desc ()
+  {}
+
+  virtual ~target_desc ()
+  {
+    struct tdesc_feature *feature;
+    struct property *prop;
+    int ix;
+
+    for (ix = 0;
+	 VEC_iterate (tdesc_feature_p, features, ix, feature);
+	 ix++)
+      delete feature;
+    VEC_free (tdesc_feature_p, features);
+
+    for (ix = 0;
+	 VEC_iterate (property_s, properties, ix, prop);
+	 ix++)
+      {
+	xfree (prop->key);
+	xfree (prop->value);
+      }
+
+    VEC_free (property_s, properties);
+    VEC_free (arch_p, compatible);
+  }
+
   /* The architecture reported by the target, if any.  */
-  const struct bfd_arch_info *arch;
+  const struct bfd_arch_info *arch = NULL;
 
   /* The osabi reported by the target, if any; GDB_OSABI_UNKNOWN
      otherwise.  */
-  enum gdb_osabi osabi;
+  enum gdb_osabi osabi = GDB_OSABI_UNKNOWN;
 
   /* The list of compatible architectures reported by the target.  */
-  VEC(arch_p) *compatible;
+  VEC(arch_p) *compatible = NULL;
 
   /* Any architecture-specific properties specified by the target.  */
-  VEC(property_s) *properties;
+  VEC(property_s) *properties = NULL;
 
   /* The features associated with this target.  */
-  VEC(tdesc_feature_p) *features;
+  VEC(tdesc_feature_p) *features = NULL;
+
+  void accept (tdesc_element_visitor &v) const override
+  {
+    v.visit (this);
+
+    struct tdesc_feature *feature;
+
+    for (int ix = 0;
+	 VEC_iterate (tdesc_feature_p, features, ix, feature);
+	 ix++)
+      {
+	feature->accept (v);
+      }
+
+    v.visit_end (this);
+  }
 };
 
 /* Per-architecture data associated with a target description.  The
@@ -1554,35 +1650,15 @@ tdesc_create_feature (struct target_desc *tdesc, const char *name)
 struct target_desc *
 allocate_target_description (void)
 {
-  return XCNEW (struct target_desc);
+  return new target_desc ();
 }
 
 static void
 free_target_description (void *arg)
 {
   struct target_desc *target_desc = (struct target_desc *) arg;
-  struct tdesc_feature *feature;
-  struct property *prop;
-  int ix;
 
-  for (ix = 0;
-       VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature);
-       ix++)
-    delete feature;
-  VEC_free (tdesc_feature_p, target_desc->features);
-
-  for (ix = 0;
-       VEC_iterate (property_s, target_desc->properties, ix, prop);
-       ix++)
-    {
-      xfree (prop->key);
-      xfree (prop->value);
-    }
-  VEC_free (property_s, target_desc->properties);
-
-  VEC_free (arch_p, target_desc->compatible);
-
-  xfree (target_desc);
+  delete target_desc;
 }
 
 struct cleanup *
@@ -1707,279 +1783,288 @@ unset_tdesc_filename_cmd (char *args, int from_tty)
   target_find_description ();
 }
 
-static void
-maint_print_c_tdesc_cmd (char *args, int from_tty)
+class print_c_tdesc : public tdesc_element_visitor
 {
-  const struct target_desc *tdesc;
-  const struct bfd_arch_info *compatible;
-  const char *filename, *inp;
-  char *function, *outp;
-  struct property *prop;
-  struct tdesc_feature *feature;
-  struct tdesc_reg *reg;
-  struct tdesc_type *type;
-  struct tdesc_type_field *f;
-  int ix, ix2, ix3;
-  int printed_field_type = 0;
+public:
+  print_c_tdesc (std::string &filename_after_features)
+    : m_filename_after_features (filename_after_features)
+  {
+    const char *inp;
+    char *outp;
+    const char *filename = lbasename (m_filename_after_features.c_str ());
 
-  /* Use the global target-supplied description, not the current
-     architecture's.  This lets a GDB for one architecture generate C
-     for another architecture's description, even though the gdbarch
-     initialization code will reject the new description.  */
-  tdesc = current_target_desc;
-  if (tdesc == NULL)
-    error (_("There is no target description to print."));
+    m_function = (char *) xmalloc (strlen (filename) + 1);
+    for (inp = filename, outp = m_function; *inp != '\0'; inp++)
+      if (*inp == '.')
+	break;
+      else if (*inp == '-')
+	*outp++ = '_';
+      else
+	*outp++ = *inp;
+    *outp = '\0';
+
+    /* Standard boilerplate.  */
+    printf_unfiltered ("/* THIS FILE IS GENERATED.  "
+		       "-*- buffer-read-only: t -*- vi"
+		       ":set ro:\n");
+    printf_unfiltered ("  Original: %s */\n\n", filename);
+  }
 
-  if (target_description_filename == NULL)
-    error (_("The current target description did not come from an XML file."));
+  ~print_c_tdesc ()
+  {
+    xfree (m_function);
+  }
 
-  filename = lbasename (target_description_filename);
-  function = (char *) alloca (strlen (filename) + 1);
-  for (inp = filename, outp = function; *inp != '\0'; inp++)
-    if (*inp == '.')
-      break;
-    else if (*inp == '-')
-      *outp++ = '_';
-    else
-      *outp++ = *inp;
-  *outp = '\0';
-
-  /* Standard boilerplate.  */
-  printf_unfiltered ("/* THIS FILE IS GENERATED.  "
-		     "-*- buffer-read-only: t -*- vi"
-		     ":set ro:\n");
-  printf_unfiltered ("  Original: %s */\n\n", filename);
-  printf_unfiltered ("#include \"defs.h\"\n");
-  printf_unfiltered ("#include \"osabi.h\"\n");
-  printf_unfiltered ("#include \"target-descriptions.h\"\n");
-  printf_unfiltered ("\n");
-
-  printf_unfiltered ("struct target_desc *tdesc_%s;\n", function);
-  printf_unfiltered ("static void\n");
-  printf_unfiltered ("initialize_tdesc_%s (void)\n", function);
-  printf_unfiltered ("{\n");
-  printf_unfiltered
-    ("  struct target_desc *result = allocate_target_description ();\n");
-  printf_unfiltered ("  struct tdesc_feature *feature;\n");
-
-  /* Now we do some "filtering" in order to know which variables to
-     declare.  This is needed because otherwise we would declare unused
-     variables `field_type' and `type'.  */
-  for (ix = 0;
-       VEC_iterate (tdesc_feature_p, tdesc->features, ix, feature);
-       ix++)
-    {
-      int printed_desc_type = 0;
+  void visit (const target_desc *e) override
+  {
+    printf_unfiltered ("#include \"defs.h\"\n");
+    printf_unfiltered ("#include \"osabi.h\"\n");
+    printf_unfiltered ("#include \"target-descriptions.h\"\n");
+    printf_unfiltered ("\n");
 
-      for (ix2 = 0;
-	   VEC_iterate (tdesc_type_p, feature->types, ix2, type);
-	   ix2++)
-	{
-	  if (!printed_field_type)
-	    {
-	      printf_unfiltered ("  struct tdesc_type *field_type;\n");
-	      printed_field_type = 1;
-	    }
+    printf_unfiltered ("struct target_desc *tdesc_%s;\n", m_function);
+    printf_unfiltered ("static void\n");
+    printf_unfiltered ("initialize_tdesc_%s (void)\n", m_function);
+    printf_unfiltered ("{\n");
+    printf_unfiltered
+      ("  struct target_desc *result = allocate_target_description ();\n");
 
-	  if ((type->kind == TDESC_TYPE_UNION
-	       || type->kind == TDESC_TYPE_STRUCT
-	       || type->kind == TDESC_TYPE_FLAGS
-	       || type->kind == TDESC_TYPE_ENUM)
-	      && VEC_length (tdesc_type_field, type->u.u.fields) > 0)
-	    {
-	      printf_unfiltered ("  struct tdesc_type *type;\n");
-	      printed_desc_type = 1;
-	      break;
-	    }
-	}
+    if (tdesc_architecture (e) != NULL)
+      {
+	printf_unfiltered
+	  ("  set_tdesc_architecture (result, bfd_scan_arch (\"%s\"));\n",
+	   tdesc_architecture (e)->printable_name);
+	printf_unfiltered ("\n");
+      }
+    if (tdesc_osabi (e) > GDB_OSABI_UNKNOWN
+	&& tdesc_osabi (e) < GDB_OSABI_INVALID)
+      {
+	printf_unfiltered
+	  ("  set_tdesc_osabi (result, osabi_from_tdesc_string (\"%s\"));\n",
+	   gdbarch_osabi_name (tdesc_osabi (e)));
+	printf_unfiltered ("\n");
+      }
 
-      if (printed_desc_type)
-	break;
-    }
+    int ix;
+    const struct bfd_arch_info *compatible;
+    struct property *prop;
 
-  printf_unfiltered ("\n");
+    for (ix = 0; VEC_iterate (arch_p, e->compatible, ix, compatible);
+	 ix++)
+      {
+	printf_unfiltered
+	  ("  tdesc_add_compatible (result, bfd_scan_arch (\"%s\"));\n",
+	   compatible->printable_name);
+      }
 
-  if (tdesc_architecture (tdesc) != NULL)
-    {
-      printf_unfiltered
-	("  set_tdesc_architecture (result, bfd_scan_arch (\"%s\"));\n",
-	 tdesc_architecture (tdesc)->printable_name);
+    if (ix)
       printf_unfiltered ("\n");
-    }
 
-  if (tdesc_osabi (tdesc) > GDB_OSABI_UNKNOWN
-      && tdesc_osabi (tdesc) < GDB_OSABI_INVALID)
-    {
-      printf_unfiltered
-	("  set_tdesc_osabi (result, osabi_from_tdesc_string (\"%s\"));\n",
-	 gdbarch_osabi_name (tdesc_osabi (tdesc)));
-      printf_unfiltered ("\n");
-    }
+    for (ix = 0; VEC_iterate (property_s, e->properties, ix, prop);
+	 ix++)
+      {
+	printf_unfiltered ("  set_tdesc_property (result, \"%s\", \"%s\");\n",
+			   prop->key, prop->value);
+      }
+    printf_unfiltered ("  struct tdesc_feature *feature;\n");
+  }
 
-  for (ix = 0; VEC_iterate (arch_p, tdesc->compatible, ix, compatible);
-       ix++)
-    {
-      printf_unfiltered
-	("  tdesc_add_compatible (result, bfd_scan_arch (\"%s\"));\n",
-	 compatible->printable_name);
-    }
-  if (ix)
-    printf_unfiltered ("\n");
+  void visit (const tdesc_feature *e) override
+  {
+    printf_unfiltered ("\n  feature = tdesc_create_feature (result, \"%s\");\n",
+		       e->name);
+  }
 
-  for (ix = 0; VEC_iterate (property_s, tdesc->properties, ix, prop);
-       ix++)
-    {
-      printf_unfiltered ("  set_tdesc_property (result, \"%s\", \"%s\");\n",
-	      prop->key, prop->value);
-    }
+  void visit_end (const target_desc *e) override
+  {
+    printf_unfiltered ("\n  tdesc_%s = result;\n", m_function);
+    printf_unfiltered ("}\n");
+  }
 
-  for (ix = 0;
-       VEC_iterate (tdesc_feature_p, tdesc->features, ix, feature);
-       ix++)
-    {
-      printf_unfiltered ("  \
-feature = tdesc_create_feature (result, \"%s\");\n",
-			 feature->name);
+  void visit (const tdesc_type *type) override
+  {
+    struct tdesc_type_field *f;
 
-      for (ix2 = 0;
-	   VEC_iterate (tdesc_type_p, feature->types, ix2, type);
-	   ix2++)
-	{
-	  switch (type->kind)
-	    {
-	    case TDESC_TYPE_VECTOR:
-	      printf_unfiltered
-		("  field_type = tdesc_named_type (feature, \"%s\");\n",
-		 type->u.v.type->name);
+    /* Now we do some "filtering" in order to know which variables to
+       declare.  This is needed because otherwise we would declare unused
+       variables `field_type' and `type'.  */
+    if (!m_printed_field_type)
+      {
+	printf_unfiltered ("  struct tdesc_type *field_type;\n");
+	m_printed_field_type = true;
+      }
+
+    if ((type->kind == TDESC_TYPE_UNION
+	 || type->kind == TDESC_TYPE_STRUCT
+	 || type->kind == TDESC_TYPE_FLAGS
+	 || type->kind == TDESC_TYPE_ENUM)
+	&& VEC_length (tdesc_type_field, type->u.u.fields) > 0
+	&& !m_printed_type)
+      {
+	printf_unfiltered ("  struct tdesc_type *type;\n");
+	m_printed_type = true;
+      }
+
+    switch (type->kind)
+      {
+      case TDESC_TYPE_VECTOR:
+	printf_unfiltered
+	  ("  field_type = tdesc_named_type (feature, \"%s\");\n",
+	   type->u.v.type->name);
+	printf_unfiltered
+	  ("  tdesc_create_vector (feature, \"%s\", field_type, %d);\n",
+	   type->name, type->u.v.count);
+	break;
+      case TDESC_TYPE_STRUCT:
+      case TDESC_TYPE_FLAGS:
+	if (type->kind == TDESC_TYPE_STRUCT)
+	  {
+	    printf_unfiltered
+	      ("  type = tdesc_create_struct (feature, \"%s\");\n",
+	       type->name);
+	    if (type->u.u.size != 0)
 	      printf_unfiltered
-		("  tdesc_create_vector (feature, \"%s\", field_type, %d);\n",
-		 type->name, type->u.v.count);
-	      break;
-	    case TDESC_TYPE_STRUCT:
-	    case TDESC_TYPE_FLAGS:
-	      if (type->kind == TDESC_TYPE_STRUCT)
-		{
-		  printf_unfiltered
-		    ("  type = tdesc_create_struct (feature, \"%s\");\n",
-		     type->name);
-		  if (type->u.u.size != 0)
+		("  tdesc_set_struct_size (type, %d);\n",
+		 type->u.u.size);
+	  }
+	else
+	  {
+	    printf_unfiltered
+	      ("  type = tdesc_create_flags (feature, \"%s\", %d);\n",
+	       type->name, type->u.u.size);
+	  }
+	for (int ix3 = 0;
+	     VEC_iterate (tdesc_type_field, type->u.u.fields, ix3, f);
+	     ix3++)
+	  {
+	    const char *type_name;
+
+	    gdb_assert (f->type != NULL);
+	    type_name = f->type->name;
+
+	    /* To minimize changes to generated files, don't emit type
+	       info for fields that have defaulted types.  */
+	    if (f->start != -1)
+	      {
+		gdb_assert (f->end != -1);
+		if (f->type->kind == TDESC_TYPE_BOOL)
+		  {
+		    gdb_assert (f->start == f->end);
 		    printf_unfiltered
-		      ("  tdesc_set_struct_size (type, %d);\n",
-		       type->u.u.size);
-		}
-	      else
-		{
-		  printf_unfiltered
-		    ("  type = tdesc_create_flags (feature, \"%s\", %d);\n",
-		     type->name, type->u.u.size);
-		}
-	      for (ix3 = 0;
-		   VEC_iterate (tdesc_type_field, type->u.u.fields, ix3, f);
-		   ix3++)
-		{
-		  const char *type_name;
-
-		  gdb_assert (f->type != NULL);
-		  type_name = f->type->name;
-
-		  /* To minimize changes to generated files, don't emit type
-		     info for fields that have defaulted types.  */
-		  if (f->start != -1)
-		    {
-		      gdb_assert (f->end != -1);
-		      if (f->type->kind == TDESC_TYPE_BOOL)
-			{
-			  gdb_assert (f->start == f->end);
-			  printf_unfiltered
-			    ("  tdesc_add_flag (type, %d, \"%s\");\n",
-			     f->start, f->name);
-			}
-		      else if ((type->u.u.size == 4
-				&& f->type->kind == TDESC_TYPE_UINT32)
-			       || (type->u.u.size == 8
-				   && f->type->kind == TDESC_TYPE_UINT64))
-			{
-			  printf_unfiltered
-			    ("  tdesc_add_bitfield (type, \"%s\", %d, %d);\n",
-			     f->name, f->start, f->end);
-			}
-		      else
-			{
-			  printf_unfiltered
-			    ("  field_type = tdesc_named_type (feature,"
-			     " \"%s\");\n",
-			     type_name);
-			  printf_unfiltered
-			    ("  tdesc_add_typed_bitfield (type, \"%s\","
-			     " %d, %d, field_type);\n",
-			     f->name, f->start, f->end);
-			}
-		    }
-		  else /* Not a bitfield.  */
-		    {
-		      gdb_assert (f->end == -1);
-		      gdb_assert (type->kind == TDESC_TYPE_STRUCT);
-		      printf_unfiltered
-			("  field_type = tdesc_named_type (feature,"
-			 " \"%s\");\n",
-			 type_name);
-		      printf_unfiltered
-			("  tdesc_add_field (type, \"%s\", field_type);\n",
-			 f->name);
-		    }
-		}
-	      break;
-	    case TDESC_TYPE_UNION:
-	      printf_unfiltered
-		("  type = tdesc_create_union (feature, \"%s\");\n",
-		 type->name);
-	      for (ix3 = 0;
-		   VEC_iterate (tdesc_type_field, type->u.u.fields, ix3, f);
-		   ix3++)
-		{
-		  printf_unfiltered
-		    ("  field_type = tdesc_named_type (feature, \"%s\");\n",
-		     f->type->name);
-		  printf_unfiltered
-		    ("  tdesc_add_field (type, \"%s\", field_type);\n",
-		     f->name);
-		}
-	      break;
-	    case TDESC_TYPE_ENUM:
-	      printf_unfiltered
-		("  type = tdesc_create_enum (feature, \"%s\", %d);\n",
-		 type->name, type->u.u.size);
-	      for (ix3 = 0;
-		   VEC_iterate (tdesc_type_field, type->u.u.fields, ix3, f);
-		   ix3++)
+		      ("  tdesc_add_flag (type, %d, \"%s\");\n",
+		       f->start, f->name);
+		  }
+		else if ((type->u.u.size == 4
+			  && f->type->kind == TDESC_TYPE_UINT32)
+			 || (type->u.u.size == 8
+			     && f->type->kind == TDESC_TYPE_UINT64))
+		  {
+		    printf_unfiltered
+		      ("  tdesc_add_bitfield (type, \"%s\", %d, %d);\n",
+		       f->name, f->start, f->end);
+		  }
+		else
+		  {
+		    printf_unfiltered
+		      ("  field_type = tdesc_named_type (feature,"
+		       " \"%s\");\n",
+		       type_name);
+		    printf_unfiltered
+		      ("  tdesc_add_typed_bitfield (type, \"%s\","
+		       " %d, %d, field_type);\n",
+		       f->name, f->start, f->end);
+		  }
+	      }
+	    else /* Not a bitfield.  */
+	      {
+		gdb_assert (f->end == -1);
+		gdb_assert (type->kind == TDESC_TYPE_STRUCT);
 		printf_unfiltered
-		  ("  tdesc_add_enum_value (type, %d, \"%s\");\n",
-		   f->start, f->name);
-	      break;
-	    default:
-	      error (_("C output is not supported type \"%s\"."), type->name);
-	    }
-	  printf_unfiltered ("\n");
-	}
+		  ("  field_type = tdesc_named_type (feature,"
+		   " \"%s\");\n",
+		   type_name);
+		printf_unfiltered
+		  ("  tdesc_add_field (type, \"%s\", field_type);\n",
+		   f->name);
+	      }
+	  }
+	break;
+      case TDESC_TYPE_UNION:
+	printf_unfiltered
+	  ("  type = tdesc_create_union (feature, \"%s\");\n",
+	   type->name);
+	for (int ix3 = 0;
+	     VEC_iterate (tdesc_type_field, type->u.u.fields, ix3, f);
+	     ix3++)
+	  {
+	    printf_unfiltered
+	      ("  field_type = tdesc_named_type (feature, \"%s\");\n",
+	       f->type->name);
+	    printf_unfiltered
+	      ("  tdesc_add_field (type, \"%s\", field_type);\n",
+	       f->name);
+	  }
+	break;
+      case TDESC_TYPE_ENUM:
+	printf_unfiltered
+	  ("  type = tdesc_create_enum (feature, \"%s\", %d);\n",
+	   type->name, type->u.u.size);
+	for (int ix3 = 0;
+	     VEC_iterate (tdesc_type_field, type->u.u.fields, ix3, f);
+	     ix3++)
+	  printf_unfiltered
+	    ("  tdesc_add_enum_value (type, %d, \"%s\");\n",
+	     f->start, f->name);
+	break;
+      default:
+	error (_("C output is not supported type \"%s\"."), type->name);
+      }
+    printf_unfiltered ("\n");
+  }
 
-      for (ix2 = 0;
-	   VEC_iterate (tdesc_reg_p, feature->registers, ix2, reg);
-	   ix2++)
-	{
-	  printf_unfiltered ("  tdesc_create_reg (feature, \"%s\", %ld, %d, ",
-			     reg->name, reg->target_regnum, reg->save_restore);
-	  if (reg->group)
-	    printf_unfiltered ("\"%s\", ", reg->group);
-	  else
-	    printf_unfiltered ("NULL, ");
-	  printf_unfiltered ("%d, \"%s\");\n", reg->bitsize, reg->type);
-	}
+  void visit (const tdesc_reg *reg) override
+  {
+    printf_unfiltered ("  tdesc_create_reg (feature, \"%s\", %ld, %d, ",
+		       reg->name, reg->target_regnum, reg->save_restore);
+    if (reg->group)
+      printf_unfiltered ("\"%s\", ", reg->group);
+    else
+      printf_unfiltered ("NULL, ");
+    printf_unfiltered ("%d, \"%s\");\n", reg->bitsize, reg->type);
+  }
 
-      printf_unfiltered ("\n");
-    }
+private:
+  char *m_function;
+  std::string m_filename_after_features;
+  bool m_printed_field_type = false;
+  bool m_printed_type = false;
+};
+
+static void
+maint_print_c_tdesc_cmd (char *args, int from_tty)
+{
+  const struct target_desc *tdesc;
+
+  /* Use the global target-supplied description, not the current
+     architecture's.  This lets a GDB for one architecture generate C
+     for another architecture's description, even though the gdbarch
+     initialization code will reject the new description.  */
+  tdesc = current_target_desc;
+  if (tdesc == NULL)
+    error (_("There is no target description to print."));
+
+  if (target_description_filename == NULL)
+    error (_("The current target description did not come from an XML file."));
+
+  std::string filename_after_features (target_description_filename);
+  auto loc = filename_after_features.rfind ("/features/");
+
+  if (loc != std::string::npos)
+    filename_after_features = filename_after_features.substr (loc + 10);
+
+  print_c_tdesc v (filename_after_features);
 
-  printf_unfiltered ("  tdesc_%s = result;\n", function);
-  printf_unfiltered ("}\n");
+  tdesc->accept (v);
 }
 
 /* Provide a prototype to silence -Wmissing-prototypes.  */
-- 
1.9.1

^ permalink raw reply	[flat|nested] 82+ messages in thread

* [PATCH 01/25] Move initialize_tdesc_mips* calls from mips-linux-nat.c to mips-linux-tdep.c
  2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
                   ` (13 preceding siblings ...)
  2017-06-12  8:42 ` [PATCH 14/25] [RFC] GDBserver self test Yao Qi
@ 2017-06-12  8:42 ` Yao Qi
  2017-06-12 15:25   ` Maciej W. Rozycki
  2017-06-12  8:42 ` [PATCH 03/25] Class-fy tdesc_reg tdesc_type and tdesc_feature Yao Qi
                   ` (11 subsequent siblings)
  26 siblings, 1 reply; 82+ messages in thread
From: Yao Qi @ 2017-06-12  8:42 UTC (permalink / raw)
  To: gdb-patches; +Cc: macro

All target descriptions except mips initialization are called in -tdep.c,
instead of -nat.c, so this patch moves mips target descriptions initialization
to -tdep.c.  Secondly, I want to change the target descriptions from pre-generated
to dynamical creation, so I want to test that these pre-generated target
descriptions equal to these dynamically created ones.  Move target descriptions
initialization to -tdep.c files so we can test them in any hosts (if they are
still -nat.c, we can only test them on mips-linux host.).

gdb:

2017-05-09  Yao Qi  <yao.qi@linaro.org>

	* mips-linux-nat.c: Move include features/mips*-linux.c to
	mips-linux-tdep.c.
	(_initialize_mips_linux_nat): Move initialize_tdesc_mips* calls
	to mips-linux-tdep.c.
	* mips-linux-tdep.c: Include features/mips*-linux.c
	(_initialize_mips_linux_tdep): Call initialize_tdesc_mips*
	functions.
	* mips-linux-tdep.h (tdesc_mips_linux): Declare.
	(tdesc_mips_dsp_linux, tdesc_mips64_linux): Declare.
	(tdesc_mips64_dsp_linux): Declare.
---
 gdb/mips-linux-nat.c  | 11 -----------
 gdb/mips-linux-tdep.c | 11 +++++++++++
 gdb/mips-linux-tdep.h |  6 ++++++
 3 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/gdb/mips-linux-nat.c b/gdb/mips-linux-nat.c
index 8041d84..1fd3365 100644
--- a/gdb/mips-linux-nat.c
+++ b/gdb/mips-linux-nat.c
@@ -38,11 +38,6 @@
 
 #include "nat/mips-linux-watch.h"
 
-#include "features/mips-linux.c"
-#include "features/mips-dsp-linux.c"
-#include "features/mips64-linux.c"
-#include "features/mips64-dsp-linux.c"
-
 #ifndef PTRACE_GET_THREAD_AREA
 #define PTRACE_GET_THREAD_AREA 25
 #endif
@@ -803,10 +798,4 @@ triggers a breakpoint or watchpoint."),
 
   linux_nat_add_target (t);
   linux_nat_set_new_thread (t, mips_linux_new_thread);
-
-  /* Initialize the standard target descriptions.  */
-  initialize_tdesc_mips_linux ();
-  initialize_tdesc_mips_dsp_linux ();
-  initialize_tdesc_mips64_linux ();
-  initialize_tdesc_mips64_dsp_linux ();
 }
diff --git a/gdb/mips-linux-tdep.c b/gdb/mips-linux-tdep.c
index ccfdcdf..f144a2e 100644
--- a/gdb/mips-linux-tdep.c
+++ b/gdb/mips-linux-tdep.c
@@ -40,6 +40,11 @@
 #include "xml-syscall.h"
 #include "gdb_signals.h"
 
+#include "features/mips-linux.c"
+#include "features/mips-dsp-linux.c"
+#include "features/mips64-linux.c"
+#include "features/mips64-dsp-linux.c"
+
 static struct target_so_ops mips_svr4_so_ops;
 
 /* This enum represents the signals' numbers on the MIPS
@@ -1739,4 +1744,10 @@ _initialize_mips_linux_tdep (void)
 			      GDB_OSABI_LINUX,
 			      mips_linux_init_abi);
     }
+
+  /* Initialize the standard target descriptions.  */
+  initialize_tdesc_mips_linux ();
+  initialize_tdesc_mips_dsp_linux ();
+  initialize_tdesc_mips64_linux ();
+  initialize_tdesc_mips64_dsp_linux ();
 }
diff --git a/gdb/mips-linux-tdep.h b/gdb/mips-linux-tdep.h
index 407b577..cca4798 100644
--- a/gdb/mips-linux-tdep.h
+++ b/gdb/mips-linux-tdep.h
@@ -105,3 +105,9 @@ enum {
 /* Return 1 if MIPS_RESTART_REGNUM is usable.  */
 
 int mips_linux_restart_reg_p (struct gdbarch *gdbarch);
+
+/* Target descriptions.  */
+extern struct target_desc *tdesc_mips_linux;
+extern struct target_desc *tdesc_mips64_linux;
+extern struct target_desc *tdesc_mips_dsp_linux;
+extern struct target_desc *tdesc_mips64_dsp_linux;
-- 
1.9.1

^ permalink raw reply	[flat|nested] 82+ messages in thread

* [PATCH 08/25] Add "maint check xml-descriptions" to test builtin xml target descriptions
  2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
                   ` (5 preceding siblings ...)
  2017-06-12  8:42 ` [PATCH 11/25] Use VEC for target_desc.reg_defs Yao Qi
@ 2017-06-12  8:42 ` Yao Qi
  2017-06-28 16:13   ` Pedro Alves
  2017-06-12  8:42 ` [PATCH 05/25] Use visitor pattern for "maint print c-tdesc" Yao Qi
                   ` (19 subsequent siblings)
  26 siblings, 1 reply; 82+ messages in thread
From: Yao Qi @ 2017-06-12  8:42 UTC (permalink / raw)
  To: gdb-patches

Now, GDB is able to dynamically create i386-linux target descriptions
from features, instead of using pre-generated target descriptions.  These
pre-generated target descriptions are no longer used by GDB (note that
they are still used by GDBserver).

This patch add a new maint command "maint check xml-descriptions" to test
dynamically generated tdesc are identical to these generated from xml files.

gdb:

2017-06-06  Yao Qi  <yao.qi@linaro.org>

	* cli/cli-cmds.c (maintenancechecklist): New variable.
	* gdbcmd.h (maintenancechecklist): Declare it.
	* i386-linux-tdep.c (_initialize_i386_linux_tdep) [GDB_SELF_TEST]:
	Call i386_linux_read_description with different masks.
	* maint.c (maintenance_check_command): New function.
	(_initialize_maint_cmds): Call add_prefix_cmd.
	* target-descriptions.c (tdesc_reg): override operator != and ==.
	(tdesc_type): Likewise.
	(tdesc_feature): Likewise.
	(target_desc): Likewise.
	[GDB_SELF_TEST] (selftests::record_xml_tdesc): New function.
	(maintenance_check_xml_descriptions): New function.
	(_initialize_target_descriptions) Add command "xml-descriptions".
	* target-descriptions.h (selftests::record_xml_tdesc): Declare.

gdb/testsuite:

2017-06-06  Yao Qi  <yao.qi@linaro.org>

	* gdb.gdb/unittest.exp: Invoke command
	"maintenance check xml-descriptions".

gdb/doc:

2017-06-06  Yao Qi  <yao.qi@linaro.org>

	* gdb.texinfo (Maintenance Commands): Document command
	"maint check xml-descriptions".
---
 gdb/cli/cli-cmds.c                 |   4 +
 gdb/doc/gdb.texinfo                |   5 ++
 gdb/gdbcmd.h                       |   4 +
 gdb/i386-linux-tdep.c              |  20 +++++
 gdb/maint.c                        |  18 +++++
 gdb/target-descriptions.c          | 148 +++++++++++++++++++++++++++++++++++++
 gdb/target-descriptions.h          |  10 +++
 gdb/testsuite/gdb.gdb/unittest.exp |   5 ++
 8 files changed, 214 insertions(+)

diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 0930342..6d7532b 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -168,6 +168,10 @@ struct cmd_list_element *maintenanceinfolist;
 
 struct cmd_list_element *maintenanceprintlist;
 
+/* Chain containing all defined "maintenance check" subcommands.  */
+
+struct cmd_list_element *maintenancechecklist;
+
 struct cmd_list_element *setprintlist;
 
 struct cmd_list_element *showprintlist;
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index eb35b43..10c82b8 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -34684,6 +34684,11 @@ argument @var{file} or the current target description.  The created
 source file can be used in @value{GDBN} when an XML parser is not
 available to parse the description.
 
+@kindex maint check xml-descriptions
+@item maint check xml-descriptions @var{dir}
+Check the target descriptions created by @value{GDBN} equal to these
+which are created from XML files in @var{dir}.
+
 @kindex maint print dummy-frames
 @item maint print dummy-frames
 Prints the contents of @value{GDBN}'s internal dummy-frame stack.
diff --git a/gdb/gdbcmd.h b/gdb/gdbcmd.h
index fbd0cb9..14c7f4e 100644
--- a/gdb/gdbcmd.h
+++ b/gdb/gdbcmd.h
@@ -95,6 +95,10 @@ extern struct cmd_list_element *maintenanceinfolist;
 
 extern struct cmd_list_element *maintenanceprintlist;
 
+/* Chain containing all defined "maintenance check" subcommands.  */
+
+extern struct cmd_list_element *maintenancechecklist;
+
 /* Chain containing all defined "maintenance set" subcommands.  */
 
 extern struct cmd_list_element *maintenance_set_cmdlist;
diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c
index 5ca58a1..f8d5a7b 100644
--- a/gdb/i386-linux-tdep.c
+++ b/gdb/i386-linux-tdep.c
@@ -1116,4 +1116,24 @@ _initialize_i386_linux_tdep (void)
 {
   gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_LINUX,
 			  i386_linux_init_abi);
+
+#if GDB_SELF_TEST
+  std::pair<const char *, uint64_t> xml_masks[] = {
+    { "i386/i386-linux.xml", X86_XSTATE_SSE_MASK },
+    { "i386/i386-mmx-linux.xml", X86_XSTATE_X87_MASK },
+    { "i386/i386-avx-linux.xml", X86_XSTATE_AVX_MASK },
+    { "i386/i386-mpx-linux.xml", X86_XSTATE_MPX_MASK },
+    { "i386/i386-avx-mpx-linux.xml", X86_XSTATE_AVX_MPX_MASK },
+    { "i386/i386-avx-avx512-linux.xml", X86_XSTATE_AVX_AVX512_MASK },
+    { "i386/i386-avx-mpx-avx512-pku-linux.xml",
+      X86_XSTATE_AVX_MPX_AVX512_PKU_MASK },
+  };
+
+  for (auto &a : xml_masks)
+    {
+      auto tdesc = i386_linux_read_description (a.second);
+
+      selftests::record_xml_tdesc (a.first, tdesc);
+    }
+#endif /* GDB_SELF_TEST */
 }
diff --git a/gdb/maint.c b/gdb/maint.c
index d95f658..a0d43ec 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -178,6 +178,19 @@ maintenance_info_command (char *arg, int from_tty)
 	     gdb_stdout);
 }
 
+/* The "maintenance check" command is defined as a prefix, with
+   allow_unknown 0.  Therefore, its own definition is called only for
+   "maintenance check" with no args.  */
+
+static void
+maintenance_check_command (char *arg, int from_tty)
+{
+  printf_unfiltered (_("\"maintenance check\" must be followed "
+		       "by the name of a check command.\n"));
+  help_list (maintenancechecklist, "maintenance check ", all_commands,
+	     gdb_stdout);
+}
+
 /* Mini tokenizing lexer for 'maint info sections' command.  */
 
 static int
@@ -1104,6 +1117,11 @@ Print the internal architecture configuration.\n\
 Takes an optional file parameter."),
 	   &maintenanceprintlist);
 
+  add_prefix_cmd ("check", class_maintenance, maintenance_check_command, _("\
+Commands for checking internal gdb state."),
+		  &maintenancechecklist, "maintenance check ", 0,
+		  &maintenancelist);
+
   add_cmd ("translate-address", class_maintenance,
 	   maintenance_translate_address,
 	   _("Translate a section name and address to a symbol."),
diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
index c0b716a..2b3083a 100644
--- a/gdb/target-descriptions.c
+++ b/gdb/target-descriptions.c
@@ -133,6 +133,20 @@ public:
     v.visit (this);
   }
 
+  bool operator== (const tdesc_reg &other) const
+  {
+    return (streq (name, other.name)
+	    && target_regnum == other.target_regnum
+	    && save_restore == other.save_restore
+	    && bitsize == other.bitsize
+	    && (group == other.group || streq (group, other.group))
+	    && streq (type, other.type));
+  }
+
+  bool operator!= (const tdesc_reg &other) const
+  {
+    return !(*this == other);
+  }
 } *tdesc_reg_p;
 DEF_VEC_P(tdesc_reg_p);
 
@@ -247,6 +261,15 @@ public:
     v.visit (this);
   }
 
+  bool operator== (const tdesc_type &other) const
+  {
+    return (streq (name, other.name) && kind == other.kind);
+  }
+
+  bool operator!= (const tdesc_type &other) const
+  {
+    return !(*this == other);
+  }
 } *tdesc_type_p;
 DEF_VEC_P(tdesc_type_p);
 
@@ -315,6 +338,53 @@ public:
 
     v.visit_end (this);
   }
+  bool operator!= (const tdesc_feature &other) const
+  {
+    if (strcmp (name, other.name) != 0)
+      return true;
+
+    if (VEC_length (tdesc_reg_p, registers)
+	!= VEC_length (tdesc_reg_p, other.registers))
+      return true;
+
+    struct tdesc_reg *reg;
+
+    for (int ix = 0;
+	 VEC_iterate (tdesc_reg_p, registers, ix, reg);
+	 ix++)
+      {
+	struct tdesc_reg *reg2
+	  = VEC_index (tdesc_reg_p, other.registers, ix);
+
+	if (reg != reg2 && *reg != *reg2)
+	  return true;
+      }
+
+    if (VEC_length (tdesc_type_p, types)
+	!= VEC_length (tdesc_type_p, other.types))
+      return true;
+
+    struct tdesc_type *type;
+
+    for (int ix = 0;
+	 VEC_iterate (tdesc_type_p, types, ix, type);
+	 ix++)
+      {
+	struct tdesc_type *type2
+	  = VEC_index (tdesc_type_p, other.types, ix);
+
+	if (type != type2 && *type != *type2)
+	  return true;
+      }
+
+    return false;
+  }
+
+  bool operator== (const tdesc_feature &other) const
+  {
+    return !(*this != other);
+  }
+
 } *tdesc_feature_p;
 DEF_VEC_P(tdesc_feature_p);
 
@@ -385,6 +455,39 @@ public:
 
     v.visit_end (this);
   }
+
+  bool operator!= (const target_desc &other) const
+  {
+    if (arch != other.arch)
+      return true;
+
+    if (osabi != other.osabi)
+      return true;
+
+    if (VEC_length (tdesc_feature_p, features)
+	!= VEC_length (tdesc_feature_p, other.features))
+      return true;
+
+    struct tdesc_feature *feature;
+
+    for (int ix = 0;
+	 VEC_iterate (tdesc_feature_p, features, ix, feature);
+	 ix++)
+      {
+	struct tdesc_feature *feature2
+	  = VEC_index (tdesc_feature_p, other.features, ix);
+
+	if (feature != feature2 && *feature != *feature2)
+	  return true;
+      }
+
+    return false;
+  }
+
+  bool operator== (const target_desc &other) const
+  {
+    return !(*this != other);
+  }
 };
 
 /* Per-architecture data associated with a target description.  The
@@ -2170,6 +2273,45 @@ maint_print_c_tdesc_cmd (char *args, int from_tty)
     }
 }
 
+namespace selftests {
+
+static std::vector<std::pair<const char*, const target_desc *>> xml_tdesc;
+
+#if GDB_SELF_TEST
+void
+record_xml_tdesc (const char *xml_file, const struct target_desc *tdesc)
+{
+  xml_tdesc.emplace_back (xml_file, tdesc);
+}
+#endif
+
+}
+
+/* Test these GDB builtin target descriptions equal to these which
+   are generated by the corresponding xml files.  */
+
+static void
+maintenance_check_xml_descriptions (char *name, int from_tty)
+{
+  if (name == NULL)
+    error (_("Missing dir name"));
+
+  std::string feature_dir (name);
+  unsigned int failed = 0;
+
+  for (auto const &e : selftests::xml_tdesc)
+    {
+      std::string tdesc_xml = (feature_dir + SLASH_STRING + e.first);
+      const target_desc *tdesc
+	= file_read_description_xml (tdesc_xml.data ());
+
+      if (tdesc == NULL || *tdesc != *e.second)
+	failed++;
+    }
+  printf_filtered (_("%lu XML are tested, %d failed\n"),
+		   (long) selftests::xml_tdesc.size (), failed);
+}
+
 /* Provide a prototype to silence -Wmissing-prototypes.  */
 extern initialize_file_ftype _initialize_target_descriptions;
 
@@ -2210,4 +2352,10 @@ GDB will read the description from the target."),
   add_cmd ("c-tdesc", class_maintenance, maint_print_c_tdesc_cmd, _("\
 Print the current target description as a C source file."),
 	   &maintenanceprintlist);
+
+  add_cmd ("xml-descriptions", class_maintenance,
+	   maintenance_check_xml_descriptions, _("\
+Check the target descriptions.\n\
+Takes a directory parameter."),
+	   &maintenancechecklist);
 }
diff --git a/gdb/target-descriptions.h b/gdb/target-descriptions.h
index 361ac97..d730672 100644
--- a/gdb/target-descriptions.h
+++ b/gdb/target-descriptions.h
@@ -253,4 +253,14 @@ void tdesc_create_reg (struct tdesc_feature *feature, const char *name,
 		       int regnum, int save_restore, const char *group,
 		       int bitsize, const char *type);
 
+#if GDB_SELF_TEST
+namespace selftests {
+
+/* Record the target description TDESC generated by XML_FILE.  */
+
+void record_xml_tdesc (const char *xml_file,
+		       const struct target_desc *tdesc);
+}
+#endif
+
 #endif /* TARGET_DESCRIPTIONS_H */
diff --git a/gdb/testsuite/gdb.gdb/unittest.exp b/gdb/testsuite/gdb.gdb/unittest.exp
index d6fc3de..991ab9c 100644
--- a/gdb/testsuite/gdb.gdb/unittest.exp
+++ b/gdb/testsuite/gdb.gdb/unittest.exp
@@ -15,3 +15,8 @@
 
 gdb_start
 gdb_test "maintenance selftest" "Ran $decimal unit tests, 0 failed"
+
+if { ![is_remote host] } {
+    gdb_test "maintenance check xml-descriptions ${srcdir}/../features" \
+	"$decimal XML are tested, 0 failed"
+}
-- 
1.9.1

^ permalink raw reply	[flat|nested] 82+ messages in thread

* [PATCH 02/25] Adjust the order of 32bit-linux.xml and 32bit-sse.xml in i386/i386-linux.xml
  2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
                   ` (11 preceding siblings ...)
  2017-06-12  8:42 ` [PATCH 20/25] Centralize amd64-linux target descriptions Yao Qi
@ 2017-06-12  8:42 ` Yao Qi
  2017-06-19 20:22   ` Simon Marchi
  2017-06-12  8:42 ` [PATCH 14/25] [RFC] GDBserver self test Yao Qi
                   ` (13 subsequent siblings)
  26 siblings, 1 reply; 82+ messages in thread
From: Yao Qi @ 2017-06-12  8:42 UTC (permalink / raw)
  To: gdb-patches

Exchange the order of 32bit-linux.xml and 32bit-sse.xml in
i386/i386-linux.xml, to align with other i386 linux .xml files.

gdb:

2017-04-27  Yao Qi  <yao.qi@linaro.org>

	* features/i386/i386-linux.xml: Exchange the order of including
	32bit-linux.xml and 32bit-sse.xml.
	* features/i386/i386-linux.c: Regenerated.
---
 gdb/features/i386/i386-linux.c   | 6 +++---
 gdb/features/i386/i386-linux.xml | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gdb/features/i386/i386-linux.c b/gdb/features/i386/i386-linux.c
index 42c406b..c7796c3 100644
--- a/gdb/features/i386/i386-linux.c
+++ b/gdb/features/i386/i386-linux.c
@@ -71,9 +71,6 @@ initialize_tdesc_i386_linux (void)
   tdesc_create_reg (feature, "fooff", 30, 1, "float", 32, "int");
   tdesc_create_reg (feature, "fop", 31, 1, "float", 32, "int");
 
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
-  tdesc_create_reg (feature, "orig_eax", 41, 1, NULL, 32, "int");
-
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.sse");
   field_type = tdesc_named_type (feature, "ieee_single");
   tdesc_create_vector (feature, "v4f", field_type, 4);
@@ -135,5 +132,8 @@ initialize_tdesc_i386_linux (void)
   tdesc_create_reg (feature, "xmm7", 39, 1, NULL, 128, "vec128");
   tdesc_create_reg (feature, "mxcsr", 40, 1, "vector", 32, "i386_mxcsr");
 
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
+  tdesc_create_reg (feature, "orig_eax", 41, 1, NULL, 32, "int");
+
   tdesc_i386_linux = result;
 }
diff --git a/gdb/features/i386/i386-linux.xml b/gdb/features/i386/i386-linux.xml
index f9aa311..17f9a1a 100644
--- a/gdb/features/i386/i386-linux.xml
+++ b/gdb/features/i386/i386-linux.xml
@@ -12,6 +12,6 @@
   <architecture>i386</architecture>
   <osabi>GNU/Linux</osabi>
   <xi:include href="32bit-core.xml"/>
-  <xi:include href="32bit-linux.xml"/>
   <xi:include href="32bit-sse.xml"/>
+  <xi:include href="32bit-linux.xml"/>
 </target>
-- 
1.9.1

^ permalink raw reply	[flat|nested] 82+ messages in thread

* [PATCH 25/25] Remove features/i386/amd64-*linux.c and features/i386/x32-*linux.c
  2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
                   ` (3 preceding siblings ...)
  2017-06-12  8:42 ` [PATCH 12/25] [GDBserver] Centralize tdesc for i386-linux Yao Qi
@ 2017-06-12  8:42 ` Yao Qi
  2017-06-12  8:42 ` [PATCH 11/25] Use VEC for target_desc.reg_defs Yao Qi
                   ` (21 subsequent siblings)
  26 siblings, 0 replies; 82+ messages in thread
From: Yao Qi @ 2017-06-12  8:42 UTC (permalink / raw)
  To: gdb-patches

gdb:

2017-06-09  Yao Qi  <yao.qi@linaro.org>

	* features/Makefile (XMLTOC): Remove i386/amd64XXX-linux.xml a
	* features/i386/amd64-avx-avx512-linux.c: Removed.
	* features/i386/amd64-avx-linux.c: Removed.
	* features/i386/amd64-avx-mpx-avx512-pku-linux.c: Removed.
	* features/i386/amd64-avx-mpx-linux.c: Removed.
	* features/i386/amd64-linux.c: Removed.
	* features/i386/amd64-mpx-linux.c: Removed.
	* features/i386/x32-avx-avx512-linux.c: Removed.
	* features/i386/x32-avx-linux.c: Removed.
	* features/i386/x32-linux.c: Removed.
---
 gdb/features/Makefile                              |   9 -
 gdb/features/i386/amd64-avx-avx512-linux.c         | 288 ------------------
 gdb/features/i386/amd64-avx-linux.c                | 177 -----------
 gdb/features/i386/amd64-avx-mpx-avx512-pku-linux.c | 329 ---------------------
 gdb/features/i386/amd64-avx-mpx-linux.c            | 215 --------------
 gdb/features/i386/amd64-linux.c                    | 159 ----------
 gdb/features/i386/amd64-mpx-linux.c                | 197 ------------
 gdb/features/i386/x32-avx-avx512-linux.c           | 288 ------------------
 gdb/features/i386/x32-avx-linux.c                  | 177 -----------
 gdb/features/i386/x32-linux.c                      | 159 ----------
 10 files changed, 1998 deletions(-)
 delete mode 100644 gdb/features/i386/amd64-avx-avx512-linux.c
 delete mode 100644 gdb/features/i386/amd64-avx-linux.c
 delete mode 100644 gdb/features/i386/amd64-avx-mpx-avx512-pku-linux.c
 delete mode 100644 gdb/features/i386/amd64-avx-mpx-linux.c
 delete mode 100644 gdb/features/i386/amd64-linux.c
 delete mode 100644 gdb/features/i386/amd64-mpx-linux.c
 delete mode 100644 gdb/features/i386/x32-avx-avx512-linux.c
 delete mode 100644 gdb/features/i386/x32-avx-linux.c
 delete mode 100644 gdb/features/i386/x32-linux.c

diff --git a/gdb/features/Makefile b/gdb/features/Makefile
index 0f43565..7a92489 100644
--- a/gdb/features/Makefile
+++ b/gdb/features/Makefile
@@ -138,16 +138,10 @@ XMLTOC = \
 	arm/arm-with-neon.xml \
 	arm/arm-with-vfpv2.xml \
 	arm/arm-with-vfpv3.xml \
-	i386/amd64-avx-linux.xml \
 	i386/amd64-avx.xml \
-	i386/amd64-avx-avx512-linux.xml \
 	i386/amd64-avx-avx512.xml \
-	i386/amd64-avx-mpx-avx512-pku-linux.xml \
 	i386/amd64-avx-mpx-avx512-pku.xml \
-	i386/amd64-linux.xml \
-	i386/amd64-mpx-linux.xml \
 	i386/amd64-mpx.xml \
-	i386/amd64-avx-mpx-linux.xml \
 	i386/amd64-avx-mpx.xml \
 	i386/amd64.xml \
 	i386/i386-avx.xml \
@@ -157,11 +151,8 @@ XMLTOC = \
 	i386/i386-mpx.xml \
 	i386/i386-avx-mpx.xml \
 	i386/i386.xml \
-	i386/x32-avx-linux.xml \
 	i386/x32-avx.xml \
-	i386/x32-avx-avx512-linux.xml \
 	i386/x32-avx-avx512.xml \
-	i386/x32-linux.xml \
 	i386/x32.xml \
 	microblaze-with-stack-protect.xml \
 	microblaze.xml \
diff --git a/gdb/features/i386/amd64-avx-avx512-linux.c b/gdb/features/i386/amd64-avx-avx512-linux.c
deleted file mode 100644
index 6129ab1..0000000
--- a/gdb/features/i386/amd64-avx-avx512-linux.c
+++ /dev/null
@@ -1,288 +0,0 @@
-/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
-  Original: amd64-avx-avx512-linux.xml */
-
-#include "defs.h"
-#include "osabi.h"
-#include "target-descriptions.h"
-
-struct target_desc *tdesc_amd64_avx_avx512_linux;
-static void
-initialize_tdesc_amd64_avx_avx512_linux (void)
-{
-  struct target_desc *result = allocate_target_description ();
-  struct tdesc_feature *feature;
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-
-  set_tdesc_architecture (result, bfd_scan_arch ("i386:x86-64"));
-
-  set_tdesc_osabi (result, osabi_from_tdesc_string ("GNU/Linux"));
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
-  type = tdesc_create_flags (feature, "i386_eflags", 4);
-  tdesc_add_flag (type, 0, "CF");
-  tdesc_add_flag (type, 1, "");
-  tdesc_add_flag (type, 2, "PF");
-  tdesc_add_flag (type, 4, "AF");
-  tdesc_add_flag (type, 6, "ZF");
-  tdesc_add_flag (type, 7, "SF");
-  tdesc_add_flag (type, 8, "TF");
-  tdesc_add_flag (type, 9, "IF");
-  tdesc_add_flag (type, 10, "DF");
-  tdesc_add_flag (type, 11, "OF");
-  tdesc_add_flag (type, 14, "NT");
-  tdesc_add_flag (type, 16, "RF");
-  tdesc_add_flag (type, 17, "VM");
-  tdesc_add_flag (type, 18, "AC");
-  tdesc_add_flag (type, 19, "VIF");
-  tdesc_add_flag (type, 20, "VIP");
-  tdesc_add_flag (type, 21, "ID");
-
-  tdesc_create_reg (feature, "rax", 0, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rbx", 1, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rcx", 2, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rdx", 3, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rsi", 4, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rdi", 5, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rbp", 6, 1, NULL, 64, "data_ptr");
-  tdesc_create_reg (feature, "rsp", 7, 1, NULL, 64, "data_ptr");
-  tdesc_create_reg (feature, "r8", 8, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r9", 9, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r10", 10, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r11", 11, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r12", 12, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r13", 13, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r14", 14, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r15", 15, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rip", 16, 1, NULL, 64, "code_ptr");
-  tdesc_create_reg (feature, "eflags", 17, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 18, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 19, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 20, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 21, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 22, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 23, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "st0", 24, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st1", 25, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st2", 26, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st3", 27, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st4", 28, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st5", 29, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st6", 30, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st7", 31, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "fctrl", 32, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fstat", 33, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "ftag", 34, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fiseg", 35, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fioff", 36, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "foseg", 37, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fooff", 38, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fop", 39, 1, "float", 32, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.sse");
-  field_type = tdesc_named_type (feature, "ieee_single");
-  tdesc_create_vector (feature, "v4f", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "ieee_double");
-  tdesc_create_vector (feature, "v2d", field_type, 2);
-
-  field_type = tdesc_named_type (feature, "int8");
-  tdesc_create_vector (feature, "v16i8", field_type, 16);
-
-  field_type = tdesc_named_type (feature, "int16");
-  tdesc_create_vector (feature, "v8i16", field_type, 8);
-
-  field_type = tdesc_named_type (feature, "int32");
-  tdesc_create_vector (feature, "v4i32", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "int64");
-  tdesc_create_vector (feature, "v2i64", field_type, 2);
-
-  type = tdesc_create_union (feature, "vec128");
-  field_type = tdesc_named_type (feature, "v4f");
-  tdesc_add_field (type, "v4_float", field_type);
-  field_type = tdesc_named_type (feature, "v2d");
-  tdesc_add_field (type, "v2_double", field_type);
-  field_type = tdesc_named_type (feature, "v16i8");
-  tdesc_add_field (type, "v16_int8", field_type);
-  field_type = tdesc_named_type (feature, "v8i16");
-  tdesc_add_field (type, "v8_int16", field_type);
-  field_type = tdesc_named_type (feature, "v4i32");
-  tdesc_add_field (type, "v4_int32", field_type);
-  field_type = tdesc_named_type (feature, "v2i64");
-  tdesc_add_field (type, "v2_int64", field_type);
-  field_type = tdesc_named_type (feature, "uint128");
-  tdesc_add_field (type, "uint128", field_type);
-
-  type = tdesc_create_flags (feature, "i386_mxcsr", 4);
-  tdesc_add_flag (type, 0, "IE");
-  tdesc_add_flag (type, 1, "DE");
-  tdesc_add_flag (type, 2, "ZE");
-  tdesc_add_flag (type, 3, "OE");
-  tdesc_add_flag (type, 4, "UE");
-  tdesc_add_flag (type, 5, "PE");
-  tdesc_add_flag (type, 6, "DAZ");
-  tdesc_add_flag (type, 7, "IM");
-  tdesc_add_flag (type, 8, "DM");
-  tdesc_add_flag (type, 9, "ZM");
-  tdesc_add_flag (type, 10, "OM");
-  tdesc_add_flag (type, 11, "UM");
-  tdesc_add_flag (type, 12, "PM");
-  tdesc_add_flag (type, 15, "FZ");
-
-  tdesc_create_reg (feature, "xmm0", 40, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm1", 41, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm2", 42, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm3", 43, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm4", 44, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm5", 45, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm6", 46, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm7", 47, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm8", 48, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm9", 49, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm10", 50, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm11", 51, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm12", 52, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm13", 53, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm14", 54, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm15", 55, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "mxcsr", 56, 1, "vector", 32, "i386_mxcsr");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
-  tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
-  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
-  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx");
-  tdesc_create_reg (feature, "ymm0h", 60, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm1h", 61, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm2h", 62, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm3h", 63, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm4h", 64, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm5h", 65, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm6h", 66, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm7h", 67, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm8h", 68, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm9h", 69, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm10h", 70, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm11h", 71, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm12h", 72, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm13h", 73, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm14h", 74, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm15h", 75, 1, NULL, 128, "uint128");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx512");
-  field_type = tdesc_named_type (feature, "ieee_single");
-  tdesc_create_vector (feature, "v4f", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "ieee_double");
-  tdesc_create_vector (feature, "v2d", field_type, 2);
-
-  field_type = tdesc_named_type (feature, "int8");
-  tdesc_create_vector (feature, "v16i8", field_type, 16);
-
-  field_type = tdesc_named_type (feature, "int16");
-  tdesc_create_vector (feature, "v8i16", field_type, 8);
-
-  field_type = tdesc_named_type (feature, "int32");
-  tdesc_create_vector (feature, "v4i32", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "int64");
-  tdesc_create_vector (feature, "v2i64", field_type, 2);
-
-  type = tdesc_create_union (feature, "vec128");
-  field_type = tdesc_named_type (feature, "v4f");
-  tdesc_add_field (type, "v4_float", field_type);
-  field_type = tdesc_named_type (feature, "v2d");
-  tdesc_add_field (type, "v2_double", field_type);
-  field_type = tdesc_named_type (feature, "v16i8");
-  tdesc_add_field (type, "v16_int8", field_type);
-  field_type = tdesc_named_type (feature, "v8i16");
-  tdesc_add_field (type, "v8_int16", field_type);
-  field_type = tdesc_named_type (feature, "v4i32");
-  tdesc_add_field (type, "v4_int32", field_type);
-  field_type = tdesc_named_type (feature, "v2i64");
-  tdesc_add_field (type, "v2_int64", field_type);
-  field_type = tdesc_named_type (feature, "uint128");
-  tdesc_add_field (type, "uint128", field_type);
-
-  field_type = tdesc_named_type (feature, "uint128");
-  tdesc_create_vector (feature, "v2ui128", field_type, 2);
-
-  tdesc_create_reg (feature, "xmm16", 76, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm17", 77, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm18", 78, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm19", 79, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm20", 80, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm21", 81, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm22", 82, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm23", 83, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm24", 84, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm25", 85, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm26", 86, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm27", 87, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm28", 88, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm29", 89, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm30", 90, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm31", 91, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "ymm16h", 92, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm17h", 93, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm18h", 94, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm19h", 95, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm20h", 96, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm21h", 97, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm22h", 98, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm23h", 99, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm24h", 100, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm25h", 101, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm26h", 102, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm27h", 103, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm28h", 104, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm29h", 105, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm30h", 106, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm31h", 107, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "k0", 108, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k1", 109, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k2", 110, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k3", 111, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k4", 112, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k5", 113, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k6", 114, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k7", 115, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "zmm0h", 116, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm1h", 117, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm2h", 118, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm3h", 119, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm4h", 120, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm5h", 121, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm6h", 122, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm7h", 123, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm8h", 124, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm9h", 125, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm10h", 126, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm11h", 127, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm12h", 128, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm13h", 129, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm14h", 130, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm15h", 131, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm16h", 132, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm17h", 133, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm18h", 134, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm19h", 135, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm20h", 136, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm21h", 137, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm22h", 138, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm23h", 139, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm24h", 140, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm25h", 141, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm26h", 142, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm27h", 143, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm28h", 144, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm29h", 145, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm30h", 146, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm31h", 146, 1, NULL, 256, "v2ui128");
-
-  tdesc_amd64_avx_avx512_linux = result;
-}
diff --git a/gdb/features/i386/amd64-avx-linux.c b/gdb/features/i386/amd64-avx-linux.c
deleted file mode 100644
index 1d56dbf..0000000
--- a/gdb/features/i386/amd64-avx-linux.c
+++ /dev/null
@@ -1,177 +0,0 @@
-/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
-  Original: amd64-avx-linux.xml */
-
-#include "defs.h"
-#include "osabi.h"
-#include "target-descriptions.h"
-
-struct target_desc *tdesc_amd64_avx_linux;
-static void
-initialize_tdesc_amd64_avx_linux (void)
-{
-  struct target_desc *result = allocate_target_description ();
-  struct tdesc_feature *feature;
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-
-  set_tdesc_architecture (result, bfd_scan_arch ("i386:x86-64"));
-
-  set_tdesc_osabi (result, osabi_from_tdesc_string ("GNU/Linux"));
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
-  type = tdesc_create_flags (feature, "i386_eflags", 4);
-  tdesc_add_flag (type, 0, "CF");
-  tdesc_add_flag (type, 1, "");
-  tdesc_add_flag (type, 2, "PF");
-  tdesc_add_flag (type, 4, "AF");
-  tdesc_add_flag (type, 6, "ZF");
-  tdesc_add_flag (type, 7, "SF");
-  tdesc_add_flag (type, 8, "TF");
-  tdesc_add_flag (type, 9, "IF");
-  tdesc_add_flag (type, 10, "DF");
-  tdesc_add_flag (type, 11, "OF");
-  tdesc_add_flag (type, 14, "NT");
-  tdesc_add_flag (type, 16, "RF");
-  tdesc_add_flag (type, 17, "VM");
-  tdesc_add_flag (type, 18, "AC");
-  tdesc_add_flag (type, 19, "VIF");
-  tdesc_add_flag (type, 20, "VIP");
-  tdesc_add_flag (type, 21, "ID");
-
-  tdesc_create_reg (feature, "rax", 0, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rbx", 1, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rcx", 2, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rdx", 3, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rsi", 4, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rdi", 5, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rbp", 6, 1, NULL, 64, "data_ptr");
-  tdesc_create_reg (feature, "rsp", 7, 1, NULL, 64, "data_ptr");
-  tdesc_create_reg (feature, "r8", 8, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r9", 9, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r10", 10, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r11", 11, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r12", 12, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r13", 13, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r14", 14, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r15", 15, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rip", 16, 1, NULL, 64, "code_ptr");
-  tdesc_create_reg (feature, "eflags", 17, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 18, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 19, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 20, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 21, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 22, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 23, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "st0", 24, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st1", 25, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st2", 26, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st3", 27, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st4", 28, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st5", 29, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st6", 30, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st7", 31, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "fctrl", 32, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fstat", 33, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "ftag", 34, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fiseg", 35, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fioff", 36, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "foseg", 37, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fooff", 38, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fop", 39, 1, "float", 32, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.sse");
-  field_type = tdesc_named_type (feature, "ieee_single");
-  tdesc_create_vector (feature, "v4f", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "ieee_double");
-  tdesc_create_vector (feature, "v2d", field_type, 2);
-
-  field_type = tdesc_named_type (feature, "int8");
-  tdesc_create_vector (feature, "v16i8", field_type, 16);
-
-  field_type = tdesc_named_type (feature, "int16");
-  tdesc_create_vector (feature, "v8i16", field_type, 8);
-
-  field_type = tdesc_named_type (feature, "int32");
-  tdesc_create_vector (feature, "v4i32", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "int64");
-  tdesc_create_vector (feature, "v2i64", field_type, 2);
-
-  type = tdesc_create_union (feature, "vec128");
-  field_type = tdesc_named_type (feature, "v4f");
-  tdesc_add_field (type, "v4_float", field_type);
-  field_type = tdesc_named_type (feature, "v2d");
-  tdesc_add_field (type, "v2_double", field_type);
-  field_type = tdesc_named_type (feature, "v16i8");
-  tdesc_add_field (type, "v16_int8", field_type);
-  field_type = tdesc_named_type (feature, "v8i16");
-  tdesc_add_field (type, "v8_int16", field_type);
-  field_type = tdesc_named_type (feature, "v4i32");
-  tdesc_add_field (type, "v4_int32", field_type);
-  field_type = tdesc_named_type (feature, "v2i64");
-  tdesc_add_field (type, "v2_int64", field_type);
-  field_type = tdesc_named_type (feature, "uint128");
-  tdesc_add_field (type, "uint128", field_type);
-
-  type = tdesc_create_flags (feature, "i386_mxcsr", 4);
-  tdesc_add_flag (type, 0, "IE");
-  tdesc_add_flag (type, 1, "DE");
-  tdesc_add_flag (type, 2, "ZE");
-  tdesc_add_flag (type, 3, "OE");
-  tdesc_add_flag (type, 4, "UE");
-  tdesc_add_flag (type, 5, "PE");
-  tdesc_add_flag (type, 6, "DAZ");
-  tdesc_add_flag (type, 7, "IM");
-  tdesc_add_flag (type, 8, "DM");
-  tdesc_add_flag (type, 9, "ZM");
-  tdesc_add_flag (type, 10, "OM");
-  tdesc_add_flag (type, 11, "UM");
-  tdesc_add_flag (type, 12, "PM");
-  tdesc_add_flag (type, 15, "FZ");
-
-  tdesc_create_reg (feature, "xmm0", 40, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm1", 41, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm2", 42, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm3", 43, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm4", 44, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm5", 45, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm6", 46, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm7", 47, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm8", 48, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm9", 49, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm10", 50, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm11", 51, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm12", 52, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm13", 53, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm14", 54, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm15", 55, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "mxcsr", 56, 1, "vector", 32, "i386_mxcsr");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
-  tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
-  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
-  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx");
-  tdesc_create_reg (feature, "ymm0h", 60, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm1h", 61, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm2h", 62, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm3h", 63, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm4h", 64, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm5h", 65, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm6h", 66, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm7h", 67, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm8h", 68, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm9h", 69, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm10h", 70, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm11h", 71, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm12h", 72, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm13h", 73, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm14h", 74, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm15h", 75, 1, NULL, 128, "uint128");
-
-  tdesc_amd64_avx_linux = result;
-}
diff --git a/gdb/features/i386/amd64-avx-mpx-avx512-pku-linux.c b/gdb/features/i386/amd64-avx-mpx-avx512-pku-linux.c
deleted file mode 100644
index 248eff7..0000000
--- a/gdb/features/i386/amd64-avx-mpx-avx512-pku-linux.c
+++ /dev/null
@@ -1,329 +0,0 @@
-/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
-  Original: amd64-avx-mpx-avx512-pku-linux.xml */
-
-#include "defs.h"
-#include "osabi.h"
-#include "target-descriptions.h"
-
-struct target_desc *tdesc_amd64_avx_mpx_avx512_pku_linux;
-static void
-initialize_tdesc_amd64_avx_mpx_avx512_pku_linux (void)
-{
-  struct target_desc *result = allocate_target_description ();
-  struct tdesc_feature *feature;
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-
-  set_tdesc_architecture (result, bfd_scan_arch ("i386:x86-64"));
-
-  set_tdesc_osabi (result, osabi_from_tdesc_string ("GNU/Linux"));
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
-  type = tdesc_create_flags (feature, "i386_eflags", 4);
-  tdesc_add_flag (type, 0, "CF");
-  tdesc_add_flag (type, 1, "");
-  tdesc_add_flag (type, 2, "PF");
-  tdesc_add_flag (type, 4, "AF");
-  tdesc_add_flag (type, 6, "ZF");
-  tdesc_add_flag (type, 7, "SF");
-  tdesc_add_flag (type, 8, "TF");
-  tdesc_add_flag (type, 9, "IF");
-  tdesc_add_flag (type, 10, "DF");
-  tdesc_add_flag (type, 11, "OF");
-  tdesc_add_flag (type, 14, "NT");
-  tdesc_add_flag (type, 16, "RF");
-  tdesc_add_flag (type, 17, "VM");
-  tdesc_add_flag (type, 18, "AC");
-  tdesc_add_flag (type, 19, "VIF");
-  tdesc_add_flag (type, 20, "VIP");
-  tdesc_add_flag (type, 21, "ID");
-
-  tdesc_create_reg (feature, "rax", 0, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rbx", 1, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rcx", 2, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rdx", 3, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rsi", 4, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rdi", 5, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rbp", 6, 1, NULL, 64, "data_ptr");
-  tdesc_create_reg (feature, "rsp", 7, 1, NULL, 64, "data_ptr");
-  tdesc_create_reg (feature, "r8", 8, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r9", 9, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r10", 10, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r11", 11, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r12", 12, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r13", 13, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r14", 14, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r15", 15, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rip", 16, 1, NULL, 64, "code_ptr");
-  tdesc_create_reg (feature, "eflags", 17, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 18, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 19, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 20, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 21, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 22, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 23, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "st0", 24, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st1", 25, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st2", 26, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st3", 27, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st4", 28, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st5", 29, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st6", 30, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st7", 31, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "fctrl", 32, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fstat", 33, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "ftag", 34, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fiseg", 35, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fioff", 36, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "foseg", 37, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fooff", 38, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fop", 39, 1, "float", 32, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.sse");
-  field_type = tdesc_named_type (feature, "ieee_single");
-  tdesc_create_vector (feature, "v4f", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "ieee_double");
-  tdesc_create_vector (feature, "v2d", field_type, 2);
-
-  field_type = tdesc_named_type (feature, "int8");
-  tdesc_create_vector (feature, "v16i8", field_type, 16);
-
-  field_type = tdesc_named_type (feature, "int16");
-  tdesc_create_vector (feature, "v8i16", field_type, 8);
-
-  field_type = tdesc_named_type (feature, "int32");
-  tdesc_create_vector (feature, "v4i32", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "int64");
-  tdesc_create_vector (feature, "v2i64", field_type, 2);
-
-  type = tdesc_create_union (feature, "vec128");
-  field_type = tdesc_named_type (feature, "v4f");
-  tdesc_add_field (type, "v4_float", field_type);
-  field_type = tdesc_named_type (feature, "v2d");
-  tdesc_add_field (type, "v2_double", field_type);
-  field_type = tdesc_named_type (feature, "v16i8");
-  tdesc_add_field (type, "v16_int8", field_type);
-  field_type = tdesc_named_type (feature, "v8i16");
-  tdesc_add_field (type, "v8_int16", field_type);
-  field_type = tdesc_named_type (feature, "v4i32");
-  tdesc_add_field (type, "v4_int32", field_type);
-  field_type = tdesc_named_type (feature, "v2i64");
-  tdesc_add_field (type, "v2_int64", field_type);
-  field_type = tdesc_named_type (feature, "uint128");
-  tdesc_add_field (type, "uint128", field_type);
-
-  type = tdesc_create_flags (feature, "i386_mxcsr", 4);
-  tdesc_add_flag (type, 0, "IE");
-  tdesc_add_flag (type, 1, "DE");
-  tdesc_add_flag (type, 2, "ZE");
-  tdesc_add_flag (type, 3, "OE");
-  tdesc_add_flag (type, 4, "UE");
-  tdesc_add_flag (type, 5, "PE");
-  tdesc_add_flag (type, 6, "DAZ");
-  tdesc_add_flag (type, 7, "IM");
-  tdesc_add_flag (type, 8, "DM");
-  tdesc_add_flag (type, 9, "ZM");
-  tdesc_add_flag (type, 10, "OM");
-  tdesc_add_flag (type, 11, "UM");
-  tdesc_add_flag (type, 12, "PM");
-  tdesc_add_flag (type, 15, "FZ");
-
-  tdesc_create_reg (feature, "xmm0", 40, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm1", 41, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm2", 42, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm3", 43, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm4", 44, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm5", 45, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm6", 46, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm7", 47, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm8", 48, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm9", 49, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm10", 50, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm11", 51, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm12", 52, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm13", 53, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm14", 54, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm15", 55, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "mxcsr", 56, 1, "vector", 32, "i386_mxcsr");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
-  tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
-  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
-  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx");
-  tdesc_create_reg (feature, "ymm0h", 60, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm1h", 61, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm2h", 62, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm3h", 63, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm4h", 64, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm5h", 65, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm6h", 66, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm7h", 67, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm8h", 68, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm9h", 69, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm10h", 70, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm11h", 71, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm12h", 72, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm13h", 73, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm14h", 74, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm15h", 75, 1, NULL, 128, "uint128");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.mpx");
-  type = tdesc_create_struct (feature, "br128");
-  field_type = tdesc_named_type (feature, "uint64");
-  tdesc_add_field (type, "lbound", field_type);
-  field_type = tdesc_named_type (feature, "uint64");
-  tdesc_add_field (type, "ubound_raw", field_type);
-
-  type = tdesc_create_struct (feature, "_bndstatus");
-  tdesc_set_struct_size (type, 8);
-  tdesc_add_bitfield (type, "bde", 2, 63);
-  tdesc_add_bitfield (type, "error", 0, 1);
-
-  type = tdesc_create_union (feature, "status");
-  field_type = tdesc_named_type (feature, "data_ptr");
-  tdesc_add_field (type, "raw", field_type);
-  field_type = tdesc_named_type (feature, "_bndstatus");
-  tdesc_add_field (type, "status", field_type);
-
-  type = tdesc_create_struct (feature, "_bndcfgu");
-  tdesc_set_struct_size (type, 8);
-  tdesc_add_bitfield (type, "base", 12, 63);
-  tdesc_add_bitfield (type, "reserved", 2, 11);
-  tdesc_add_bitfield (type, "preserved", 1, 1);
-  tdesc_add_bitfield (type, "enabled", 0, 0);
-
-  type = tdesc_create_union (feature, "cfgu");
-  field_type = tdesc_named_type (feature, "data_ptr");
-  tdesc_add_field (type, "raw", field_type);
-  field_type = tdesc_named_type (feature, "_bndcfgu");
-  tdesc_add_field (type, "config", field_type);
-
-  tdesc_create_reg (feature, "bnd0raw", 76, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd1raw", 77, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd2raw", 78, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd3raw", 79, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bndcfgu", 80, 1, NULL, 64, "cfgu");
-  tdesc_create_reg (feature, "bndstatus", 81, 1, NULL, 64, "status");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx512");
-  field_type = tdesc_named_type (feature, "ieee_single");
-  tdesc_create_vector (feature, "v4f", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "ieee_double");
-  tdesc_create_vector (feature, "v2d", field_type, 2);
-
-  field_type = tdesc_named_type (feature, "int8");
-  tdesc_create_vector (feature, "v16i8", field_type, 16);
-
-  field_type = tdesc_named_type (feature, "int16");
-  tdesc_create_vector (feature, "v8i16", field_type, 8);
-
-  field_type = tdesc_named_type (feature, "int32");
-  tdesc_create_vector (feature, "v4i32", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "int64");
-  tdesc_create_vector (feature, "v2i64", field_type, 2);
-
-  type = tdesc_create_union (feature, "vec128");
-  field_type = tdesc_named_type (feature, "v4f");
-  tdesc_add_field (type, "v4_float", field_type);
-  field_type = tdesc_named_type (feature, "v2d");
-  tdesc_add_field (type, "v2_double", field_type);
-  field_type = tdesc_named_type (feature, "v16i8");
-  tdesc_add_field (type, "v16_int8", field_type);
-  field_type = tdesc_named_type (feature, "v8i16");
-  tdesc_add_field (type, "v8_int16", field_type);
-  field_type = tdesc_named_type (feature, "v4i32");
-  tdesc_add_field (type, "v4_int32", field_type);
-  field_type = tdesc_named_type (feature, "v2i64");
-  tdesc_add_field (type, "v2_int64", field_type);
-  field_type = tdesc_named_type (feature, "uint128");
-  tdesc_add_field (type, "uint128", field_type);
-
-  field_type = tdesc_named_type (feature, "uint128");
-  tdesc_create_vector (feature, "v2ui128", field_type, 2);
-
-  tdesc_create_reg (feature, "xmm16", 82, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm17", 83, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm18", 84, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm19", 85, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm20", 86, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm21", 87, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm22", 88, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm23", 89, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm24", 90, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm25", 91, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm26", 92, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm27", 93, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm28", 94, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm29", 95, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm30", 96, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm31", 97, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "ymm16h", 98, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm17h", 99, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm18h", 100, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm19h", 101, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm20h", 102, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm21h", 103, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm22h", 104, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm23h", 105, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm24h", 106, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm25h", 107, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm26h", 108, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm27h", 109, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm28h", 110, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm29h", 111, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm30h", 112, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm31h", 113, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "k0", 114, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k1", 115, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k2", 116, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k3", 117, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k4", 118, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k5", 119, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k6", 120, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k7", 121, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "zmm0h", 122, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm1h", 123, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm2h", 124, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm3h", 125, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm4h", 126, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm5h", 127, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm6h", 128, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm7h", 129, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm8h", 130, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm9h", 131, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm10h", 132, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm11h", 133, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm12h", 134, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm13h", 135, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm14h", 136, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm15h", 137, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm16h", 138, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm17h", 139, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm18h", 140, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm19h", 141, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm20h", 142, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm21h", 143, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm22h", 144, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm23h", 145, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm24h", 146, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm25h", 147, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm26h", 148, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm27h", 149, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm28h", 150, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm29h", 151, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm30h", 152, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm31h", 153, 1, NULL, 256, "v2ui128");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.pkeys");
-  tdesc_create_reg (feature, "pkru", 152, 1, NULL, 32, "uint32");
-
-  tdesc_amd64_avx_mpx_avx512_pku_linux = result;
-}
diff --git a/gdb/features/i386/amd64-avx-mpx-linux.c b/gdb/features/i386/amd64-avx-mpx-linux.c
deleted file mode 100644
index 26c1339..0000000
--- a/gdb/features/i386/amd64-avx-mpx-linux.c
+++ /dev/null
@@ -1,215 +0,0 @@
-/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
-  Original: amd64-avx-mpx-linux.xml */
-
-#include "defs.h"
-#include "osabi.h"
-#include "target-descriptions.h"
-
-struct target_desc *tdesc_amd64_avx_mpx_linux;
-static void
-initialize_tdesc_amd64_avx_mpx_linux (void)
-{
-  struct target_desc *result = allocate_target_description ();
-  struct tdesc_feature *feature;
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-
-  set_tdesc_architecture (result, bfd_scan_arch ("i386:x86-64"));
-
-  set_tdesc_osabi (result, osabi_from_tdesc_string ("GNU/Linux"));
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
-  type = tdesc_create_flags (feature, "i386_eflags", 4);
-  tdesc_add_flag (type, 0, "CF");
-  tdesc_add_flag (type, 1, "");
-  tdesc_add_flag (type, 2, "PF");
-  tdesc_add_flag (type, 4, "AF");
-  tdesc_add_flag (type, 6, "ZF");
-  tdesc_add_flag (type, 7, "SF");
-  tdesc_add_flag (type, 8, "TF");
-  tdesc_add_flag (type, 9, "IF");
-  tdesc_add_flag (type, 10, "DF");
-  tdesc_add_flag (type, 11, "OF");
-  tdesc_add_flag (type, 14, "NT");
-  tdesc_add_flag (type, 16, "RF");
-  tdesc_add_flag (type, 17, "VM");
-  tdesc_add_flag (type, 18, "AC");
-  tdesc_add_flag (type, 19, "VIF");
-  tdesc_add_flag (type, 20, "VIP");
-  tdesc_add_flag (type, 21, "ID");
-
-  tdesc_create_reg (feature, "rax", 0, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rbx", 1, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rcx", 2, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rdx", 3, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rsi", 4, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rdi", 5, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rbp", 6, 1, NULL, 64, "data_ptr");
-  tdesc_create_reg (feature, "rsp", 7, 1, NULL, 64, "data_ptr");
-  tdesc_create_reg (feature, "r8", 8, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r9", 9, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r10", 10, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r11", 11, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r12", 12, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r13", 13, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r14", 14, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r15", 15, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rip", 16, 1, NULL, 64, "code_ptr");
-  tdesc_create_reg (feature, "eflags", 17, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 18, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 19, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 20, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 21, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 22, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 23, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "st0", 24, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st1", 25, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st2", 26, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st3", 27, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st4", 28, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st5", 29, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st6", 30, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st7", 31, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "fctrl", 32, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fstat", 33, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "ftag", 34, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fiseg", 35, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fioff", 36, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "foseg", 37, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fooff", 38, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fop", 39, 1, "float", 32, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.sse");
-  field_type = tdesc_named_type (feature, "ieee_single");
-  tdesc_create_vector (feature, "v4f", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "ieee_double");
-  tdesc_create_vector (feature, "v2d", field_type, 2);
-
-  field_type = tdesc_named_type (feature, "int8");
-  tdesc_create_vector (feature, "v16i8", field_type, 16);
-
-  field_type = tdesc_named_type (feature, "int16");
-  tdesc_create_vector (feature, "v8i16", field_type, 8);
-
-  field_type = tdesc_named_type (feature, "int32");
-  tdesc_create_vector (feature, "v4i32", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "int64");
-  tdesc_create_vector (feature, "v2i64", field_type, 2);
-
-  type = tdesc_create_union (feature, "vec128");
-  field_type = tdesc_named_type (feature, "v4f");
-  tdesc_add_field (type, "v4_float", field_type);
-  field_type = tdesc_named_type (feature, "v2d");
-  tdesc_add_field (type, "v2_double", field_type);
-  field_type = tdesc_named_type (feature, "v16i8");
-  tdesc_add_field (type, "v16_int8", field_type);
-  field_type = tdesc_named_type (feature, "v8i16");
-  tdesc_add_field (type, "v8_int16", field_type);
-  field_type = tdesc_named_type (feature, "v4i32");
-  tdesc_add_field (type, "v4_int32", field_type);
-  field_type = tdesc_named_type (feature, "v2i64");
-  tdesc_add_field (type, "v2_int64", field_type);
-  field_type = tdesc_named_type (feature, "uint128");
-  tdesc_add_field (type, "uint128", field_type);
-
-  type = tdesc_create_flags (feature, "i386_mxcsr", 4);
-  tdesc_add_flag (type, 0, "IE");
-  tdesc_add_flag (type, 1, "DE");
-  tdesc_add_flag (type, 2, "ZE");
-  tdesc_add_flag (type, 3, "OE");
-  tdesc_add_flag (type, 4, "UE");
-  tdesc_add_flag (type, 5, "PE");
-  tdesc_add_flag (type, 6, "DAZ");
-  tdesc_add_flag (type, 7, "IM");
-  tdesc_add_flag (type, 8, "DM");
-  tdesc_add_flag (type, 9, "ZM");
-  tdesc_add_flag (type, 10, "OM");
-  tdesc_add_flag (type, 11, "UM");
-  tdesc_add_flag (type, 12, "PM");
-  tdesc_add_flag (type, 15, "FZ");
-
-  tdesc_create_reg (feature, "xmm0", 40, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm1", 41, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm2", 42, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm3", 43, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm4", 44, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm5", 45, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm6", 46, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm7", 47, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm8", 48, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm9", 49, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm10", 50, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm11", 51, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm12", 52, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm13", 53, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm14", 54, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm15", 55, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "mxcsr", 56, 1, "vector", 32, "i386_mxcsr");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
-  tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
-  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
-  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx");
-  tdesc_create_reg (feature, "ymm0h", 60, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm1h", 61, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm2h", 62, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm3h", 63, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm4h", 64, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm5h", 65, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm6h", 66, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm7h", 67, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm8h", 68, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm9h", 69, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm10h", 70, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm11h", 71, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm12h", 72, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm13h", 73, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm14h", 74, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm15h", 75, 1, NULL, 128, "uint128");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.mpx");
-  type = tdesc_create_struct (feature, "br128");
-  field_type = tdesc_named_type (feature, "uint64");
-  tdesc_add_field (type, "lbound", field_type);
-  field_type = tdesc_named_type (feature, "uint64");
-  tdesc_add_field (type, "ubound_raw", field_type);
-
-  type = tdesc_create_struct (feature, "_bndstatus");
-  tdesc_set_struct_size (type, 8);
-  tdesc_add_bitfield (type, "bde", 2, 63);
-  tdesc_add_bitfield (type, "error", 0, 1);
-
-  type = tdesc_create_union (feature, "status");
-  field_type = tdesc_named_type (feature, "data_ptr");
-  tdesc_add_field (type, "raw", field_type);
-  field_type = tdesc_named_type (feature, "_bndstatus");
-  tdesc_add_field (type, "status", field_type);
-
-  type = tdesc_create_struct (feature, "_bndcfgu");
-  tdesc_set_struct_size (type, 8);
-  tdesc_add_bitfield (type, "base", 12, 63);
-  tdesc_add_bitfield (type, "reserved", 2, 11);
-  tdesc_add_bitfield (type, "preserved", 1, 1);
-  tdesc_add_bitfield (type, "enabled", 0, 0);
-
-  type = tdesc_create_union (feature, "cfgu");
-  field_type = tdesc_named_type (feature, "data_ptr");
-  tdesc_add_field (type, "raw", field_type);
-  field_type = tdesc_named_type (feature, "_bndcfgu");
-  tdesc_add_field (type, "config", field_type);
-
-  tdesc_create_reg (feature, "bnd0raw", 76, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd1raw", 77, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd2raw", 78, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd3raw", 79, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bndcfgu", 80, 1, NULL, 64, "cfgu");
-  tdesc_create_reg (feature, "bndstatus", 81, 1, NULL, 64, "status");
-
-  tdesc_amd64_avx_mpx_linux = result;
-}
diff --git a/gdb/features/i386/amd64-linux.c b/gdb/features/i386/amd64-linux.c
deleted file mode 100644
index 0e921ba9..0000000
--- a/gdb/features/i386/amd64-linux.c
+++ /dev/null
@@ -1,159 +0,0 @@
-/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
-  Original: amd64-linux.xml */
-
-#include "defs.h"
-#include "osabi.h"
-#include "target-descriptions.h"
-
-struct target_desc *tdesc_amd64_linux;
-static void
-initialize_tdesc_amd64_linux (void)
-{
-  struct target_desc *result = allocate_target_description ();
-  struct tdesc_feature *feature;
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-
-  set_tdesc_architecture (result, bfd_scan_arch ("i386:x86-64"));
-
-  set_tdesc_osabi (result, osabi_from_tdesc_string ("GNU/Linux"));
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
-  type = tdesc_create_flags (feature, "i386_eflags", 4);
-  tdesc_add_flag (type, 0, "CF");
-  tdesc_add_flag (type, 1, "");
-  tdesc_add_flag (type, 2, "PF");
-  tdesc_add_flag (type, 4, "AF");
-  tdesc_add_flag (type, 6, "ZF");
-  tdesc_add_flag (type, 7, "SF");
-  tdesc_add_flag (type, 8, "TF");
-  tdesc_add_flag (type, 9, "IF");
-  tdesc_add_flag (type, 10, "DF");
-  tdesc_add_flag (type, 11, "OF");
-  tdesc_add_flag (type, 14, "NT");
-  tdesc_add_flag (type, 16, "RF");
-  tdesc_add_flag (type, 17, "VM");
-  tdesc_add_flag (type, 18, "AC");
-  tdesc_add_flag (type, 19, "VIF");
-  tdesc_add_flag (type, 20, "VIP");
-  tdesc_add_flag (type, 21, "ID");
-
-  tdesc_create_reg (feature, "rax", 0, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rbx", 1, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rcx", 2, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rdx", 3, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rsi", 4, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rdi", 5, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rbp", 6, 1, NULL, 64, "data_ptr");
-  tdesc_create_reg (feature, "rsp", 7, 1, NULL, 64, "data_ptr");
-  tdesc_create_reg (feature, "r8", 8, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r9", 9, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r10", 10, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r11", 11, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r12", 12, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r13", 13, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r14", 14, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r15", 15, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rip", 16, 1, NULL, 64, "code_ptr");
-  tdesc_create_reg (feature, "eflags", 17, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 18, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 19, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 20, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 21, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 22, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 23, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "st0", 24, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st1", 25, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st2", 26, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st3", 27, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st4", 28, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st5", 29, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st6", 30, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st7", 31, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "fctrl", 32, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fstat", 33, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "ftag", 34, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fiseg", 35, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fioff", 36, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "foseg", 37, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fooff", 38, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fop", 39, 1, "float", 32, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.sse");
-  field_type = tdesc_named_type (feature, "ieee_single");
-  tdesc_create_vector (feature, "v4f", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "ieee_double");
-  tdesc_create_vector (feature, "v2d", field_type, 2);
-
-  field_type = tdesc_named_type (feature, "int8");
-  tdesc_create_vector (feature, "v16i8", field_type, 16);
-
-  field_type = tdesc_named_type (feature, "int16");
-  tdesc_create_vector (feature, "v8i16", field_type, 8);
-
-  field_type = tdesc_named_type (feature, "int32");
-  tdesc_create_vector (feature, "v4i32", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "int64");
-  tdesc_create_vector (feature, "v2i64", field_type, 2);
-
-  type = tdesc_create_union (feature, "vec128");
-  field_type = tdesc_named_type (feature, "v4f");
-  tdesc_add_field (type, "v4_float", field_type);
-  field_type = tdesc_named_type (feature, "v2d");
-  tdesc_add_field (type, "v2_double", field_type);
-  field_type = tdesc_named_type (feature, "v16i8");
-  tdesc_add_field (type, "v16_int8", field_type);
-  field_type = tdesc_named_type (feature, "v8i16");
-  tdesc_add_field (type, "v8_int16", field_type);
-  field_type = tdesc_named_type (feature, "v4i32");
-  tdesc_add_field (type, "v4_int32", field_type);
-  field_type = tdesc_named_type (feature, "v2i64");
-  tdesc_add_field (type, "v2_int64", field_type);
-  field_type = tdesc_named_type (feature, "uint128");
-  tdesc_add_field (type, "uint128", field_type);
-
-  type = tdesc_create_flags (feature, "i386_mxcsr", 4);
-  tdesc_add_flag (type, 0, "IE");
-  tdesc_add_flag (type, 1, "DE");
-  tdesc_add_flag (type, 2, "ZE");
-  tdesc_add_flag (type, 3, "OE");
-  tdesc_add_flag (type, 4, "UE");
-  tdesc_add_flag (type, 5, "PE");
-  tdesc_add_flag (type, 6, "DAZ");
-  tdesc_add_flag (type, 7, "IM");
-  tdesc_add_flag (type, 8, "DM");
-  tdesc_add_flag (type, 9, "ZM");
-  tdesc_add_flag (type, 10, "OM");
-  tdesc_add_flag (type, 11, "UM");
-  tdesc_add_flag (type, 12, "PM");
-  tdesc_add_flag (type, 15, "FZ");
-
-  tdesc_create_reg (feature, "xmm0", 40, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm1", 41, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm2", 42, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm3", 43, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm4", 44, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm5", 45, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm6", 46, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm7", 47, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm8", 48, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm9", 49, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm10", 50, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm11", 51, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm12", 52, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm13", 53, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm14", 54, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm15", 55, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "mxcsr", 56, 1, "vector", 32, "i386_mxcsr");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
-  tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
-  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
-  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
-
-  tdesc_amd64_linux = result;
-}
diff --git a/gdb/features/i386/amd64-mpx-linux.c b/gdb/features/i386/amd64-mpx-linux.c
deleted file mode 100644
index e26a74a..0000000
--- a/gdb/features/i386/amd64-mpx-linux.c
+++ /dev/null
@@ -1,197 +0,0 @@
-/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
-  Original: amd64-mpx-linux.xml */
-
-#include "defs.h"
-#include "osabi.h"
-#include "target-descriptions.h"
-
-struct target_desc *tdesc_amd64_mpx_linux;
-static void
-initialize_tdesc_amd64_mpx_linux (void)
-{
-  struct target_desc *result = allocate_target_description ();
-  struct tdesc_feature *feature;
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-
-  set_tdesc_architecture (result, bfd_scan_arch ("i386:x86-64"));
-
-  set_tdesc_osabi (result, osabi_from_tdesc_string ("GNU/Linux"));
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
-  type = tdesc_create_flags (feature, "i386_eflags", 4);
-  tdesc_add_flag (type, 0, "CF");
-  tdesc_add_flag (type, 1, "");
-  tdesc_add_flag (type, 2, "PF");
-  tdesc_add_flag (type, 4, "AF");
-  tdesc_add_flag (type, 6, "ZF");
-  tdesc_add_flag (type, 7, "SF");
-  tdesc_add_flag (type, 8, "TF");
-  tdesc_add_flag (type, 9, "IF");
-  tdesc_add_flag (type, 10, "DF");
-  tdesc_add_flag (type, 11, "OF");
-  tdesc_add_flag (type, 14, "NT");
-  tdesc_add_flag (type, 16, "RF");
-  tdesc_add_flag (type, 17, "VM");
-  tdesc_add_flag (type, 18, "AC");
-  tdesc_add_flag (type, 19, "VIF");
-  tdesc_add_flag (type, 20, "VIP");
-  tdesc_add_flag (type, 21, "ID");
-
-  tdesc_create_reg (feature, "rax", 0, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rbx", 1, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rcx", 2, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rdx", 3, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rsi", 4, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rdi", 5, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rbp", 6, 1, NULL, 64, "data_ptr");
-  tdesc_create_reg (feature, "rsp", 7, 1, NULL, 64, "data_ptr");
-  tdesc_create_reg (feature, "r8", 8, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r9", 9, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r10", 10, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r11", 11, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r12", 12, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r13", 13, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r14", 14, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r15", 15, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rip", 16, 1, NULL, 64, "code_ptr");
-  tdesc_create_reg (feature, "eflags", 17, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 18, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 19, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 20, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 21, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 22, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 23, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "st0", 24, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st1", 25, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st2", 26, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st3", 27, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st4", 28, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st5", 29, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st6", 30, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st7", 31, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "fctrl", 32, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fstat", 33, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "ftag", 34, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fiseg", 35, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fioff", 36, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "foseg", 37, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fooff", 38, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fop", 39, 1, "float", 32, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.sse");
-  field_type = tdesc_named_type (feature, "ieee_single");
-  tdesc_create_vector (feature, "v4f", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "ieee_double");
-  tdesc_create_vector (feature, "v2d", field_type, 2);
-
-  field_type = tdesc_named_type (feature, "int8");
-  tdesc_create_vector (feature, "v16i8", field_type, 16);
-
-  field_type = tdesc_named_type (feature, "int16");
-  tdesc_create_vector (feature, "v8i16", field_type, 8);
-
-  field_type = tdesc_named_type (feature, "int32");
-  tdesc_create_vector (feature, "v4i32", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "int64");
-  tdesc_create_vector (feature, "v2i64", field_type, 2);
-
-  type = tdesc_create_union (feature, "vec128");
-  field_type = tdesc_named_type (feature, "v4f");
-  tdesc_add_field (type, "v4_float", field_type);
-  field_type = tdesc_named_type (feature, "v2d");
-  tdesc_add_field (type, "v2_double", field_type);
-  field_type = tdesc_named_type (feature, "v16i8");
-  tdesc_add_field (type, "v16_int8", field_type);
-  field_type = tdesc_named_type (feature, "v8i16");
-  tdesc_add_field (type, "v8_int16", field_type);
-  field_type = tdesc_named_type (feature, "v4i32");
-  tdesc_add_field (type, "v4_int32", field_type);
-  field_type = tdesc_named_type (feature, "v2i64");
-  tdesc_add_field (type, "v2_int64", field_type);
-  field_type = tdesc_named_type (feature, "uint128");
-  tdesc_add_field (type, "uint128", field_type);
-
-  type = tdesc_create_flags (feature, "i386_mxcsr", 4);
-  tdesc_add_flag (type, 0, "IE");
-  tdesc_add_flag (type, 1, "DE");
-  tdesc_add_flag (type, 2, "ZE");
-  tdesc_add_flag (type, 3, "OE");
-  tdesc_add_flag (type, 4, "UE");
-  tdesc_add_flag (type, 5, "PE");
-  tdesc_add_flag (type, 6, "DAZ");
-  tdesc_add_flag (type, 7, "IM");
-  tdesc_add_flag (type, 8, "DM");
-  tdesc_add_flag (type, 9, "ZM");
-  tdesc_add_flag (type, 10, "OM");
-  tdesc_add_flag (type, 11, "UM");
-  tdesc_add_flag (type, 12, "PM");
-  tdesc_add_flag (type, 15, "FZ");
-
-  tdesc_create_reg (feature, "xmm0", 40, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm1", 41, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm2", 42, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm3", 43, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm4", 44, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm5", 45, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm6", 46, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm7", 47, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm8", 48, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm9", 49, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm10", 50, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm11", 51, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm12", 52, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm13", 53, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm14", 54, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm15", 55, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "mxcsr", 56, 1, "vector", 32, "i386_mxcsr");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
-  tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
-  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
-  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.mpx");
-  type = tdesc_create_struct (feature, "br128");
-  field_type = tdesc_named_type (feature, "uint64");
-  tdesc_add_field (type, "lbound", field_type);
-  field_type = tdesc_named_type (feature, "uint64");
-  tdesc_add_field (type, "ubound_raw", field_type);
-
-  type = tdesc_create_struct (feature, "_bndstatus");
-  tdesc_set_struct_size (type, 8);
-  tdesc_add_bitfield (type, "bde", 2, 63);
-  tdesc_add_bitfield (type, "error", 0, 1);
-
-  type = tdesc_create_union (feature, "status");
-  field_type = tdesc_named_type (feature, "data_ptr");
-  tdesc_add_field (type, "raw", field_type);
-  field_type = tdesc_named_type (feature, "_bndstatus");
-  tdesc_add_field (type, "status", field_type);
-
-  type = tdesc_create_struct (feature, "_bndcfgu");
-  tdesc_set_struct_size (type, 8);
-  tdesc_add_bitfield (type, "base", 12, 63);
-  tdesc_add_bitfield (type, "reserved", 2, 11);
-  tdesc_add_bitfield (type, "preserved", 1, 1);
-  tdesc_add_bitfield (type, "enabled", 0, 0);
-
-  type = tdesc_create_union (feature, "cfgu");
-  field_type = tdesc_named_type (feature, "data_ptr");
-  tdesc_add_field (type, "raw", field_type);
-  field_type = tdesc_named_type (feature, "_bndcfgu");
-  tdesc_add_field (type, "config", field_type);
-
-  tdesc_create_reg (feature, "bnd0raw", 60, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd1raw", 61, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd2raw", 62, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd3raw", 63, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bndcfgu", 64, 1, NULL, 64, "cfgu");
-  tdesc_create_reg (feature, "bndstatus", 65, 1, NULL, 64, "status");
-
-  tdesc_amd64_mpx_linux = result;
-}
diff --git a/gdb/features/i386/x32-avx-avx512-linux.c b/gdb/features/i386/x32-avx-avx512-linux.c
deleted file mode 100644
index 0467d87..0000000
--- a/gdb/features/i386/x32-avx-avx512-linux.c
+++ /dev/null
@@ -1,288 +0,0 @@
-/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
-  Original: x32-avx-avx512-linux.xml */
-
-#include "defs.h"
-#include "osabi.h"
-#include "target-descriptions.h"
-
-struct target_desc *tdesc_x32_avx_avx512_linux;
-static void
-initialize_tdesc_x32_avx_avx512_linux (void)
-{
-  struct target_desc *result = allocate_target_description ();
-  struct tdesc_feature *feature;
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-
-  set_tdesc_architecture (result, bfd_scan_arch ("i386:x64-32"));
-
-  set_tdesc_osabi (result, osabi_from_tdesc_string ("GNU/Linux"));
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
-  type = tdesc_create_flags (feature, "i386_eflags", 4);
-  tdesc_add_flag (type, 0, "CF");
-  tdesc_add_flag (type, 1, "");
-  tdesc_add_flag (type, 2, "PF");
-  tdesc_add_flag (type, 4, "AF");
-  tdesc_add_flag (type, 6, "ZF");
-  tdesc_add_flag (type, 7, "SF");
-  tdesc_add_flag (type, 8, "TF");
-  tdesc_add_flag (type, 9, "IF");
-  tdesc_add_flag (type, 10, "DF");
-  tdesc_add_flag (type, 11, "OF");
-  tdesc_add_flag (type, 14, "NT");
-  tdesc_add_flag (type, 16, "RF");
-  tdesc_add_flag (type, 17, "VM");
-  tdesc_add_flag (type, 18, "AC");
-  tdesc_add_flag (type, 19, "VIF");
-  tdesc_add_flag (type, 20, "VIP");
-  tdesc_add_flag (type, 21, "ID");
-
-  tdesc_create_reg (feature, "rax", 0, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rbx", 1, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rcx", 2, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rdx", 3, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rsi", 4, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rdi", 5, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rbp", 6, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rsp", 7, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r8", 8, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r9", 9, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r10", 10, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r11", 11, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r12", 12, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r13", 13, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r14", 14, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r15", 15, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rip", 16, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "eflags", 17, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 18, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 19, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 20, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 21, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 22, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 23, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "st0", 24, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st1", 25, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st2", 26, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st3", 27, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st4", 28, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st5", 29, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st6", 30, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st7", 31, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "fctrl", 32, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fstat", 33, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "ftag", 34, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fiseg", 35, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fioff", 36, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "foseg", 37, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fooff", 38, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fop", 39, 1, "float", 32, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.sse");
-  field_type = tdesc_named_type (feature, "ieee_single");
-  tdesc_create_vector (feature, "v4f", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "ieee_double");
-  tdesc_create_vector (feature, "v2d", field_type, 2);
-
-  field_type = tdesc_named_type (feature, "int8");
-  tdesc_create_vector (feature, "v16i8", field_type, 16);
-
-  field_type = tdesc_named_type (feature, "int16");
-  tdesc_create_vector (feature, "v8i16", field_type, 8);
-
-  field_type = tdesc_named_type (feature, "int32");
-  tdesc_create_vector (feature, "v4i32", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "int64");
-  tdesc_create_vector (feature, "v2i64", field_type, 2);
-
-  type = tdesc_create_union (feature, "vec128");
-  field_type = tdesc_named_type (feature, "v4f");
-  tdesc_add_field (type, "v4_float", field_type);
-  field_type = tdesc_named_type (feature, "v2d");
-  tdesc_add_field (type, "v2_double", field_type);
-  field_type = tdesc_named_type (feature, "v16i8");
-  tdesc_add_field (type, "v16_int8", field_type);
-  field_type = tdesc_named_type (feature, "v8i16");
-  tdesc_add_field (type, "v8_int16", field_type);
-  field_type = tdesc_named_type (feature, "v4i32");
-  tdesc_add_field (type, "v4_int32", field_type);
-  field_type = tdesc_named_type (feature, "v2i64");
-  tdesc_add_field (type, "v2_int64", field_type);
-  field_type = tdesc_named_type (feature, "uint128");
-  tdesc_add_field (type, "uint128", field_type);
-
-  type = tdesc_create_flags (feature, "i386_mxcsr", 4);
-  tdesc_add_flag (type, 0, "IE");
-  tdesc_add_flag (type, 1, "DE");
-  tdesc_add_flag (type, 2, "ZE");
-  tdesc_add_flag (type, 3, "OE");
-  tdesc_add_flag (type, 4, "UE");
-  tdesc_add_flag (type, 5, "PE");
-  tdesc_add_flag (type, 6, "DAZ");
-  tdesc_add_flag (type, 7, "IM");
-  tdesc_add_flag (type, 8, "DM");
-  tdesc_add_flag (type, 9, "ZM");
-  tdesc_add_flag (type, 10, "OM");
-  tdesc_add_flag (type, 11, "UM");
-  tdesc_add_flag (type, 12, "PM");
-  tdesc_add_flag (type, 15, "FZ");
-
-  tdesc_create_reg (feature, "xmm0", 40, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm1", 41, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm2", 42, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm3", 43, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm4", 44, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm5", 45, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm6", 46, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm7", 47, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm8", 48, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm9", 49, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm10", 50, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm11", 51, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm12", 52, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm13", 53, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm14", 54, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm15", 55, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "mxcsr", 56, 1, "vector", 32, "i386_mxcsr");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
-  tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
-  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
-  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx");
-  tdesc_create_reg (feature, "ymm0h", 60, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm1h", 61, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm2h", 62, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm3h", 63, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm4h", 64, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm5h", 65, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm6h", 66, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm7h", 67, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm8h", 68, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm9h", 69, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm10h", 70, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm11h", 71, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm12h", 72, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm13h", 73, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm14h", 74, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm15h", 75, 1, NULL, 128, "uint128");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx512");
-  field_type = tdesc_named_type (feature, "ieee_single");
-  tdesc_create_vector (feature, "v4f", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "ieee_double");
-  tdesc_create_vector (feature, "v2d", field_type, 2);
-
-  field_type = tdesc_named_type (feature, "int8");
-  tdesc_create_vector (feature, "v16i8", field_type, 16);
-
-  field_type = tdesc_named_type (feature, "int16");
-  tdesc_create_vector (feature, "v8i16", field_type, 8);
-
-  field_type = tdesc_named_type (feature, "int32");
-  tdesc_create_vector (feature, "v4i32", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "int64");
-  tdesc_create_vector (feature, "v2i64", field_type, 2);
-
-  type = tdesc_create_union (feature, "vec128");
-  field_type = tdesc_named_type (feature, "v4f");
-  tdesc_add_field (type, "v4_float", field_type);
-  field_type = tdesc_named_type (feature, "v2d");
-  tdesc_add_field (type, "v2_double", field_type);
-  field_type = tdesc_named_type (feature, "v16i8");
-  tdesc_add_field (type, "v16_int8", field_type);
-  field_type = tdesc_named_type (feature, "v8i16");
-  tdesc_add_field (type, "v8_int16", field_type);
-  field_type = tdesc_named_type (feature, "v4i32");
-  tdesc_add_field (type, "v4_int32", field_type);
-  field_type = tdesc_named_type (feature, "v2i64");
-  tdesc_add_field (type, "v2_int64", field_type);
-  field_type = tdesc_named_type (feature, "uint128");
-  tdesc_add_field (type, "uint128", field_type);
-
-  field_type = tdesc_named_type (feature, "uint128");
-  tdesc_create_vector (feature, "v2ui128", field_type, 2);
-
-  tdesc_create_reg (feature, "xmm16", 76, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm17", 77, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm18", 78, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm19", 79, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm20", 80, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm21", 81, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm22", 82, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm23", 83, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm24", 84, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm25", 85, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm26", 86, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm27", 87, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm28", 88, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm29", 89, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm30", 90, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm31", 91, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "ymm16h", 92, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm17h", 93, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm18h", 94, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm19h", 95, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm20h", 96, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm21h", 97, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm22h", 98, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm23h", 99, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm24h", 100, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm25h", 101, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm26h", 102, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm27h", 103, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm28h", 104, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm29h", 105, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm30h", 106, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm31h", 107, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "k0", 108, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k1", 109, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k2", 110, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k3", 111, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k4", 112, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k5", 113, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k6", 114, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k7", 115, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "zmm0h", 116, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm1h", 117, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm2h", 118, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm3h", 119, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm4h", 120, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm5h", 121, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm6h", 122, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm7h", 123, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm8h", 124, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm9h", 125, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm10h", 126, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm11h", 127, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm12h", 128, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm13h", 129, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm14h", 130, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm15h", 131, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm16h", 132, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm17h", 133, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm18h", 134, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm19h", 135, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm20h", 136, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm21h", 137, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm22h", 138, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm23h", 139, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm24h", 140, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm25h", 141, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm26h", 142, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm27h", 143, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm28h", 144, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm29h", 145, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm30h", 146, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm31h", 147, 1, NULL, 256, "v2ui128");
-
-  tdesc_x32_avx_avx512_linux = result;
-}
diff --git a/gdb/features/i386/x32-avx-linux.c b/gdb/features/i386/x32-avx-linux.c
deleted file mode 100644
index 8406815..0000000
--- a/gdb/features/i386/x32-avx-linux.c
+++ /dev/null
@@ -1,177 +0,0 @@
-/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
-  Original: x32-avx-linux.xml */
-
-#include "defs.h"
-#include "osabi.h"
-#include "target-descriptions.h"
-
-struct target_desc *tdesc_x32_avx_linux;
-static void
-initialize_tdesc_x32_avx_linux (void)
-{
-  struct target_desc *result = allocate_target_description ();
-  struct tdesc_feature *feature;
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-
-  set_tdesc_architecture (result, bfd_scan_arch ("i386:x64-32"));
-
-  set_tdesc_osabi (result, osabi_from_tdesc_string ("GNU/Linux"));
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
-  type = tdesc_create_flags (feature, "i386_eflags", 4);
-  tdesc_add_flag (type, 0, "CF");
-  tdesc_add_flag (type, 1, "");
-  tdesc_add_flag (type, 2, "PF");
-  tdesc_add_flag (type, 4, "AF");
-  tdesc_add_flag (type, 6, "ZF");
-  tdesc_add_flag (type, 7, "SF");
-  tdesc_add_flag (type, 8, "TF");
-  tdesc_add_flag (type, 9, "IF");
-  tdesc_add_flag (type, 10, "DF");
-  tdesc_add_flag (type, 11, "OF");
-  tdesc_add_flag (type, 14, "NT");
-  tdesc_add_flag (type, 16, "RF");
-  tdesc_add_flag (type, 17, "VM");
-  tdesc_add_flag (type, 18, "AC");
-  tdesc_add_flag (type, 19, "VIF");
-  tdesc_add_flag (type, 20, "VIP");
-  tdesc_add_flag (type, 21, "ID");
-
-  tdesc_create_reg (feature, "rax", 0, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rbx", 1, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rcx", 2, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rdx", 3, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rsi", 4, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rdi", 5, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rbp", 6, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rsp", 7, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r8", 8, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r9", 9, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r10", 10, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r11", 11, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r12", 12, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r13", 13, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r14", 14, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r15", 15, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rip", 16, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "eflags", 17, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 18, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 19, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 20, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 21, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 22, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 23, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "st0", 24, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st1", 25, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st2", 26, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st3", 27, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st4", 28, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st5", 29, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st6", 30, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st7", 31, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "fctrl", 32, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fstat", 33, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "ftag", 34, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fiseg", 35, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fioff", 36, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "foseg", 37, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fooff", 38, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fop", 39, 1, "float", 32, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.sse");
-  field_type = tdesc_named_type (feature, "ieee_single");
-  tdesc_create_vector (feature, "v4f", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "ieee_double");
-  tdesc_create_vector (feature, "v2d", field_type, 2);
-
-  field_type = tdesc_named_type (feature, "int8");
-  tdesc_create_vector (feature, "v16i8", field_type, 16);
-
-  field_type = tdesc_named_type (feature, "int16");
-  tdesc_create_vector (feature, "v8i16", field_type, 8);
-
-  field_type = tdesc_named_type (feature, "int32");
-  tdesc_create_vector (feature, "v4i32", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "int64");
-  tdesc_create_vector (feature, "v2i64", field_type, 2);
-
-  type = tdesc_create_union (feature, "vec128");
-  field_type = tdesc_named_type (feature, "v4f");
-  tdesc_add_field (type, "v4_float", field_type);
-  field_type = tdesc_named_type (feature, "v2d");
-  tdesc_add_field (type, "v2_double", field_type);
-  field_type = tdesc_named_type (feature, "v16i8");
-  tdesc_add_field (type, "v16_int8", field_type);
-  field_type = tdesc_named_type (feature, "v8i16");
-  tdesc_add_field (type, "v8_int16", field_type);
-  field_type = tdesc_named_type (feature, "v4i32");
-  tdesc_add_field (type, "v4_int32", field_type);
-  field_type = tdesc_named_type (feature, "v2i64");
-  tdesc_add_field (type, "v2_int64", field_type);
-  field_type = tdesc_named_type (feature, "uint128");
-  tdesc_add_field (type, "uint128", field_type);
-
-  type = tdesc_create_flags (feature, "i386_mxcsr", 4);
-  tdesc_add_flag (type, 0, "IE");
-  tdesc_add_flag (type, 1, "DE");
-  tdesc_add_flag (type, 2, "ZE");
-  tdesc_add_flag (type, 3, "OE");
-  tdesc_add_flag (type, 4, "UE");
-  tdesc_add_flag (type, 5, "PE");
-  tdesc_add_flag (type, 6, "DAZ");
-  tdesc_add_flag (type, 7, "IM");
-  tdesc_add_flag (type, 8, "DM");
-  tdesc_add_flag (type, 9, "ZM");
-  tdesc_add_flag (type, 10, "OM");
-  tdesc_add_flag (type, 11, "UM");
-  tdesc_add_flag (type, 12, "PM");
-  tdesc_add_flag (type, 15, "FZ");
-
-  tdesc_create_reg (feature, "xmm0", 40, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm1", 41, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm2", 42, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm3", 43, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm4", 44, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm5", 45, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm6", 46, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm7", 47, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm8", 48, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm9", 49, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm10", 50, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm11", 51, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm12", 52, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm13", 53, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm14", 54, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm15", 55, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "mxcsr", 56, 1, "vector", 32, "i386_mxcsr");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
-  tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
-  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
-  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx");
-  tdesc_create_reg (feature, "ymm0h", 60, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm1h", 61, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm2h", 62, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm3h", 63, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm4h", 64, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm5h", 65, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm6h", 66, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm7h", 67, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm8h", 68, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm9h", 69, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm10h", 70, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm11h", 71, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm12h", 72, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm13h", 73, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm14h", 74, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm15h", 75, 1, NULL, 128, "uint128");
-
-  tdesc_x32_avx_linux = result;
-}
diff --git a/gdb/features/i386/x32-linux.c b/gdb/features/i386/x32-linux.c
deleted file mode 100644
index ae49549..0000000
--- a/gdb/features/i386/x32-linux.c
+++ /dev/null
@@ -1,159 +0,0 @@
-/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
-  Original: x32-linux.xml */
-
-#include "defs.h"
-#include "osabi.h"
-#include "target-descriptions.h"
-
-struct target_desc *tdesc_x32_linux;
-static void
-initialize_tdesc_x32_linux (void)
-{
-  struct target_desc *result = allocate_target_description ();
-  struct tdesc_feature *feature;
-  struct tdesc_type *field_type;
-  struct tdesc_type *type;
-
-  set_tdesc_architecture (result, bfd_scan_arch ("i386:x64-32"));
-
-  set_tdesc_osabi (result, osabi_from_tdesc_string ("GNU/Linux"));
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
-  type = tdesc_create_flags (feature, "i386_eflags", 4);
-  tdesc_add_flag (type, 0, "CF");
-  tdesc_add_flag (type, 1, "");
-  tdesc_add_flag (type, 2, "PF");
-  tdesc_add_flag (type, 4, "AF");
-  tdesc_add_flag (type, 6, "ZF");
-  tdesc_add_flag (type, 7, "SF");
-  tdesc_add_flag (type, 8, "TF");
-  tdesc_add_flag (type, 9, "IF");
-  tdesc_add_flag (type, 10, "DF");
-  tdesc_add_flag (type, 11, "OF");
-  tdesc_add_flag (type, 14, "NT");
-  tdesc_add_flag (type, 16, "RF");
-  tdesc_add_flag (type, 17, "VM");
-  tdesc_add_flag (type, 18, "AC");
-  tdesc_add_flag (type, 19, "VIF");
-  tdesc_add_flag (type, 20, "VIP");
-  tdesc_add_flag (type, 21, "ID");
-
-  tdesc_create_reg (feature, "rax", 0, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rbx", 1, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rcx", 2, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rdx", 3, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rsi", 4, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rdi", 5, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rbp", 6, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rsp", 7, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r8", 8, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r9", 9, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r10", 10, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r11", 11, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r12", 12, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r13", 13, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r14", 14, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "r15", 15, 1, NULL, 64, "int64");
-  tdesc_create_reg (feature, "rip", 16, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "eflags", 17, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 18, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 19, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 20, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 21, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 22, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 23, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "st0", 24, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st1", 25, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st2", 26, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st3", 27, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st4", 28, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st5", 29, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st6", 30, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "st7", 31, 1, NULL, 80, "i387_ext");
-  tdesc_create_reg (feature, "fctrl", 32, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fstat", 33, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "ftag", 34, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fiseg", 35, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fioff", 36, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "foseg", 37, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fooff", 38, 1, "float", 32, "int");
-  tdesc_create_reg (feature, "fop", 39, 1, "float", 32, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.sse");
-  field_type = tdesc_named_type (feature, "ieee_single");
-  tdesc_create_vector (feature, "v4f", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "ieee_double");
-  tdesc_create_vector (feature, "v2d", field_type, 2);
-
-  field_type = tdesc_named_type (feature, "int8");
-  tdesc_create_vector (feature, "v16i8", field_type, 16);
-
-  field_type = tdesc_named_type (feature, "int16");
-  tdesc_create_vector (feature, "v8i16", field_type, 8);
-
-  field_type = tdesc_named_type (feature, "int32");
-  tdesc_create_vector (feature, "v4i32", field_type, 4);
-
-  field_type = tdesc_named_type (feature, "int64");
-  tdesc_create_vector (feature, "v2i64", field_type, 2);
-
-  type = tdesc_create_union (feature, "vec128");
-  field_type = tdesc_named_type (feature, "v4f");
-  tdesc_add_field (type, "v4_float", field_type);
-  field_type = tdesc_named_type (feature, "v2d");
-  tdesc_add_field (type, "v2_double", field_type);
-  field_type = tdesc_named_type (feature, "v16i8");
-  tdesc_add_field (type, "v16_int8", field_type);
-  field_type = tdesc_named_type (feature, "v8i16");
-  tdesc_add_field (type, "v8_int16", field_type);
-  field_type = tdesc_named_type (feature, "v4i32");
-  tdesc_add_field (type, "v4_int32", field_type);
-  field_type = tdesc_named_type (feature, "v2i64");
-  tdesc_add_field (type, "v2_int64", field_type);
-  field_type = tdesc_named_type (feature, "uint128");
-  tdesc_add_field (type, "uint128", field_type);
-
-  type = tdesc_create_flags (feature, "i386_mxcsr", 4);
-  tdesc_add_flag (type, 0, "IE");
-  tdesc_add_flag (type, 1, "DE");
-  tdesc_add_flag (type, 2, "ZE");
-  tdesc_add_flag (type, 3, "OE");
-  tdesc_add_flag (type, 4, "UE");
-  tdesc_add_flag (type, 5, "PE");
-  tdesc_add_flag (type, 6, "DAZ");
-  tdesc_add_flag (type, 7, "IM");
-  tdesc_add_flag (type, 8, "DM");
-  tdesc_add_flag (type, 9, "ZM");
-  tdesc_add_flag (type, 10, "OM");
-  tdesc_add_flag (type, 11, "UM");
-  tdesc_add_flag (type, 12, "PM");
-  tdesc_add_flag (type, 15, "FZ");
-
-  tdesc_create_reg (feature, "xmm0", 40, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm1", 41, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm2", 42, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm3", 43, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm4", 44, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm5", 45, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm6", 46, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm7", 47, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm8", 48, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm9", 49, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm10", 50, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm11", 51, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm12", 52, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm13", 53, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm14", 54, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm15", 55, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "mxcsr", 56, 1, "vector", 32, "i386_mxcsr");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
-  tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
-
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
-  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
-  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
-
-  tdesc_x32_linux = result;
-}
-- 
1.9.1

^ permalink raw reply	[flat|nested] 82+ messages in thread

* [PATCH 24/25] [GDBserver] Use pre-generated amd64-linux tdesc as test
  2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
                   ` (22 preceding siblings ...)
  2017-06-12  8:42 ` [PATCH 13/25] Dynamically create tdesc in GDBserver Yao Qi
@ 2017-06-12  8:42 ` Yao Qi
  2017-06-12  8:42 ` [PATCH 16/25] Dynamically composite xml in reply to GDB Yao Qi
                   ` (2 subsequent siblings)
  26 siblings, 0 replies; 82+ messages in thread
From: Yao Qi @ 2017-06-12  8:42 UTC (permalink / raw)
  To: gdb-patches

Now, all these amd64-linux pre-generated tdesc can be used as test, so
don't need to build them if $development is false.

Note that this patch wants to remove ipa_x32_linux_regobj, but it was
removed by mistake by 22049425ce40324139be82d9a6ec518c46b65815.

gdb/gdbserver:

2017-06-09  Yao Qi  <yao.qi@linaro.org>

	* configure.srv: Empty srv_amd64_linux_regobj if $development is
	false.
	(ipa_amd64_linux_regobj): Remove.
---
 gdb/gdbserver/configure.srv | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv
index 5c3ba1f..2b4897b 100644
--- a/gdb/gdbserver/configure.srv
+++ b/gdb/gdbserver/configure.srv
@@ -28,14 +28,14 @@ srv_i386_regobj="i386.o i386-avx.o i386-avx-avx512.o i386-avx-mpx-avx512-pku.o i
 
 if $development; then
    srv_i386_linux_regobj="i386-linux.o i386-avx-linux.o i386-avx-avx512-linux.o i386-avx-mpx-avx512-pku-linux.o i386-mpx-linux.o i386-avx-mpx-linux.o i386-mmx-linux.o linux-x86-tdesc-selftest.o"
+   srv_amd64_linux_regobj="amd64-linux.o amd64-avx-linux.o amd64-avx-avx512-linux.o amd64-avx-mpx-avx512-pku-linux.o amd64-mpx-linux.o amd64-avx-mpx-linux.o x32-linux.o x32-avx-linux.o x32-avx-avx512-linux.o"
 else
    srv_i386_linux_regobj=""
+   srv_amd64_linux_regobj=""
 fi
 
 srv_amd64_regobj="amd64.o amd64-avx.o amd64-avx-avx512.o amd64-avx-mpx-avx512-pku.o amd64-mpx.o amd64-avx-mpx.o x32.o x32-avx.o x32-avx-avx512.o"
-srv_amd64_linux_regobj="amd64-linux.o amd64-avx-linux.o amd64-avx-avx512-linux.o amd64-avx-mpx-avx512-pku-linux.o amd64-mpx-linux.o amd64-avx-mpx-linux.o x32-linux.o x32-avx-linux.o x32-avx-avx512-linux.o"
 
-ipa_amd64_linux_regobj="amd64-linux-ipa.o amd64-avx-linux-ipa.o amd64-avx-mpx-linux-ipa.o amd64-avx-avx512-linux-ipa.o amd64-avx-mpx-avx512-pku-linux-ipa.o amd64-mpx-linux-ipa.o"
 ipa_ppc_linux_regobj="powerpc-32l-ipa.o powerpc-altivec32l-ipa.o powerpc-cell32l-ipa.o powerpc-vsx32l-ipa.o powerpc-isa205-32l-ipa.o powerpc-isa205-altivec32l-ipa.o powerpc-isa205-vsx32l-ipa.o powerpc-e500l-ipa.o powerpc-64l-ipa.o powerpc-altivec64l-ipa.o powerpc-cell64l-ipa.o powerpc-vsx64l-ipa.o powerpc-isa205-64l-ipa.o powerpc-isa205-altivec64l-ipa.o powerpc-isa205-vsx64l-ipa.o"
 
 srv_i386_32bit_xmlfiles="i386/32bit-core.xml i386/32bit-sse.xml i386/32bit-avx.xml i386/32bit-avx512.xml i386/32bit-mpx.xml i386/32bit-pkeys.xml"
@@ -370,12 +370,7 @@ case "${target}" in
 			srv_linux_regsets=yes
 			srv_linux_thread_db=yes
 			srv_linux_btrace=yes
-			if test "$gdb_cv_x86_is_x32" = yes ; then
-			    ipa_obj="${ipa_x32_linux_regobj}"
-			else
-			    ipa_obj="${ipa_amd64_linux_regobj}"
-			fi
-			ipa_obj="${ipa_obj} linux-amd64-ipa.o linux-x86-tdesc-ipa.o"
+			ipa_obj="linux-amd64-ipa.o linux-x86-tdesc-ipa.o"
 			;;
   x86_64-*-mingw*)	srv_regobj="$srv_amd64_regobj"
 			srv_tgtobj="x86-low.o x86-dregs.o i387-fp.o win32-low.o win32-i386-low.o"
-- 
1.9.1

^ permalink raw reply	[flat|nested] 82+ messages in thread

* [PATCH 16/25] Dynamically composite xml in reply to GDB
  2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
                   ` (23 preceding siblings ...)
  2017-06-12  8:42 ` [PATCH 24/25] [GDBserver] Use pre-generated amd64-linux tdesc as test Yao Qi
@ 2017-06-12  8:42 ` Yao Qi
  2017-06-19 19:59 ` [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Simon Marchi
  2017-06-28 19:06 ` Pedro Alves
  26 siblings, 0 replies; 82+ messages in thread
From: Yao Qi @ 2017-06-12  8:42 UTC (permalink / raw)
  To: gdb-patches

GDBserver still uses pre-generated target descriptions in order to
reply to GDB's query on target description (see xml-builtin-generated.c
in GDBserver build directory).  This patch teaches GDBserver to
create XML contents according to the target descriptions rather than
using pre-generated ones.

First, change target feature c files to pass the feature xml file
name to tdesc_create_feature, so that target description in GDBserver
can record them, and create XML contents from these features in
buffer, like

  ...
  <xi:include href="$FEATURE1_XML_NAME"/>
  <xi:include href="$FEATURE2_XML_NAME"/>
  ...

and send this buffer back to GDB.

gdb/gdbserver:

2017-05-24  Yao Qi  <yao.qi@linaro.org>

	* linux-x86-tdesc.c (i386_get_ipa_tdesc): Call
	set_tdesc_architecture and set_tdesc_osabi.  Don't set
	xmltarget field.
	* server.c (get_features_xml): Call tdesc_get_features_xml.
	* tdesc.c (set_tdesc_architecture): New function.
	(set_tdesc_osabi): New function.
	(tdesc_get_features_xml): New function.
	(tdesc_create_feature): Add one argument.
	* tdesc.h (struct target_desc) <features>: New field.
	<arch>: New field.
	<osabi>: New field.
	(target_desc::~target_desc): xfree arch, osabi, and
	features.
	(set_tdesc_architecture): Declare.
	(set_tdesc_osabi): Declare.
	(tdesc_get_features_xml): Declare.
	* target-descriptions.c (tdesc_create_feature): Add one
	argument.
	* target-descriptions.h (tdesc_create_feature): Update
	the declaration.
---
 gdb/features/i386/32bit-avx.c    |  2 +-
 gdb/features/i386/32bit-avx512.c |  2 +-
 gdb/features/i386/32bit-core.c   |  2 +-
 gdb/features/i386/32bit-linux.c  |  2 +-
 gdb/features/i386/32bit-mpx.c    |  2 +-
 gdb/features/i386/32bit-pkeys.c  |  2 +-
 gdb/features/i386/32bit-sse.c    |  2 +-
 gdb/gdbserver/linux-x86-tdesc.c  | 35 +++++-------------------
 gdb/gdbserver/server.c           | 10 ++++---
 gdb/gdbserver/tdesc.c            | 58 +++++++++++++++++++++++++++++++++++++++-
 gdb/gdbserver/tdesc.h            | 26 +++++++++++++++---
 gdb/target-descriptions.c        |  9 ++++---
 gdb/target-descriptions.h        |  3 ++-
 13 files changed, 106 insertions(+), 49 deletions(-)

diff --git a/gdb/features/i386/32bit-avx.c b/gdb/features/i386/32bit-avx.c
index bae025d..2146e00 100644
--- a/gdb/features/i386/32bit-avx.c
+++ b/gdb/features/i386/32bit-avx.c
@@ -14,7 +14,7 @@ create_feature_i386_32bit_avx (struct target_desc *result, long regnum)
 {
   struct tdesc_feature *feature;
 
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx");
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx", "32bit-avx.xml");
   tdesc_create_reg (feature, "ymm0h", regnum++, 1, NULL, 128, "uint128");
   tdesc_create_reg (feature, "ymm1h", regnum++, 1, NULL, 128, "uint128");
   tdesc_create_reg (feature, "ymm2h", regnum++, 1, NULL, 128, "uint128");
diff --git a/gdb/features/i386/32bit-avx512.c b/gdb/features/i386/32bit-avx512.c
index ca15f8b..d36b4b0 100644
--- a/gdb/features/i386/32bit-avx512.c
+++ b/gdb/features/i386/32bit-avx512.c
@@ -14,7 +14,7 @@ create_feature_i386_32bit_avx512 (struct target_desc *result, long regnum)
 {
   struct tdesc_feature *feature;
 
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx512");
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx512", "32bit-avx512.xml");
   struct tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "uint128");
   tdesc_create_vector (feature, "v2ui128", field_type, 2);
diff --git a/gdb/features/i386/32bit-core.c b/gdb/features/i386/32bit-core.c
index 8db91ab..72694b8 100644
--- a/gdb/features/i386/32bit-core.c
+++ b/gdb/features/i386/32bit-core.c
@@ -14,7 +14,7 @@ create_feature_i386_32bit_core (struct target_desc *result, long regnum)
 {
   struct tdesc_feature *feature;
 
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core");
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core", "32bit-core.xml");
   struct tdesc_type *field_type;
   struct tdesc_type *type;
   type = tdesc_create_flags (feature, "i386_eflags", 4);
diff --git a/gdb/features/i386/32bit-linux.c b/gdb/features/i386/32bit-linux.c
index 7535c55..9ba9ae1 100644
--- a/gdb/features/i386/32bit-linux.c
+++ b/gdb/features/i386/32bit-linux.c
@@ -14,7 +14,7 @@ create_feature_i386_32bit_linux (struct target_desc *result, long regnum)
 {
   struct tdesc_feature *feature;
 
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux", "32bit-linux.xml");
   regnum = 41;
   tdesc_create_reg (feature, "orig_eax", regnum++, 1, NULL, 32, "int");
   return regnum;
diff --git a/gdb/features/i386/32bit-mpx.c b/gdb/features/i386/32bit-mpx.c
index 9f1ae67..19fbae5 100644
--- a/gdb/features/i386/32bit-mpx.c
+++ b/gdb/features/i386/32bit-mpx.c
@@ -14,7 +14,7 @@ create_feature_i386_32bit_mpx (struct target_desc *result, long regnum)
 {
   struct tdesc_feature *feature;
 
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.mpx");
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.mpx", "32bit-mpx.xml");
   struct tdesc_type *field_type;
   struct tdesc_type *type;
   type = tdesc_create_struct (feature, "br128");
diff --git a/gdb/features/i386/32bit-pkeys.c b/gdb/features/i386/32bit-pkeys.c
index 86035ab..ee8208a 100644
--- a/gdb/features/i386/32bit-pkeys.c
+++ b/gdb/features/i386/32bit-pkeys.c
@@ -14,7 +14,7 @@ create_feature_i386_32bit_pkeys (struct target_desc *result, long regnum)
 {
   struct tdesc_feature *feature;
 
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.pkeys");
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.pkeys", "32bit-pkeys.xml");
   tdesc_create_reg (feature, "pkru", regnum++, 1, NULL, 32, "uint32");
   return regnum;
 }
diff --git a/gdb/features/i386/32bit-sse.c b/gdb/features/i386/32bit-sse.c
index 876c04d..d57cf49 100644
--- a/gdb/features/i386/32bit-sse.c
+++ b/gdb/features/i386/32bit-sse.c
@@ -14,7 +14,7 @@ create_feature_i386_32bit_sse (struct target_desc *result, long regnum)
 {
   struct tdesc_feature *feature;
 
-  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.sse");
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.sse", "32bit-sse.xml");
   struct tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "ieee_single");
   tdesc_create_vector (feature, "v4f", field_type, 4);
diff --git a/gdb/gdbserver/linux-x86-tdesc.c b/gdb/gdbserver/linux-x86-tdesc.c
index 06e5bf9..0dc5275 100644
--- a/gdb/gdbserver/linux-x86-tdesc.c
+++ b/gdb/gdbserver/linux-x86-tdesc.c
@@ -132,6 +132,12 @@ i386_get_ipa_tdesc (int idx)
   if (*tdesc == NULL)
     {
       *tdesc = new target_desc ();
+
+#ifndef IN_PROCESS_AGENT
+      set_tdesc_architecture (*tdesc, "i386");
+      set_tdesc_osabi (*tdesc, "GNU/Linux");
+#endif
+
       long regnum = 0;
 
       regnum = create_feature_i386_32bit_core (*tdesc, regnum);
@@ -162,35 +168,6 @@ i386_get_ipa_tdesc (int idx)
 #ifndef IN_PROCESS_AGENT
       static const char *expedite_regs_i386[] = { "ebp", "esp", "eip", NULL };
       (*tdesc)->expedite_regs = expedite_regs_i386;
-
-      switch (idx)
-	{
-	case X86_TDESC_MMX:
-	  (*tdesc)->xmltarget = "i386-mmx-linux.xml";
-	  break;
-	case X86_TDESC_SSE:
-	  (*tdesc)->xmltarget = "i386-linux.xml";
-	  break;
-	case X86_TDESC_AVX:
-	  (*tdesc)->xmltarget = "i386-avx-linux.xml";
-	  break;
-	case X86_TDESC_MPX:
-	  (*tdesc)->xmltarget = "i386-mpx-linux.xml";
-	  break;
-	case X86_TDESC_AVX_MPX:
-	  (*tdesc)->xmltarget = "i386-avx-mpx-linux.xml";
-	  break;
-	case X86_TDESC_AVX_AVX512:
-	  (*tdesc)->xmltarget = "i386-avx-avx512-linux.xml";
-	  break;
-	case X86_TDESC_AVX_MPX_AVX512_PKU:
-	  (*tdesc)->xmltarget = "i386-avx-mpx-avx512-pku-linux.xml";
-	  break;
-	default:
-	  internal_error (__FILE__, __LINE__,
-			  "unknown ipa tdesc index: %d", idx);
-	}
-
 #endif
     }
   return *tdesc;;
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index 428a9db..b862d48 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -850,12 +850,14 @@ get_features_xml (const char *annex)
      This variable is set up from the auto-generated
      init_registers_... routine for the current target.  */
 
-  if (desc->xmltarget != NULL && strcmp (annex, "target.xml") == 0)
+  if (strcmp (annex, "target.xml") == 0)
     {
-      if (*desc->xmltarget == '@')
-	return desc->xmltarget + 1;
+      const char *ret = tdesc_get_features_xml ((target_desc*) desc);
+
+      if (*ret == '@')
+	return ret + 1;
       else
-	annex = desc->xmltarget;
+	annex = ret;
     }
 
 #ifdef USE_XML
diff --git a/gdb/gdbserver/tdesc.c b/gdb/gdbserver/tdesc.c
index 686c76a..6b4c4b7 100644
--- a/gdb/gdbserver/tdesc.c
+++ b/gdb/gdbserver/tdesc.c
@@ -61,14 +61,70 @@ current_target_desc (void)
 
   return current_process ()->tdesc;
 }
+void
+set_tdesc_architecture (struct target_desc *target_desc,
+			const char *name)
+{
+  target_desc->arch = xstrdup (name);
+}
+
+void
+set_tdesc_osabi (struct target_desc *target_desc, const char *name)
+{
+  target_desc->osabi = xstrdup (name);
+}
+
+const char *
+tdesc_get_features_xml (target_desc *tdesc)
+{
+  /* Either .xmltarget or .features is not NULL.  */
+  gdb_assert (tdesc->xmltarget != NULL
+	      || (tdesc->features != NULL
+		  && tdesc->arch != NULL
+		  && tdesc->osabi != NULL));
+
+  if (tdesc->xmltarget == NULL)
+    {
+      std::string buffer ("@<?xml version=\"1.0\"?>");
+
+      buffer += "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">";
+      buffer += "<target>";
+      buffer += "<architecture>";
+      buffer += tdesc->arch;
+      buffer += "</architecture>";
+
+      buffer += "<osabi>";
+      buffer += tdesc->osabi;
+      buffer += "</osabi>";
+
+      char *xml;
+
+      for (int i = 0; VEC_iterate (char_ptr, tdesc->features, i, xml); i++)
+	{
+	  buffer += "<xi:include href=\"";
+	  buffer += xml;
+	  buffer += "\"/>";
+	}
+
+      buffer += "</target>";
+
+      tdesc->xmltarget = xstrdup (buffer.c_str ());
+    }
+
+  return tdesc->xmltarget;
+}
 #endif
 
 struct tdesc_type
 {};
 
 struct tdesc_feature *
-tdesc_create_feature (struct target_desc *tdesc, const char *name)
+tdesc_create_feature (struct target_desc *tdesc, const char *name,
+		      const char *xml)
 {
+#ifndef IN_PROCESS_AGENT
+  VEC_safe_push (char_ptr, tdesc->features, xstrdup (xml));
+#endif
   return tdesc;
 }
 
diff --git a/gdb/gdbserver/tdesc.h b/gdb/gdbserver/tdesc.h
index e64f0b3..c3ab30d 100644
--- a/gdb/gdbserver/tdesc.h
+++ b/gdb/gdbserver/tdesc.h
@@ -47,6 +47,12 @@ struct target_desc
      actual XML file to be used in place of "target.xml".  */
   const char *xmltarget = NULL;
 
+  VEC (char_ptr) *features = NULL;
+
+  const char *arch = NULL;
+
+  const char *osabi = NULL;
+
 public:
   target_desc ()
     : reg_defs (NULL), registers_size (0)
@@ -60,6 +66,15 @@ public:
     for (i = 0; VEC_iterate (tdesc_reg_p, reg_defs, i, reg); i++)
       xfree (reg);
     VEC_free (tdesc_reg_p, reg_defs);
+
+    xfree ((char *) arch);
+    xfree ((char *) osabi);
+
+    char *f;
+
+    for (i = 0; VEC_iterate (char_ptr, features, i, f); i++)
+      xfree (f);
+    VEC_free (char_ptr, features);
   }
   bool operator!= (const target_desc &other) const
   {
@@ -90,9 +105,6 @@ public:
     if (other.expedite_regs[i] != NULL)
       return true;
 
-    if (strcmp (xmltarget, other.xmltarget) != 0)
-      return true;
-
     return false;
   }
 
@@ -118,6 +130,11 @@ void init_target_desc (struct target_desc *tdesc);
 const struct target_desc *current_target_desc (void);
 
 #ifndef IN_PROCESS_AGENT
+void set_tdesc_architecture (struct target_desc *target_desc,
+			     const char *name);
+void set_tdesc_osabi (struct target_desc *target_desc, const char *name);
+
+const char *tdesc_get_features_xml (struct target_desc *tdesc);
 #endif
 
 #define tdesc_feature target_desc
@@ -125,7 +142,8 @@ const struct target_desc *current_target_desc (void);
 struct tdesc_type;
 
 struct tdesc_feature *tdesc_create_feature (struct target_desc *tdesc,
-					    const char *name);
+					    const char *name,
+					    const char *xml = NULL);
 
 struct tdesc_type *tdesc_create_flags (struct tdesc_feature *feature,
 				       const char *name, int size);
diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
index 38e28d3..a12fd7e 100644
--- a/gdb/target-descriptions.c
+++ b/gdb/target-descriptions.c
@@ -1746,7 +1746,8 @@ tdesc_add_enum_value (struct tdesc_type *type, int value,
 }
 
 struct tdesc_feature *
-tdesc_create_feature (struct target_desc *tdesc, const char *name)
+tdesc_create_feature (struct target_desc *tdesc, const char *name,
+		      const char *xml)
 {
   struct tdesc_feature *new_feature = new tdesc_feature (name);
 
@@ -2195,8 +2196,10 @@ public:
 
     printf_unfiltered ("{\n");
     printf_unfiltered ("  struct tdesc_feature *feature;\n");
-    printf_unfiltered ("\n  feature = tdesc_create_feature (result, \"%s\");\n",
-		       e->name);
+
+    printf_unfiltered
+      ("\n  feature = tdesc_create_feature (result, \"%s\", \"%s\");\n",
+       e->name, lbasename (m_filename_after_features.c_str ()));
   }
 
   void visit_end (const tdesc_feature *e) override
diff --git a/gdb/target-descriptions.h b/gdb/target-descriptions.h
index d730672..25afaf0 100644
--- a/gdb/target-descriptions.h
+++ b/gdb/target-descriptions.h
@@ -222,7 +222,8 @@ void tdesc_add_compatible (struct target_desc *,
 			   const struct bfd_arch_info *);
 
 struct tdesc_feature *tdesc_create_feature (struct target_desc *tdesc,
-					    const char *name);
+					    const char *name,
+					    const char *xml = NULL);
 struct tdesc_type *tdesc_create_vector (struct tdesc_feature *feature,
 					const char *name,
 					struct tdesc_type *field_type,
-- 
1.9.1

^ permalink raw reply	[flat|nested] 82+ messages in thread

* [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible
@ 2017-06-12  8:42 Yao Qi
  2017-06-12  8:42 ` [PATCH 04/25] Centralize i386 linux target descriptions Yao Qi
                   ` (26 more replies)
  0 siblings, 27 replies; 82+ messages in thread
From: Yao Qi @ 2017-06-12  8:42 UTC (permalink / raw)
  To: gdb-patches

This patch series is to change GDB and GDBserver builtin target
descriptions more flexible, by removing pre-generated ones.  Instead,
these builtin target descriptions can be got lazily and dynamically.
GDB builtin target descriptions are created from initialize_tdesc_*
functions in features/*.c files, while GDBserver builtin target
descriptions are generated from regformats/*.dat files.

This patch series changes both GDB and GDBserver to create target
description dynamically from features, instead of using pre-generated
target descriptions.  This patch series only convert x86-linux (
including i386-linux, amd64-linux and x32-linux) target description
to demonstrate the usefulness of the change.

Once one target architecture switches to the new flexible target
description, 

 - only need xml feature files under gdb/features directory.  All
 existing target description xml files can be kept for the tests.
 Add new xml feature file if we want to support the new feature,
 but don't need to add new target description xml files.

 - All existing gdb/regformats/*.dat are not used, but kept for
 the tests.

This is the V2, and V1 is here
https://sourceware.org/ml/gdb-patches/2017-05/msg00291.html,
the differences are,

 - Change target descriptions for both GDB and GDBserver,
 - Generate functions creating features from xml feature file
   instead of feature name, so that don't have to worry about
   different features with the same name (different features
   with the same name still have different file names).
 - Extend the changes for i386-linux to x86-linux (including,
   {i386,amd64,x32}-linux)

The big design change in V2 is that use generate c files from
xml feature files, and use generate c files in both GDB and
GDBserver.

In next step,  I want to remove the duplication of target
descriptions in GDB and GDBserver, and share more code on
creating x86-linux target descriptions in GDB and GDBserver.
I also want people give comments on how to do unit/self
tests in GDBserver, see patch 14.  The purpose of this patch
series is still to demonstrate the design, so the changelog,
NEWS entry, and doc may be incomplete.  I'll complete them
later.

Regression tested on x86_64-linux (both -m64 and -m32),
native and gdbserver, on aarch64-linux native and gdbserver.
ppc64-linux, native.

*** BLURB HERE ***

Yao Qi (25):
  Move initialize_tdesc_mips* calls from mips-linux-nat.c to
    mips-linux-tdep.c
  Adjust the order of 32bit-linux.xml and 32bit-sse.xml in
    i386/i386-linux.xml
  Class-fy tdesc_reg tdesc_type and tdesc_feature
  Centralize i386 linux target descriptions
  Use visitor pattern for "maint print c-tdesc"
  Generate c for feature instead of tdesc
  Lazily and dynamically create i386-linux target descriptions
  Add "maint check xml-descriptions" to test builtin xml target
    descriptions
  Use target_desc fields expedite_regs and xmltarget ifndef
    IN_PROCESS_AGENT
  Adjust code generated by regformats/regdat.sh
  Use VEC for target_desc.reg_defs
  [GDBserver] Centralize tdesc for i386-linux
  Dynamically create tdesc in GDBserver
  [RFC] GDBserver self test
  [RFC] GDBserver unit test to i386_tdesc
  Dynamically composite xml in reply to GDB
  Remove features/i386/i386-*linux.c
  [GDBserver] Use pre-generated tdesc as test
  GDBserver: remove srv_i386_linux_xmlfiles
  Centralize amd64-linux target descriptions
  Lazily and dynamically create amd64-linux target descriptions
  Regenerate two regformats/i386/.dat files
  [GDBserver] Convert amd64-linux target descriptions
  [GDBserver] Use pre-generated amd64-linux tdesc as test
  Remove features/i386/amd64-*linux.c and features/i386/x32-*linux.c

 gdb/amd64-linux-tdep.c                             |  165 ++-
 gdb/amd64-linux-tdep.h                             |    6 +
 gdb/cli/cli-cmds.c                                 |    4 +
 gdb/doc/gdb.texinfo                                |   15 +-
 gdb/features/Makefile                              |   59 +-
 gdb/features/i386/32bit-avx.c                      |   27 +
 gdb/features/i386/32bit-avx512.c                   |   39 +
 gdb/features/i386/32bit-core.c                     |   72 ++
 gdb/features/i386/32bit-linux.c                    |   21 +
 gdb/features/i386/32bit-mpx.c                      |   57 +
 gdb/features/i386/32bit-pkeys.c                    |   20 +
 gdb/features/i386/32bit-sse.c                      |   81 ++
 gdb/features/i386/64bit-avx.c                      |   35 +
 gdb/features/i386/64bit-avx512.c                   |  130 +++
 gdb/features/i386/64bit-core.c                     |   80 ++
 gdb/features/i386/64bit-linux.c                    |   21 +
 gdb/features/i386/64bit-mpx.c                      |   57 +
 gdb/features/i386/64bit-pkeys.c                    |   20 +
 gdb/features/i386/64bit-segments.c                 |   21 +
 gdb/features/i386/64bit-sse.c                      |   89 ++
 gdb/features/i386/amd64-avx-avx512-linux.c         |  288 -----
 gdb/features/i386/amd64-avx-linux.c                |  177 ----
 gdb/features/i386/amd64-avx-mpx-avx512-pku-linux.c |  329 ------
 gdb/features/i386/amd64-avx-mpx-linux.c            |  215 ----
 gdb/features/i386/amd64-linux.c                    |  159 ---
 gdb/features/i386/amd64-mpx-linux.c                |  197 ----
 gdb/features/i386/i386-avx-avx512-linux.c          |  170 ---
 gdb/features/i386/i386-avx-avx512.c                |    8 +-
 gdb/features/i386/i386-avx-linux.c                 |  149 ---
 gdb/features/i386/i386-avx-mpx-avx512-pku-linux.c  |  211 ----
 gdb/features/i386/i386-avx-mpx-avx512-pku.c        |    8 +-
 gdb/features/i386/i386-avx-mpx-linux.c             |  187 ----
 gdb/features/i386/i386-avx-mpx.c                   |    8 +-
 gdb/features/i386/i386-avx.c                       |    8 +-
 gdb/features/i386/i386-linux.c                     |  139 ---
 gdb/features/i386/i386-linux.xml                   |    2 +-
 gdb/features/i386/i386-mmx-linux.c                 |   78 --
 gdb/features/i386/i386-mmx.c                       |    8 +-
 gdb/features/i386/i386-mpx-linux.c                 |  177 ----
 gdb/features/i386/i386-mpx.c                       |    8 +-
 gdb/features/i386/i386.c                           |    8 +-
 gdb/features/i386/x32-avx-avx512-linux.c           |  288 -----
 gdb/features/i386/x32-avx-linux.c                  |  177 ----
 gdb/features/i386/x32-core.c                       |   80 ++
 gdb/features/i386/x32-linux.c                      |  159 ---
 gdb/gdbcmd.h                                       |    4 +
 gdb/gdbserver/Makefile.in                          |    2 +-
 gdb/gdbserver/config.in                            |    3 +
 gdb/gdbserver/configure                            |   12 +-
 gdb/gdbserver/configure.ac                         |    5 +
 gdb/gdbserver/configure.srv                        |   29 +-
 gdb/gdbserver/linux-amd64-ipa.c                    |   56 -
 gdb/gdbserver/linux-i386-ipa.c                     |   36 -
 gdb/gdbserver/linux-x86-low.c                      |  102 +-
 gdb/gdbserver/linux-x86-tdesc-selftest.c           |  200 ++++
 gdb/gdbserver/linux-x86-tdesc.c                    |  218 ++++
 gdb/gdbserver/linux-x86-tdesc.h                    |   77 +-
 gdb/gdbserver/regcache.c                           |   34 +-
 gdb/gdbserver/server.c                             |   28 +-
 gdb/gdbserver/tdesc.c                              |  140 ++-
 gdb/gdbserver/tdesc.h                              |  131 ++-
 gdb/i386-linux-tdep.c                              |  119 ++-
 gdb/i386-linux-tdep.h                              |   10 +-
 gdb/maint.c                                        |   18 +
 gdb/mips-linux-nat.c                               |   11 -
 gdb/mips-linux-tdep.c                              |   11 +
 gdb/mips-linux-tdep.h                              |    6 +
 .../i386/amd64-avx-mpx-avx512-pku-linux.dat        |    1 +
 gdb/regformats/i386/amd64-avx-mpx-avx512-pku.dat   |    3 -
 gdb/regformats/regdat.sh                           |   27 +-
 gdb/regformats/regdef.h                            |   12 +
 gdb/selftest.c                                     |   18 +-
 gdb/target-descriptions.c                          | 1109 +++++++++++++-------
 gdb/target-descriptions.h                          |   13 +-
 gdb/testsuite/gdb.gdb/unittest.exp                 |    5 +
 gdb/x86-linux-nat.c                                |   59 +-
 76 files changed, 2763 insertions(+), 3993 deletions(-)
 create mode 100644 gdb/features/i386/32bit-avx.c
 create mode 100644 gdb/features/i386/32bit-avx512.c
 create mode 100644 gdb/features/i386/32bit-core.c
 create mode 100644 gdb/features/i386/32bit-linux.c
 create mode 100644 gdb/features/i386/32bit-mpx.c
 create mode 100644 gdb/features/i386/32bit-pkeys.c
 create mode 100644 gdb/features/i386/32bit-sse.c
 create mode 100644 gdb/features/i386/64bit-avx.c
 create mode 100644 gdb/features/i386/64bit-avx512.c
 create mode 100644 gdb/features/i386/64bit-core.c
 create mode 100644 gdb/features/i386/64bit-linux.c
 create mode 100644 gdb/features/i386/64bit-mpx.c
 create mode 100644 gdb/features/i386/64bit-pkeys.c
 create mode 100644 gdb/features/i386/64bit-segments.c
 create mode 100644 gdb/features/i386/64bit-sse.c
 delete mode 100644 gdb/features/i386/amd64-avx-avx512-linux.c
 delete mode 100644 gdb/features/i386/amd64-avx-linux.c
 delete mode 100644 gdb/features/i386/amd64-avx-mpx-avx512-pku-linux.c
 delete mode 100644 gdb/features/i386/amd64-avx-mpx-linux.c
 delete mode 100644 gdb/features/i386/amd64-linux.c
 delete mode 100644 gdb/features/i386/amd64-mpx-linux.c
 delete mode 100644 gdb/features/i386/i386-avx-avx512-linux.c
 delete mode 100644 gdb/features/i386/i386-avx-linux.c
 delete mode 100644 gdb/features/i386/i386-avx-mpx-avx512-pku-linux.c
 delete mode 100644 gdb/features/i386/i386-avx-mpx-linux.c
 delete mode 100644 gdb/features/i386/i386-linux.c
 delete mode 100644 gdb/features/i386/i386-mmx-linux.c
 delete mode 100644 gdb/features/i386/i386-mpx-linux.c
 delete mode 100644 gdb/features/i386/x32-avx-avx512-linux.c
 delete mode 100644 gdb/features/i386/x32-avx-linux.c
 create mode 100644 gdb/features/i386/x32-core.c
 delete mode 100644 gdb/features/i386/x32-linux.c
 create mode 100644 gdb/gdbserver/linux-x86-tdesc-selftest.c
 create mode 100644 gdb/gdbserver/linux-x86-tdesc.c

-- 
1.9.1

^ permalink raw reply	[flat|nested] 82+ messages in thread

* [PATCH 22/25] Regenerate two regformats/i386/.dat files
  2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
                   ` (19 preceding siblings ...)
  2017-06-12  8:42 ` [PATCH 09/25] Use target_desc fields expedite_regs and xmltarget ifndef IN_PROCESS_AGENT Yao Qi
@ 2017-06-12  8:42 ` Yao Qi
  2017-06-22 12:43   ` Yao Qi
  2017-06-12  8:42 ` [PATCH 21/25] Lazily and dynamically create amd64-linux target descriptions Yao Qi
                   ` (5 subsequent siblings)
  26 siblings, 1 reply; 82+ messages in thread
From: Yao Qi @ 2017-06-12  8:42 UTC (permalink / raw)
  To: gdb-patches

The self tests which compare pre-generated target descriptions and dynamically
created target descriptions fail, and it turns out that two pre-generated
target descriptions are wrong, so regenerate them.

gdb:

2017-06-09  Yao Qi  <yao.qi@linaro.org>

	* regformats/i386/amd64-avx-mpx-avx512-pku-linux.dat: Regenerated.
	* regformats/i386/amd64-avx-mpx-avx512-pku.dat: Regenerated.
---
 gdb/regformats/i386/amd64-avx-mpx-avx512-pku-linux.dat | 1 +
 gdb/regformats/i386/amd64-avx-mpx-avx512-pku.dat       | 3 ---
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/gdb/regformats/i386/amd64-avx-mpx-avx512-pku-linux.dat b/gdb/regformats/i386/amd64-avx-mpx-avx512-pku-linux.dat
index 3ae6b0e..9cd0fae 100644
--- a/gdb/regformats/i386/amd64-avx-mpx-avx512-pku-linux.dat
+++ b/gdb/regformats/i386/amd64-avx-mpx-avx512-pku-linux.dat
@@ -157,3 +157,4 @@ expedite:rbp,rsp,rip
 256:zmm29h
 256:zmm30h
 256:zmm31h
+32:pkru
diff --git a/gdb/regformats/i386/amd64-avx-mpx-avx512-pku.dat b/gdb/regformats/i386/amd64-avx-mpx-avx512-pku.dat
index 88185fd..b3340d3 100644
--- a/gdb/regformats/i386/amd64-avx-mpx-avx512-pku.dat
+++ b/gdb/regformats/i386/amd64-avx-mpx-avx512-pku.dat
@@ -60,9 +60,6 @@ expedite:rbp,rsp,rip
 128:xmm14
 128:xmm15
 32:mxcsr
-64:orig_rax
-64:fs_base
-64:gs_base
 128:ymm0h
 128:ymm1h
 128:ymm2h
-- 
1.9.1

^ permalink raw reply	[flat|nested] 82+ messages in thread

* [PATCH 15/25] [RFC] GDBserver unit test to i386_tdesc
  2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
                   ` (9 preceding siblings ...)
  2017-06-12  8:42 ` [PATCH 23/25] [GDBserver] Convert amd64-linux target descriptions Yao Qi
@ 2017-06-12  8:42 ` Yao Qi
  2017-06-28 17:22   ` Pedro Alves
  2017-06-12  8:42 ` [PATCH 20/25] Centralize amd64-linux target descriptions Yao Qi
                   ` (15 subsequent siblings)
  26 siblings, 1 reply; 82+ messages in thread
From: Yao Qi @ 2017-06-12  8:42 UTC (permalink / raw)
  To: gdb-patches

This patch adds a unit test in GDBserver to test dynamically created
target descriptions equal to these pre-generated ones.

gdb/gdbserver:

2017-06-06  Yao Qi  <yao.qi@linaro.org>

	* linux-x86-tdesc.c (i386_tdesc_test): New function.
	(initialize_low_tdesc): Call register_self_test.
	* tdesc.h: TODO.
---
 gdb/gdbserver/linux-x86-tdesc.c | 45 +++++++++++++++++++++++++++++++++++++++++
 gdb/gdbserver/tdesc.h           | 42 +++++++++++++++++++++++++++++++++++++-
 gdb/regformats/regdef.h         | 12 +++++++++++
 3 files changed, 98 insertions(+), 1 deletion(-)

diff --git a/gdb/gdbserver/linux-x86-tdesc.c b/gdb/gdbserver/linux-x86-tdesc.c
index f247a3c..06e5bf9 100644
--- a/gdb/gdbserver/linux-x86-tdesc.c
+++ b/gdb/gdbserver/linux-x86-tdesc.c
@@ -61,6 +61,47 @@ extern const struct target_desc *tdesc_i386_mpx_linux;
 
 static const struct target_desc *i386_tdescs[X86_TDESC_LAST] = { };
 
+#if defined GDB_SELF_TEST && !defined IN_PROCESS_AGENT
+#include "selftest.h"
+
+namespace selftests {
+namespace gdbserver {
+static void
+i386_tdesc_test ()
+{
+  const struct target_desc *tdesc = i386_get_ipa_tdesc (X86_TDESC_MMX);
+
+  SELF_CHECK (*tdesc == *tdesc_i386_mmx_linux);
+  delete tdesc;
+
+  tdesc = i386_get_ipa_tdesc (X86_TDESC_SSE);
+  SELF_CHECK (*tdesc == *tdesc_i386_linux);
+  delete tdesc;
+
+  tdesc = i386_get_ipa_tdesc (X86_TDESC_AVX);
+  SELF_CHECK (*tdesc == *tdesc_i386_avx_linux);
+  delete tdesc;
+
+  tdesc = i386_get_ipa_tdesc (X86_TDESC_MPX);
+  SELF_CHECK (*tdesc == *tdesc_i386_mpx_linux);
+  delete tdesc;
+
+  tdesc = i386_get_ipa_tdesc (X86_TDESC_AVX_MPX);
+  SELF_CHECK (*tdesc == *tdesc_i386_avx_mpx_linux);
+  delete tdesc;
+
+  tdesc = i386_get_ipa_tdesc (X86_TDESC_AVX_AVX512);
+  SELF_CHECK (*tdesc == *tdesc_i386_avx_avx512_linux);
+  delete tdesc;
+
+  tdesc = i386_get_ipa_tdesc (X86_TDESC_AVX_MPX_AVX512_PKU);
+  SELF_CHECK (*tdesc == *tdesc_i386_avx_mpx_avx512_pku_linux);
+  delete tdesc;
+}
+}
+} // namespace selftests
+#endif /* GDB_SELF_TEST */
+
 void
 initialize_low_tdesc ()
 {
@@ -72,6 +113,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
+  register_self_test (selftests::gdbserver::i386_tdesc_test);
+#endif
 #endif
 }
 
diff --git a/gdb/gdbserver/tdesc.h b/gdb/gdbserver/tdesc.h
index 2d4cbfa..e64f0b3 100644
--- a/gdb/gdbserver/tdesc.h
+++ b/gdb/gdbserver/tdesc.h
@@ -19,7 +19,8 @@
 #ifndef TDESC_H
 #define TDESC_H
 
-struct reg;
+#include "regdef.h"
+#include <cstring>
 
 typedef struct reg *tdesc_reg_p;
 DEF_VEC_P(tdesc_reg_p);
@@ -60,6 +61,45 @@ 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 true;
+
+    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 true;
+      }
+
+    /* Compare expedite_regs.  */
+    int i = 0;
+    for (; expedite_regs[i] != NULL; i++)
+      {
+	if (strcmp (expedite_regs[i], other.expedite_regs[i]) != 0)
+	  return true;
+      }
+    if (other.expedite_regs[i] != NULL)
+      return true;
+
+    if (strcmp (xmltarget, other.xmltarget) != 0)
+      return true;
+
+    return false;
+  }
+
+  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

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 06/25] Generate c for feature instead of tdesc
  2017-06-12  8:42 ` [PATCH 06/25] Generate c for feature instead of tdesc Yao Qi
@ 2017-06-12 14:48   ` Eli Zaretskii
  2017-06-13 12:07     ` Yao Qi
  2017-06-20 10:59   ` Pedro Alves
  2017-06-26 21:38   ` Simon Marchi
  2 siblings, 1 reply; 82+ messages in thread
From: Eli Zaretskii @ 2017-06-12 14:48 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

> From: Yao Qi <qiyaoltc@gmail.com>
> Date: Mon, 12 Jun 2017 09:41:37 +0100
> 
> gdb/doc:
> 
> 2017-06-08  Yao Qi  <yao.qi@linaro.org>
> 
> 	* gdb.texinfo (Maintenance Commands): Document optional
> 	argument of "maint print c-tdesc".

Thanks.

> -@kindex maint print c-tdesc
> +@kindex maint print c-tdesc @r{[}@var{file}@r{]}
>  @item maint print c-tdesc
> -Print the current target description (@pxref{Target Descriptions}) as
> -a C source file.  The created source file can be used in @value{GDBN}
> -when an XML parser is not available to parse the description.
> +Print the target description (@pxref{Target Descriptions}) as
> +a C source file.  The target description is got from the optional
                                            ^^^^^^
"is produced", I guess?  Or maybe I don't understand what you mean by
"is got" here.

> +argument @var{file} or the current target description.

I think this should be described in the reverse order:

  By default, the target description is for the current target, but if
  the optional argument @var{file} is provided, that file is used to
  produce the description.

>                                                        The created
> +source file can be used in @value{GDBN} when an XML parser is not
> +available to parse the description.

I also have some clarification requests (and I do realize that the
original text had the same issues):

 . I think we should say a few words regarding the argument FILE: I
   don't believe _any_ file will do in this role, so we should tell
   what kind of files are expected here.
 . "The created source file can be used in GDB ..." -- used how?  I'd
   prefer that we said a sentence or tow about that as well, or had a
   cross-reference to where that is described.

Also, what about a NEWS entry?

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 01/25] Move initialize_tdesc_mips* calls from mips-linux-nat.c to mips-linux-tdep.c
  2017-06-12  8:42 ` [PATCH 01/25] Move initialize_tdesc_mips* calls from mips-linux-nat.c to mips-linux-tdep.c Yao Qi
@ 2017-06-12 15:25   ` Maciej W. Rozycki
  2017-06-13  8:07     ` Yao Qi
  0 siblings, 1 reply; 82+ messages in thread
From: Maciej W. Rozycki @ 2017-06-12 15:25 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

On Mon, 12 Jun 2017, Yao Qi wrote:

> All target descriptions except mips initialization are called in -tdep.c,
> instead of -nat.c, so this patch moves mips target descriptions initialization
> to -tdep.c.  Secondly, I want to change the target descriptions from pre-generated
> to dynamical creation, so I want to test that these pre-generated target
> descriptions equal to these dynamically created ones.  Move target descriptions
> initialization to -tdep.c files so we can test them in any hosts (if they are
> still -nat.c, we can only test them on mips-linux host.).

 Can you please wrap the commit description such that it does not go past 
80th column?  Bear in mind that GIT indents by 4 characters, but if you 
stick to our general 74-column rule for text you'll be good.

 Otherwise LGTM.

  Maciej

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 01/25] Move initialize_tdesc_mips* calls from mips-linux-nat.c to mips-linux-tdep.c
  2017-06-12 15:25   ` Maciej W. Rozycki
@ 2017-06-13  8:07     ` Yao Qi
  0 siblings, 0 replies; 82+ messages in thread
From: Yao Qi @ 2017-06-13  8:07 UTC (permalink / raw)
  To: Maciej W. Rozycki; +Cc: gdb-patches

"Maciej W. Rozycki" <macro@imgtec.com> writes:

>  Can you please wrap the commit description such that it does not go past 
> 80th column?  Bear in mind that GIT indents by 4 characters, but if you 
> stick to our general 74-column rule for text you'll be good.
>

OK, I adjust the line width in the commit log.  Patch below is pushed.

-- 
Yao (齐尧)

From 032bb6eae8a0166f9b5d2eac6960383c532ef6d1 Mon Sep 17 00:00:00 2001
From: Yao Qi <yao.qi@linaro.org>
Date: Tue, 13 Jun 2017 09:05:04 +0100
Subject: [PATCH] Move initialize_tdesc_mips* calls from mips-linux-nat.c to
 mips-linux-tdep.c

All target descriptions except mips initialization are called in -tdep.c,
instead of -nat.c, so this patch moves mips target descriptions
initialization to -tdep.c.  Secondly, I want to change the target
descriptions from pre-generated to dynamical creation, so I want to test
that these pre-generated target descriptions equal to these dynamically
created ones.  Move target descriptions initialization to -tdep.c files so
we can test them in any hosts (if they are still -nat.c, we can only test
them on mips-linux host.).

gdb:

2017-06-13  Yao Qi  <yao.qi@linaro.org>

	* mips-linux-nat.c: Move include features/mips*-linux.c to
	mips-linux-tdep.c.
	(_initialize_mips_linux_nat): Move initialize_tdesc_mips* calls
	to mips-linux-tdep.c.
	* mips-linux-tdep.c: Include features/mips*-linux.c
	(_initialize_mips_linux_tdep): Call initialize_tdesc_mips*
	functions.
	* mips-linux-tdep.h (tdesc_mips_linux): Declare.
	(tdesc_mips_dsp_linux, tdesc_mips64_linux): Declare.
	(tdesc_mips64_dsp_linux): Declare.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 2956819..c2bceeb 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,16 @@
+2017-06-13  Yao Qi  <yao.qi@linaro.org>
+
+	* mips-linux-nat.c: Move include features/mips*-linux.c to
+	mips-linux-tdep.c.
+	(_initialize_mips_linux_nat): Move initialize_tdesc_mips* calls
+	to mips-linux-tdep.c.
+	* mips-linux-tdep.c: Include features/mips*-linux.c
+	(_initialize_mips_linux_tdep): Call initialize_tdesc_mips*
+	functions.
+	* mips-linux-tdep.h (tdesc_mips_linux): Declare.
+	(tdesc_mips_dsp_linux, tdesc_mips64_linux): Declare.
+	(tdesc_mips64_dsp_linux): Declare.
+
 2017-06-12  Tom Tromey  <tom@tromey.com>
 
 	* valprint.h (val_print_type_code_int): Remove.
diff --git a/gdb/mips-linux-nat.c b/gdb/mips-linux-nat.c
index 8041d84..1fd3365 100644
--- a/gdb/mips-linux-nat.c
+++ b/gdb/mips-linux-nat.c
@@ -38,11 +38,6 @@
 
 #include "nat/mips-linux-watch.h"
 
-#include "features/mips-linux.c"
-#include "features/mips-dsp-linux.c"
-#include "features/mips64-linux.c"
-#include "features/mips64-dsp-linux.c"
-
 #ifndef PTRACE_GET_THREAD_AREA
 #define PTRACE_GET_THREAD_AREA 25
 #endif
@@ -803,10 +798,4 @@ triggers a breakpoint or watchpoint."),
 
   linux_nat_add_target (t);
   linux_nat_set_new_thread (t, mips_linux_new_thread);
-
-  /* Initialize the standard target descriptions.  */
-  initialize_tdesc_mips_linux ();
-  initialize_tdesc_mips_dsp_linux ();
-  initialize_tdesc_mips64_linux ();
-  initialize_tdesc_mips64_dsp_linux ();
 }
diff --git a/gdb/mips-linux-tdep.c b/gdb/mips-linux-tdep.c
index ccfdcdf..f144a2e 100644
--- a/gdb/mips-linux-tdep.c
+++ b/gdb/mips-linux-tdep.c
@@ -40,6 +40,11 @@
 #include "xml-syscall.h"
 #include "gdb_signals.h"
 
+#include "features/mips-linux.c"
+#include "features/mips-dsp-linux.c"
+#include "features/mips64-linux.c"
+#include "features/mips64-dsp-linux.c"
+
 static struct target_so_ops mips_svr4_so_ops;
 
 /* This enum represents the signals' numbers on the MIPS
@@ -1739,4 +1744,10 @@ _initialize_mips_linux_tdep (void)
 			      GDB_OSABI_LINUX,
 			      mips_linux_init_abi);
     }
+
+  /* Initialize the standard target descriptions.  */
+  initialize_tdesc_mips_linux ();
+  initialize_tdesc_mips_dsp_linux ();
+  initialize_tdesc_mips64_linux ();
+  initialize_tdesc_mips64_dsp_linux ();
 }
diff --git a/gdb/mips-linux-tdep.h b/gdb/mips-linux-tdep.h
index 407b577..cca4798 100644
--- a/gdb/mips-linux-tdep.h
+++ b/gdb/mips-linux-tdep.h
@@ -105,3 +105,9 @@ enum {
 /* Return 1 if MIPS_RESTART_REGNUM is usable.  */
 
 int mips_linux_restart_reg_p (struct gdbarch *gdbarch);
+
+/* Target descriptions.  */
+extern struct target_desc *tdesc_mips_linux;
+extern struct target_desc *tdesc_mips64_linux;
+extern struct target_desc *tdesc_mips_dsp_linux;
+extern struct target_desc *tdesc_mips64_dsp_linux;

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 06/25] Generate c for feature instead of tdesc
  2017-06-12 14:48   ` Eli Zaretskii
@ 2017-06-13 12:07     ` Yao Qi
  2017-06-13 14:49       ` Eli Zaretskii
  0 siblings, 1 reply; 82+ messages in thread
From: Yao Qi @ 2017-06-13 12:07 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

Eli Zaretskii <eliz@gnu.org> writes:

>>                                                        The created
>> +source file can be used in @value{GDBN} when an XML parser is not
>> +available to parse the description.
>
> I also have some clarification requests (and I do realize that the
> original text had the same issues):
>
>  . I think we should say a few words regarding the argument FILE: I
>    don't believe _any_ file will do in this role, so we should tell
>    what kind of files are expected here.

It is an XML target description.

>  . "The created source file can be used in GDB ..." -- used how?  I'd
>    prefer that we said a sentence or tow about that as well, or had a
>    cross-reference to where that is described.

The created source file is built into GDB.  How is the doc and NEWS
entry below?  Note that I removed the last sentence "... when an XML
parser is not available to parse the description", because these created
c files are builtin target descriptions which are used too when an XML
parser is available.

@kindex maint print c-tdesc @r{[}@var{file}@r{]}
@item maint print c-tdesc
Print the target description (@pxref{Target Descriptions}) as
a C source file.  By default, the target description is for the current
target, but if the optional argument @var{file} is provided, that file
is used to produce the description.  The @var{file} is an XML document,
of the form described in @ref{Target Description Format}.  The created
source file is built in @value{GDBN}.

>
> Also, what about a NEWS entry?

* The "maintenance print c-tdesc" command now takes an optional
  argument which is the file name of XML target description.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 06/25] Generate c for feature instead of tdesc
  2017-06-13 12:07     ` Yao Qi
@ 2017-06-13 14:49       ` Eli Zaretskii
  2017-06-13 15:31         ` Yao Qi
  0 siblings, 1 reply; 82+ messages in thread
From: Eli Zaretskii @ 2017-06-13 14:49 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

> From: Yao Qi <qiyaoltc@gmail.com>
> Cc: gdb-patches@sourceware.org
> Date: Tue, 13 Jun 2017 13:07:20 +0100
> 
> >  . "The created source file can be used in GDB ..." -- used how?  I'd
> >    prefer that we said a sentence or tow about that as well, or had a
> >    cross-reference to where that is described.
> 
> The created source file is built into GDB.

Sorry, I don't understand: built into GDB how?  The GDB in which the
user runs this command can then turn around and have the produced file
built into it?

> How is the doc and NEWS entry below?

OK, with two comments, see below.

> @kindex maint print c-tdesc @r{[}@var{file}@r{]}
> @item maint print c-tdesc
> Print the target description (@pxref{Target Descriptions}) as
> a C source file.  By default, the target description is for the current
> target, but if the optional argument @var{file} is provided, that file
> is used to produce the description.  The @var{file} is an XML document,
                                                      ^^
"should be"

> of the form described in @ref{Target Description Format}.  The created
> source file is built in @value{GDBN}.
                       ^^
"into"

> > Also, what about a NEWS entry?
> 
> * The "maintenance print c-tdesc" command now takes an optional
>   argument which is the file name of XML target description.

This is OK.

Thanks.

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 06/25] Generate c for feature instead of tdesc
  2017-06-13 14:49       ` Eli Zaretskii
@ 2017-06-13 15:31         ` Yao Qi
  2017-06-13 15:41           ` Eli Zaretskii
  0 siblings, 1 reply; 82+ messages in thread
From: Yao Qi @ 2017-06-13 15:31 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

Eli Zaretskii <eliz@gnu.org> writes:

> Sorry, I don't understand: built into GDB how?  The GDB in which the
> user runs this command can then turn around and have the produced file
> built into it?

Yes,
We feed GDB the XML target description file, let GDB print the c file,
and then include these generated c files in *-tdep.c.  That is, in
gdb/features/Makefile, we have,

%.c: %.xml
        $(GDB) -nx -q -batch \
          -ex "set tdesc filename $<" -ex 'maint print c-tdesc' > $@.tmp
        sh ../../move-if-change $@.tmp $@

it generates gdb/features/*.c files from the corresponding .xml files.
They are included in gdb source, like, in gdb/i386-linux-tdep.c,

#include "features/i386/i386-linux.c"
#include "features/i386/i386-mmx-linux.c"
#include "features/i386/i386-mpx-linux.c"
#include "features/i386/i386-avx-mpx-linux.c"
#include "features/i386/i386-avx-linux.c"
#include "features/i386/i386-avx-avx512-linux.c"
#include "features/i386/i386-avx-mpx-avx512-pku-linux.c"

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 06/25] Generate c for feature instead of tdesc
  2017-06-13 15:31         ` Yao Qi
@ 2017-06-13 15:41           ` Eli Zaretskii
  2017-06-14 16:21             ` Yao Qi
  0 siblings, 1 reply; 82+ messages in thread
From: Eli Zaretskii @ 2017-06-13 15:41 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

> From: Yao Qi <qiyaoltc@gmail.com>
> Cc: gdb-patches@sourceware.org
> Date: Tue, 13 Jun 2017 16:31:16 +0100
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > Sorry, I don't understand: built into GDB how?  The GDB in which the
> > user runs this command can then turn around and have the produced file
> > built into it?
> 
> Yes,
> We feed GDB the XML target description file, let GDB print the c file,
> and then include these generated c files in *-tdep.c.

But that means the produced file can only be used by rebuilding GDB,
doesn't it?  If so, the text should make this clear, I think.

(In general, since GDB is a compiled program which cannot easily be
modified without rebuilding it, I wonder how useful this feature will
be.  But I'll yield to your expertise on that.)

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 06/25] Generate c for feature instead of tdesc
  2017-06-13 15:41           ` Eli Zaretskii
@ 2017-06-14 16:21             ` Yao Qi
  2017-06-14 16:32               ` Eli Zaretskii
  0 siblings, 1 reply; 82+ messages in thread
From: Yao Qi @ 2017-06-14 16:21 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

Eli Zaretskii <eliz@gnu.org> writes:

> But that means the produced file can only be used by rebuilding GDB,
> doesn't it?  If so, the text should make this clear, I think.
>

Yes.  The last sentence is about it, "The created source file is built
into @value{GDBN}", but I didn't explicitly say GDB needs rebuild.

> (In general, since GDB is a compiled program which cannot easily be
> modified without rebuilding it, I wonder how useful this feature will
> be.  But I'll yield to your expertise on that.)

This command is only used by developers after they add or modify XML
target descriptions.  I don't think GDB users will use this command.
A question in general, do we really need to document these commands,
which are used for GDB development, in GDB user manual?  These
commands are "maint print c-tdesc", "maint check xml-descriptions"
(added by one patch in this series), and "maint selftest".  Can we
remove them from the user manual?

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 06/25] Generate c for feature instead of tdesc
  2017-06-14 16:21             ` Yao Qi
@ 2017-06-14 16:32               ` Eli Zaretskii
  2017-06-15 13:19                 ` Yao Qi
  0 siblings, 1 reply; 82+ messages in thread
From: Eli Zaretskii @ 2017-06-14 16:32 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

> From: Yao Qi <qiyaoltc@gmail.com>
> Cc: gdb-patches@sourceware.org
> Date: Wed, 14 Jun 2017 17:21:36 +0100
> 
> > But that means the produced file can only be used by rebuilding GDB,
> > doesn't it?  If so, the text should make this clear, I think.
> >
> 
> Yes.  The last sentence is about it, "The created source file is built
> into @value{GDBN}", but I didn't explicitly say GDB needs rebuild.

I think we should say that.

> > (In general, since GDB is a compiled program which cannot easily be
> > modified without rebuilding it, I wonder how useful this feature will
> > be.  But I'll yield to your expertise on that.)
> 
> This command is only used by developers after they add or modify XML
> target descriptions.

Then I think we should say that as well.

> A question in general, do we really need to document these commands,
> which are used for GDB development, in GDB user manual?  These
> commands are "maint print c-tdesc", "maint check xml-descriptions"
> (added by one patch in this series), and "maint selftest".  Can we
> remove them from the user manual?

If we remove them, there will be no place where they are documented,
right?  GDB developers are GDB users as well, e.g. I read the manual
quite a lot.

So I see no reason to remove these commands.  We just need to indicate
when a command makes sense only for GDB developers.

Thanks.

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 06/25] Generate c for feature instead of tdesc
  2017-06-14 16:32               ` Eli Zaretskii
@ 2017-06-15 13:19                 ` Yao Qi
  2017-06-15 14:45                   ` Eli Zaretskii
  0 siblings, 1 reply; 82+ messages in thread
From: Yao Qi @ 2017-06-15 13:19 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

Eli Zaretskii <eliz@gnu.org> writes:

>> Yes.  The last sentence is about it, "The created source file is built
>> into @value{GDBN}", but I didn't explicitly say GDB needs rebuild.
>
> I think we should say that.
>
>> > (In general, since GDB is a compiled program which cannot easily be
>> > modified without rebuilding it, I wonder how useful this feature will
>> > be.  But I'll yield to your expertise on that.)
>> 
>> This command is only used by developers after they add or modify XML
>> target descriptions.
>
> Then I think we should say that as well.
>

I update the paragraph for this command a little bit,

@kindex maint print c-tdesc @r{[}@var{file}@r{]}
@item maint print c-tdesc
Print the target description (@pxref{Target Descriptions}) as
a C source file.  By default, the target description is for the current
target, but if the optional argument @var{file} is provided, that file
is used to produce the description.  The @var{file} should be an XML
document, of the form described in @ref{Target Description Format}.
The created source file is built into @value{GDBN} when @value{GDBN} is
built again.  This command is used by developers after they add or
modify XML target descriptions.

>> A question in general, do we really need to document these commands,
>> which are used for GDB development, in GDB user manual?  These
>> commands are "maint print c-tdesc", "maint check xml-descriptions"
>> (added by one patch in this series), and "maint selftest".  Can we
>> remove them from the user manual?
>
> If we remove them, there will be no place where they are documented,
> right?  GDB developers are GDB users as well, e.g. I read the manual
> quite a lot.
>
> So I see no reason to remove these commands.  We just need to indicate
> when a command makes sense only for GDB developers.

but GDB users are not GDB developers.  Why does user manual documents
some commands users never use?  IMO, these documents should be
documented in GDB internals.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 06/25] Generate c for feature instead of tdesc
  2017-06-15 13:19                 ` Yao Qi
@ 2017-06-15 14:45                   ` Eli Zaretskii
  0 siblings, 0 replies; 82+ messages in thread
From: Eli Zaretskii @ 2017-06-15 14:45 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

> From: Yao Qi <qiyaoltc@gmail.com>
> Cc: gdb-patches@sourceware.org
> Date: Thu, 15 Jun 2017 14:19:25 +0100
> 
> I update the paragraph for this command a little bit,
> 
> @kindex maint print c-tdesc @r{[}@var{file}@r{]}
> @item maint print c-tdesc
> Print the target description (@pxref{Target Descriptions}) as
> a C source file.  By default, the target description is for the current
> target, but if the optional argument @var{file} is provided, that file
> is used to produce the description.  The @var{file} should be an XML
> document, of the form described in @ref{Target Description Format}.
> The created source file is built into @value{GDBN} when @value{GDBN} is
> built again.  This command is used by developers after they add or
> modify XML target descriptions.

Thanks, this is good.

> > If we remove them, there will be no place where they are documented,
> > right?  GDB developers are GDB users as well, e.g. I read the manual
> > quite a lot.
> >
> > So I see no reason to remove these commands.  We just need to indicate
> > when a command makes sense only for GDB developers.
> 
> but GDB users are not GDB developers.  Why does user manual documents
> some commands users never use?

Because I expect GDB developers to look for commands they need to use
in this manual.

> IMO, these documents should be documented in GDB internals.

AFAIU, GDB internals documents the GDB implementation, not commands
and options that are used interactively within GDB.

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 00/25 V2] Make GDB builtin target descriptions more  flexible
  2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
                   ` (24 preceding siblings ...)
  2017-06-12  8:42 ` [PATCH 16/25] Dynamically composite xml in reply to GDB Yao Qi
@ 2017-06-19 19:59 ` Simon Marchi
  2017-06-20 11:02   ` Yao Qi
  2017-06-26 14:45   ` Tedeschi, Walfred
  2017-06-28 19:06 ` Pedro Alves
  26 siblings, 2 replies; 82+ messages in thread
From: Simon Marchi @ 2017-06-19 19:59 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

On 2017-06-12 10:41, Yao Qi wrote:
> This patch series is to change GDB and GDBserver builtin target
> descriptions more flexible, by removing pre-generated ones.  Instead,
> these builtin target descriptions can be got lazily and dynamically.
> GDB builtin target descriptions are created from initialize_tdesc_*
> functions in features/*.c files, while GDBserver builtin target
> descriptions are generated from regformats/*.dat files.
> 
> This patch series changes both GDB and GDBserver to create target
> description dynamically from features, instead of using pre-generated
> target descriptions.  This patch series only convert x86-linux (
> including i386-linux, amd64-linux and x32-linux) target description
> to demonstrate the usefulness of the change.
> 
> Once one target architecture switches to the new flexible target
> description,
> 
>  - only need xml feature files under gdb/features directory.  All
>  existing target description xml files can be kept for the tests.
>  Add new xml feature file if we want to support the new feature,
>  but don't need to add new target description xml files.
> 
>  - All existing gdb/regformats/*.dat are not used, but kept for
>  the tests.
> 
> This is the V2, and V1 is here
> https://sourceware.org/ml/gdb-patches/2017-05/msg00291.html,
> the differences are,
> 
>  - Change target descriptions for both GDB and GDBserver,
>  - Generate functions creating features from xml feature file
>    instead of feature name, so that don't have to worry about
>    different features with the same name (different features
>    with the same name still have different file names).
>  - Extend the changes for i386-linux to x86-linux (including,
>    {i386,amd64,x32}-linux)
> 
> The big design change in V2 is that use generate c files from
> xml feature files, and use generate c files in both GDB and
> GDBserver.
> 
> In next step,  I want to remove the duplication of target
> descriptions in GDB and GDBserver, and share more code on
> creating x86-linux target descriptions in GDB and GDBserver.
> I also want people give comments on how to do unit/self
> tests in GDBserver, see patch 14.  The purpose of this patch
> series is still to demonstrate the design, so the changelog,
> NEWS entry, and doc may be incomplete.  I'll complete them
> later.
> 
> Regression tested on x86_64-linux (both -m64 and -m32),
> native and gdbserver, on aarch64-linux native and gdbserver.
> ppc64-linux, native.

Hi Yao,

Do you have a git branch we can pull from to look at this change?

Thanks,

Simon

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 02/25] Adjust the order of 32bit-linux.xml and  32bit-sse.xml in i386/i386-linux.xml
  2017-06-12  8:42 ` [PATCH 02/25] Adjust the order of 32bit-linux.xml and 32bit-sse.xml in i386/i386-linux.xml Yao Qi
@ 2017-06-19 20:22   ` Simon Marchi
  2017-06-19 21:24     ` Pedro Alves
  0 siblings, 1 reply; 82+ messages in thread
From: Simon Marchi @ 2017-06-19 20:22 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

On 2017-06-12 10:41, Yao Qi wrote:
> Exchange the order of 32bit-linux.xml and 32bit-sse.xml in
> i386/i386-linux.xml, to align with other i386 linux .xml files.
> 
> gdb:
> 
> 2017-04-27  Yao Qi  <yao.qi@linaro.org>
> 
> 	* features/i386/i386-linux.xml: Exchange the order of including
> 	32bit-linux.xml and 32bit-sse.xml.
> 	* features/i386/i386-linux.c: Regenerated.
> ---
>  gdb/features/i386/i386-linux.c   | 6 +++---
>  gdb/features/i386/i386-linux.xml | 2 +-
>  2 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/gdb/features/i386/i386-linux.c 
> b/gdb/features/i386/i386-linux.c
> index 42c406b..c7796c3 100644
> --- a/gdb/features/i386/i386-linux.c
> +++ b/gdb/features/i386/i386-linux.c
> @@ -71,9 +71,6 @@ initialize_tdesc_i386_linux (void)
>    tdesc_create_reg (feature, "fooff", 30, 1, "float", 32, "int");
>    tdesc_create_reg (feature, "fop", 31, 1, "float", 32, "int");
> 
> -  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
> -  tdesc_create_reg (feature, "orig_eax", 41, 1, NULL, 32, "int");
> -
>    feature = tdesc_create_feature (result, "org.gnu.gdb.i386.sse");
>    field_type = tdesc_named_type (feature, "ieee_single");
>    tdesc_create_vector (feature, "v4f", field_type, 4);
> @@ -135,5 +132,8 @@ initialize_tdesc_i386_linux (void)
>    tdesc_create_reg (feature, "xmm7", 39, 1, NULL, 128, "vec128");
>    tdesc_create_reg (feature, "mxcsr", 40, 1, "vector", 32, 
> "i386_mxcsr");
> 
> +  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
> +  tdesc_create_reg (feature, "orig_eax", 41, 1, NULL, 32, "int");
> +
>    tdesc_i386_linux = result;
>  }
> diff --git a/gdb/features/i386/i386-linux.xml 
> b/gdb/features/i386/i386-linux.xml
> index f9aa311..17f9a1a 100644
> --- a/gdb/features/i386/i386-linux.xml
> +++ b/gdb/features/i386/i386-linux.xml
> @@ -12,6 +12,6 @@
>    <architecture>i386</architecture>
>    <osabi>GNU/Linux</osabi>
>    <xi:include href="32bit-core.xml"/>
> -  <xi:include href="32bit-linux.xml"/>
>    <xi:include href="32bit-sse.xml"/>
> +  <xi:include href="32bit-linux.xml"/>
>  </target>

I think you can push this one right away as a cosmetic cleanup.

Simon

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 03/25] Class-fy tdesc_reg tdesc_type and tdesc_feature
  2017-06-12  8:42 ` [PATCH 03/25] Class-fy tdesc_reg tdesc_type and tdesc_feature Yao Qi
@ 2017-06-19 20:55   ` Simon Marchi
  2017-06-19 21:30   ` Simon Marchi
  1 sibling, 0 replies; 82+ messages in thread
From: Simon Marchi @ 2017-06-19 20:55 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

On 2017-06-12 10:41, Yao Qi wrote:
> This patch class-fies them, adding ctor, dtor, and deleting
> copy ctor and assignment operator.
> 
> gdb:
> 
> 2017-05-20  Yao Qi  <yao.qi@linaro.org>
> 
> 	* target-descriptions.c (tdesc_reg): Add ctor, dtor.
> 	Delete copy ctor and assignment operator.
> 	(tdesc_type): Likewise.
> 	(tdesc_feature): Likewise.
> 	(tdesc_free_reg): Remove.
> 	(tdesc_create_reg): Use new.
> 	(tdesc_free_type): Remove.
> 	(tdesc_create_vector): Use new.
> 	(tdesc_create_union): Likewise.
> 	(tdesc_create_flags): Likewise.
> 	(tdesc_create_enum): Likewise.
> 	(tdesc_free_feature): Delete.
> 	(free_target_description): Use delete.
> ---
>  gdb/target-descriptions.c | 200 
> +++++++++++++++++++++++-----------------------
>  1 file changed, 100 insertions(+), 100 deletions(-)
> 
> diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
> index 9a7e2dd..e2dcd1d 100644
> --- a/gdb/target-descriptions.c
> +++ b/gdb/target-descriptions.c
> @@ -48,6 +48,32 @@ DEF_VEC_O(property_s);
> 
>  typedef struct tdesc_reg
>  {
> +public:

Since you are using the "struct" keyword, members are public by default, 
so you don't have to put "public:".  Same things for other types.

Otherwise it LGTM.  Of course, more c++ification is always possible, but 
I think it's fine to go in small increments.

Just FYI, I tested this on top of my "poison-xnew" branch, which points 
out the invalid use of XNEW/xfree on non-POD types, and it built fine.

Simon

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 02/25] Adjust the order of 32bit-linux.xml and 32bit-sse.xml in i386/i386-linux.xml
  2017-06-19 20:22   ` Simon Marchi
@ 2017-06-19 21:24     ` Pedro Alves
  2017-06-19 21:48       ` Simon Marchi
  0 siblings, 1 reply; 82+ messages in thread
From: Pedro Alves @ 2017-06-19 21:24 UTC (permalink / raw)
  To: Simon Marchi, Yao Qi; +Cc: gdb-patches

On 06/19/2017 09:22 PM, Simon Marchi wrote:
> On 2017-06-12 10:41, Yao Qi wrote:
>> Exchange the order of 32bit-linux.xml and 32bit-sse.xml in
>> i386/i386-linux.xml, to align with other i386 linux .xml files.
>>


>> --- a/gdb/features/i386/i386-linux.xml
>> +++ b/gdb/features/i386/i386-linux.xml
>> @@ -12,6 +12,6 @@
>>    <architecture>i386</architecture>
>>    <osabi>GNU/Linux</osabi>
>>    <xi:include href="32bit-core.xml"/>
>> -  <xi:include href="32bit-linux.xml"/>
>>    <xi:include href="32bit-sse.xml"/>
>> +  <xi:include href="32bit-linux.xml"/>
>>  </target>
> 
> I think you can push this one right away as a cosmetic cleanup.

Unless this is a case of a default target description matching
the layout of targets that predated support for XML descriptions.

Could that be the case here?  From:

static void
i386_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
{
...
  if (! tdesc_has_registers (tdesc))
    tdesc = tdesc_i386_linux;
...

... it may well be.  So we need to tread carefully here.  The
order may be required for back compatibility.  A deeper audit
with that in mind is in order.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 04/25] Centralize i386 linux target descriptions
  2017-06-12  8:42 ` [PATCH 04/25] Centralize i386 linux target descriptions Yao Qi
@ 2017-06-19 21:27   ` Simon Marchi
  0 siblings, 0 replies; 82+ messages in thread
From: Simon Marchi @ 2017-06-19 21:27 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

On 2017-06-12 10:41, Yao Qi wrote:
> This patch moves all the tdesc_i386*_linux target descriptions to a
> function i386_linux_read_description, which returns the right target
> description according to xcr0.  This also remove the duplication in
> getting target descriptions in corefile and native target.
> 
> gdb:
> 
> 2017-04-27  Yao Qi  <yao.qi@linaro.org>
> 
> 	* i386-linux-tdep.c (i386_linux_read_description): New function.
> 	(i386_linux_core_read_description): Call
> 	i386_linux_read_description.
> 	* i386-linux-tdep.h (i386_linux_read_description): Declare.
> 	(tdesc_i386_linux, tdesc_i386_mmx_linux): Remove declarations.
> 	(tdesc_i386_avx_linux, tdesc_i386_mpx_linux): Likewise
> 	(tdesc_i386_avx_mpx_linux, tdesc_i386_avx_avx512_linux): Likewise.
> 	(tdesc_i386_avx_mpx_avx512_pku_linux): Likewise.
> 	* x86-linux-nat.c (x86_linux_read_description): Call
> 	i386_linux_read_description.
> ---
>  gdb/i386-linux-tdep.c | 34 ++++++++++++++++++++++------------
>  gdb/i386-linux-tdep.h | 10 ++--------
>  gdb/x86-linux-nat.c   | 24 ++++++++----------------
>  3 files changed, 32 insertions(+), 36 deletions(-)
> 
> diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c
> index 1909d61..1bc1a6f 100644
> --- a/gdb/i386-linux-tdep.c
> +++ b/gdb/i386-linux-tdep.c
> @@ -678,16 +678,9 @@ i386_linux_core_read_xcr0 (bfd *abfd)
>    return xcr0;
>  }
> 
> -/* Get Linux/x86 target description from core dump.  */
> -
> -static const struct target_desc *
> -i386_linux_core_read_description (struct gdbarch *gdbarch,
> -				  struct target_ops *target,
> -				  bfd *abfd)
> +const struct target_desc *
> +i386_linux_read_description (uint64_t xcr0)

This would need a comment

   /* See i386-linux-tdep.h.  */

>  {
> -  /* Linux/i386.  */
> -  uint64_t xcr0 = i386_linux_core_read_xcr0 (abfd);
> -
>    switch ((xcr0 & X86_XSTATE_ALL_MASK))
>      {
>      case X86_XSTATE_AVX_MPX_AVX512_PKU_MASK:
> @@ -708,10 +701,27 @@ i386_linux_core_read_description (struct gdbarch 
> *gdbarch,
>        break;
>      }
> 
> +  return NULL;
> +}

I was going to say: I think it would make more sense if 
i386_linux_read_description always returned something non-NULL, but then 
I realized you need to handle the special case in 
i386_linux_core_read_description...

> +
> +/* Get Linux/x86 target description from core dump.  */
> +
> +static const struct target_desc *
> +i386_linux_core_read_description (struct gdbarch *gdbarch,
> +				  struct target_ops *target,
> +				  bfd *abfd)
> +{
> +  /* Linux/i386.  */
> +  uint64_t xcr0 = i386_linux_core_read_xcr0 (abfd);
> +  const struct target_desc * tdesc = i386_linux_read_description 
> (xcr0);

Extra space after *.

The logic seems OK to me.  It's not related to your patch, but I find a 
bit confusing that i386-linux has SSE, and in i386-mmx-linux, the mmx is 
there to denote the lack of sse.  I looks like Mark agrees with me :)

   https://sourceware.org/ml/gdb-patches/2010-04/msg00300.html

Simon

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 03/25] Class-fy tdesc_reg tdesc_type and tdesc_feature
  2017-06-12  8:42 ` [PATCH 03/25] Class-fy tdesc_reg tdesc_type and tdesc_feature Yao Qi
  2017-06-19 20:55   ` Simon Marchi
@ 2017-06-19 21:30   ` Simon Marchi
  2017-06-20 10:31     ` Yao Qi
  1 sibling, 1 reply; 82+ messages in thread
From: Simon Marchi @ 2017-06-19 21:30 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

On 2017-06-12 10:41, Yao Qi wrote:
> --- a/gdb/target-descriptions.c
> +++ b/gdb/target-descriptions.c
> @@ -48,6 +48,32 @@ DEF_VEC_O(property_s);
> 
>  typedef struct tdesc_reg
>  {
> +public:
> +  tdesc_reg (struct tdesc_feature *feature, const char *name_,
> +	     int regnum, int save_restore_, const char *group_,
> +	     int bitsize_, const char *type_)
> +    : name (xstrdup (name_)), target_regnum (regnum),
> +      save_restore (save_restore_),
> +      group (group_ ? xstrdup (group_) : NULL),
> +      bitsize (bitsize_),
> +      type (type_ ? xstrdup (type_) : xstrdup ("<unknown>"))

Oh, I forgot to mention: you could take this opportunity to make these 
expression respect our coding style (use != NULL to check for NULL 
pointer).

Simon

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 02/25] Adjust the order of 32bit-linux.xml and  32bit-sse.xml in i386/i386-linux.xml
  2017-06-19 21:24     ` Pedro Alves
@ 2017-06-19 21:48       ` Simon Marchi
  2017-06-19 21:56         ` Pedro Alves
  0 siblings, 1 reply; 82+ messages in thread
From: Simon Marchi @ 2017-06-19 21:48 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Yao Qi, gdb-patches

On 2017-06-19 23:24, Pedro Alves wrote:
> Unless this is a case of a default target description matching
> the layout of targets that predated support for XML descriptions.
> 
> Could that be the case here?  From:
> 
> static void
> i386_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
> {
> ...
>   if (! tdesc_has_registers (tdesc))
>     tdesc = tdesc_i386_linux;
> ...
> 
> ... it may well be.  So we need to tread carefully here.  The
> order may be required for back compatibility.  A deeper audit
> with that in mind is in order.
> 
> Thanks,
> Pedro Alves

Do you mean that this might impact backward compatibility with older 
gdbservers (or other remotes) that don't send XML target descriptions 
and just assume a certain "well-known" register numbering?

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 02/25] Adjust the order of 32bit-linux.xml and 32bit-sse.xml in i386/i386-linux.xml
  2017-06-19 21:48       ` Simon Marchi
@ 2017-06-19 21:56         ` Pedro Alves
  2017-06-20  9:20           ` Yao Qi
  0 siblings, 1 reply; 82+ messages in thread
From: Pedro Alves @ 2017-06-19 21:56 UTC (permalink / raw)
  To: Simon Marchi; +Cc: Yao Qi, gdb-patches


On 06/19/2017 10:48 PM, Simon Marchi wrote:
> On 2017-06-19 23:24, Pedro Alves wrote:
>> Unless this is a case of a default target description matching
>> the layout of targets that predated support for XML descriptions.
>>
>> Could that be the case here?  From:
>>
>> static void
>> i386_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>> {
>> ...
>>   if (! tdesc_has_registers (tdesc))
>>     tdesc = tdesc_i386_linux;
>> ...
>>
>> ... it may well be.  So we need to tread carefully here.  The
>> order may be required for back compatibility.  A deeper audit
>> with that in mind is in order.

> Do you mean that this might impact backward compatibility with older
> gdbservers (or other remotes) that don't send XML target descriptions
> and just assume a certain "well-known" register numbering?

Yes.

It may be easy to check against gdbserver.  You'd need to hack it to
disable the x86 xml tdesc support, which is a relatively
recent addition.  [It took a while for the x86 port to support xml
tdescs].  The xmlRegisters= qSupported feature had to invented to
keep backward compatibility back then.

E.g., hack gdb's remote.c:register_remote_support_xml, or
gdbserver's linux-x86-low.c:x86_linux_process_qsupported.
If, with x86 XML support disabled, before vs after patch the
layout of GDB's g/G packet buffer changes, then you have
a back compatibility break.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 02/25] Adjust the order of 32bit-linux.xml and 32bit-sse.xml in i386/i386-linux.xml
  2017-06-19 21:56         ` Pedro Alves
@ 2017-06-20  9:20           ` Yao Qi
  2017-06-20 10:12             ` Pedro Alves
  0 siblings, 1 reply; 82+ messages in thread
From: Yao Qi @ 2017-06-20  9:20 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Simon Marchi, gdb-patches

Pedro Alves <palves@redhat.com> writes:

This patch doesn't change the registers layout in gdbserver, because
gdb/regformats/i386/i386-linux.dat isn't affected by this patch.  It
determines the register layout for i386-linux, in which "orig_eax" is
already put the end of list, thanks to sort-regs.xsl.

This patch only changes the order of iterating features and registers in
GDB, however, the order doesn't matter.

> It may be easy to check against gdbserver.  You'd need to hack it to
> disable the x86 xml tdesc support, which is a relatively
> recent addition.  [It took a while for the x86 port to support xml
> tdescs].  The xmlRegisters= qSupported feature had to invented to
> keep backward compatibility back then.
>
> E.g., hack gdb's remote.c:register_remote_support_xml, or
> gdbserver's linux-x86-low.c:x86_linux_process_qsupported.
> If, with x86 XML support disabled, before vs after patch the
> layout of GDB's g/G packet buffer changes, then you have
> a back compatibility break.

I hacked remote.c:register_remote_support_xml like this,

--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -4711,6 +4711,7 @@ void
 register_remote_support_xml (const char *xml)
 {
 #if defined(HAVE_LIBEXPAT)
+#if 0
   if (remote_support_xml == NULL)
     remote_support_xml = concat ("xmlRegisters=", xml, (char *) NULL);
   else
@@ -4735,6 +4736,7 @@ register_remote_support_xml (const char *xml)
                                     (char *) NULL);
     }
 #endif
+#endif
 }
 
 static char *
---

so GDB doesn't send qSupported:xmlRegisters=i386, and as a result,
GDBserver doesn't reply GDB about the target description registers,

Sending packet: $qXfer:features:read:target.xml:0,fff#7d...Packet received: l<target><architecture>i386</architecture><osabi>GNU/Linux</osabi></target>

The GDB's understanding to g/G packet layout is not changed, verified by
"maintenance print remote-registers",

(gdb) maintenance print remote-registers 
 Name         Nr  Rel Offset    Size  Type            Rmt Nr  g/G Offset
 eax           0    0      0       4 int32_t               0           0
 ecx           1    1      4       4 int32_t               1           4
 edx           2    2      8       4 int32_t               2           8
 ebx           3    3     12       4 int32_t               3          12
 esp           4    4     16       4 *1                    4          16
 ebp           5    5     20       4 *1                    5          20
 esi           6    6     24       4 int32_t               6          24
 edi           7    7     28       4 int32_t               7          28
 eip           8    8     32       4 *1                    8          32
 eflags        9    9     36       4 i386_eflags           9          36
 cs           10   10     40       4 int32_t              10          40
 ss           11   11     44       4 int32_t              11          44
 ds           12   12     48       4 int32_t              12          48
 es           13   13     52       4 int32_t              13          52
 fs           14   14     56       4 int32_t              14          56
 gs           15   15     60       4 int32_t              15          60
 st0          16   16     64      10 _i387_ext            16          64
 st1          17   17     74      10 _i387_ext            17          74
 st2          18   18     84      10 _i387_ext            18          84
 st3          19   19     94      10 _i387_ext            19          94
 st4          20   20    104      10 _i387_ext            20         104
 st5          21   21    114      10 _i387_ext            21         114
 st6          22   22    124      10 _i387_ext            22         124
 st7          23   23    134      10 _i387_ext            23         134
 fctrl        24   24    144       4 long                 24         144
 fstat        25   25    148       4 long                 25         148
 ftag         26   26    152       4 long                 26         152
 fiseg        27   27    156       4 long                 27         156
 fioff        28   28    160       4 long                 28         160
 foseg        29   29    164       4 long                 29         164
 fooff        30   30    168       4 long                 30         168
 fop          31   31    172       4 long                 31         172
 xmm0         32   32    176      16 vec128               32         176
 xmm1         33   33    192      16 vec128               33         192
 xmm2         34   34    208      16 vec128               34         208
 xmm3         35   35    224      16 vec128               35         224
 xmm4         36   36    240      16 vec128               36         240
 xmm5         37   37    256      16 vec128               37         256
 xmm6         38   38    272      16 vec128               38         272
 xmm7         39   39    288      16 vec128               39         288
 mxcsr        40   40    304       4 i386_mxcsr           40         304
 ''           41   41    308       0 int0_t          
 ''           42   42    308       0 int0_t          
 ''           43   43    308       0 int0_t          
 ''           44   44    308       0 int0_t          
 ''           45   45    308       0 int0_t          
 ''           46   46    308       0 int0_t          
 ''           47   47    308       0 int0_t          
 ''           48   48    308       0 int0_t          
 ''           49   49    308       0 int0_t          
 ''           50   50    308       0 int0_t          
 ''           51   51    308       0 int0_t          
 ''           52   52    308       0 int0_t          
 ''           53   53    308       0 int0_t          
 ''           54   54    308       0 int0_t          
 ''           55   55    308       0 int0_t          
 ''           56   56    308       0 int0_t          
 ''           57   57    308       0 int0_t          
 ''           58   58    308       0 int0_t          
 ''           59   59    308       0 int0_t          
 ''           60   60    308       0 int0_t          
 ''           61   61    308       0 int0_t          
 ''           62   62    308       0 int0_t          
 ''           63   63    308       0 int0_t          
 ''           64   64    308       0 int0_t          
 ''           65   65    308       0 int0_t          
 ''           66   66    308       0 int0_t          
 ''           67   67    308       0 int0_t          
 ''           68   68    308       0 int0_t          
 ''           69   69    308       0 int0_t          
 ''           70   70    308       0 int0_t          
 ''           71   71    308       0 int0_t          
 orig_eax     72   72    308       4 long                 41         308
 al           73    0    312       1 int8_t          
 cl           74    1    313       1 int8_t          
 dl           75    2    314       1 int8_t          
 bl           76    3    315       1 int8_t          
 ah           77    4    316       1 int8_t          
 ch           78    5    317       1 int8_t          
 dh           79    6    318       1 int8_t          
 bh           80    7    319       1 int8_t          
 ax           81    8    320       2 int16_t         
 cx           82    9    322       2 int16_t         
 dx           83   10    324       2 int16_t         
 bx           84   11    326       2 int16_t         
 ''           85   12    328       2 int16_t         
 bp           86   13    330       2 int16_t         
 si           87   14    332       2 int16_t         
 di           88   15    334       2 int16_t         
 mm0          89   16    336       8 _vec64i         
 mm1          90   17    344       8 _vec64i         
 mm2          91   18    352       8 _vec64i         
 mm3          92   19    360       8 _vec64i         
 mm4          93   20    368       8 _vec64i         
 mm5          94   21    376       8 _vec64i         
 mm6          95   22    384       8 _vec64i         
 mm7          96   23    392       8 _vec64i

however, I can't verify that GDBserver's understanding to g/G packet
layout is not changed, unless we write a unit test, but as I analyzed
above, the layout in GDBserver side doesn't change.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 02/25] Adjust the order of 32bit-linux.xml and 32bit-sse.xml in i386/i386-linux.xml
  2017-06-20  9:20           ` Yao Qi
@ 2017-06-20 10:12             ` Pedro Alves
  2017-06-20 11:09               ` Yao Qi
  0 siblings, 1 reply; 82+ messages in thread
From: Pedro Alves @ 2017-06-20 10:12 UTC (permalink / raw)
  To: Yao Qi; +Cc: Simon Marchi, gdb-patches

On 06/20/2017 10:20 AM, Yao Qi wrote:
> This patch doesn't change the registers layout in gdbserver, because
> gdb/regformats/i386/i386-linux.dat isn't affected by this patch.  

...

> It
> determines the register layout for i386-linux, in which "orig_eax" is
> already put the end of list, thanks to sort-regs.xsl.

Ok, that's for gdbserver, while I was worrying more about gdb, but
it's a good hint.  The feature xml files hardcode register numbers,
and the move ends up being a nop.  Good.

> 
> This patch only changes the order of iterating features and registers in
> GDB, however, the order doesn't matter.
> 

> The GDB's understanding to g/G packet layout is not changed, verified by
> "maintenance print remote-registers",

Great, thanks for confirming.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 03/25] Class-fy tdesc_reg tdesc_type and tdesc_feature
  2017-06-19 21:30   ` Simon Marchi
@ 2017-06-20 10:31     ` Yao Qi
  0 siblings, 0 replies; 82+ messages in thread
From: Yao Qi @ 2017-06-20 10:31 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

Simon Marchi <simon.marchi@polymtl.ca> writes:

> Oh, I forgot to mention: you could take this opportunity to make these
> expression respect our coding style (use != NULL to check for NULL
> pointer).

Thanks for the review.  They are fixed.  Patch below is pushed in.

-- 
Yao (齐尧)
From 72ddacb77e3301a0481003a23b2d8dced7116de5 Mon Sep 17 00:00:00 2001
From: Yao Qi <yao.qi@linaro.org>
Date: Tue, 20 Jun 2017 11:29:17 +0100
Subject: [PATCH] Class-fy tdesc_reg tdesc_type and tdesc_feature

This patch class-fies them, adding ctor, dtor, and deleting
copy ctor and assignment operator.

gdb:

2017-06-20  Yao Qi  <yao.qi@linaro.org>

	* target-descriptions.c (tdesc_reg): Add ctor, dtor.
	Delete copy ctor and assignment operator.
	(tdesc_type): Likewise.
	(tdesc_feature): Likewise.
	(tdesc_free_reg): Remove.
	(tdesc_create_reg): Use new.
	(tdesc_free_type): Remove.
	(tdesc_create_vector): Use new.
	(tdesc_create_union): Likewise.
	(tdesc_create_flags): Likewise.
	(tdesc_create_enum): Likewise.
	(tdesc_free_feature): Delete.
	(free_target_description): Use delete.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 4e091d7..c1998bb 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,19 @@
+2017-06-20  Yao Qi  <yao.qi@linaro.org>
+
+	* target-descriptions.c (tdesc_reg): Add ctor, dtor.
+	Delete copy ctor and assignment operator.
+	(tdesc_type): Likewise.
+	(tdesc_feature): Likewise.
+	(tdesc_free_reg): Remove.
+	(tdesc_create_reg): Use new.
+	(tdesc_free_type): Remove.
+	(tdesc_create_vector): Use new.
+	(tdesc_create_union): Likewise.
+	(tdesc_create_flags): Likewise.
+	(tdesc_create_enum): Likewise.
+	(tdesc_free_feature): Delete.
+	(free_target_description): Use delete.
+
 2017-06-19  John Baldwin  <jhb@FreeBSD.org>
 
 	* mips-tdep.c (print_gp_register_row): Don't error for unavailable
diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
index 9a7e2dd..0b5b46f 100644
--- a/gdb/target-descriptions.c
+++ b/gdb/target-descriptions.c
@@ -48,6 +48,31 @@ DEF_VEC_O(property_s);
 
 typedef struct tdesc_reg
 {
+  tdesc_reg (struct tdesc_feature *feature, const char *name_,
+	     int regnum, int save_restore_, const char *group_,
+	     int bitsize_, const char *type_)
+    : name (xstrdup (name_)), target_regnum (regnum),
+      save_restore (save_restore_),
+      group (group_ != NULL ? xstrdup (group_) : NULL),
+      bitsize (bitsize_),
+      type (type_ != NULL ? xstrdup (type_) : xstrdup ("<unknown>"))
+  {
+    /* If the register's type is target-defined, look it up now.  We may not
+       have easy access to the containing feature when we want it later.  */
+    tdesc_type = tdesc_named_type (feature, type);
+  }
+
+  ~tdesc_reg ()
+  {
+    xfree (name);
+    xfree (type);
+    xfree (group);
+  }
+
+  /* Disable copying.  */
+  tdesc_reg (const tdesc_reg &) = delete;
+  tdesc_reg &operator= (const tdesc_reg &) = delete;
+
   /* The name of this register.  In standard features, it may be
      recognized by the architecture support code, or it may be purely
      for the user.  */
@@ -128,6 +153,42 @@ enum tdesc_type_kind
 
 typedef struct tdesc_type
 {
+  tdesc_type (const char *name_, enum tdesc_type_kind kind_)
+    : name (xstrdup (name_)), kind (kind_)
+  {
+    memset (&u, 0, sizeof (u));
+  }
+
+  ~tdesc_type ()
+  {
+    switch (kind)
+      {
+      case TDESC_TYPE_STRUCT:
+      case TDESC_TYPE_UNION:
+      case TDESC_TYPE_FLAGS:
+      case TDESC_TYPE_ENUM:
+	{
+	  struct tdesc_type_field *f;
+	  int ix;
+
+	  for (ix = 0;
+	       VEC_iterate (tdesc_type_field, u.u.fields, ix, f);
+	       ix++)
+	    xfree (f->name);
+
+	  VEC_free (tdesc_type_field, u.u.fields);
+	}
+	break;
+
+      default:
+	break;
+      }
+    xfree ((char *) name);
+  }
+  /* Disable copying.  */
+  tdesc_type (const tdesc_type &) = delete;
+  tdesc_type &operator= (const tdesc_type &) = delete;
+
   /* The name of this type.  If this type is a built-in type, this is
      a pointer to a constant string.  Otherwise, it's a
      malloc-allocated string (and thus must be freed).  */
@@ -161,15 +222,40 @@ DEF_VEC_P(tdesc_type_p);
 
 typedef struct tdesc_feature
 {
+  tdesc_feature (const char *name_)
+    : name (xstrdup (name_))
+  {}
+
+  ~tdesc_feature ()
+  {
+    struct tdesc_reg *reg;
+    struct tdesc_type *type;
+    int ix;
+
+    for (ix = 0; VEC_iterate (tdesc_reg_p, registers, ix, reg); ix++)
+      delete reg;
+    VEC_free (tdesc_reg_p, registers);
+
+    for (ix = 0; VEC_iterate (tdesc_type_p, types, ix, type); ix++)
+      delete type;
+    VEC_free (tdesc_type_p, types);
+
+    xfree (name);
+  }
+
+  /* Disable copying.  */
+  tdesc_feature (const tdesc_feature &) = delete;
+  tdesc_feature &operator= (const tdesc_feature &) = delete;
+
   /* The name of this feature.  It may be recognized by the architecture
      support code.  */
   char *name;
 
   /* The registers associated with this feature.  */
-  VEC(tdesc_reg_p) *registers;
+  VEC(tdesc_reg_p) *registers = NULL;
 
   /* The types associated with this feature.  */
-  VEC(tdesc_type_p) *types;
+  VEC(tdesc_type_p) *types = NULL;
 } *tdesc_feature_p;
 DEF_VEC_P(tdesc_feature_p);
 
@@ -1274,81 +1360,23 @@ tdesc_use_registers (struct gdbarch *gdbarch,
 }
 \f
 
-/* Methods for constructing a target description.  */
-
-static void
-tdesc_free_reg (struct tdesc_reg *reg)
-{
-  xfree (reg->name);
-  xfree (reg->type);
-  xfree (reg->group);
-  xfree (reg);
-}
-
 void
 tdesc_create_reg (struct tdesc_feature *feature, const char *name,
 		  int regnum, int save_restore, const char *group,
 		  int bitsize, const char *type)
 {
-  struct tdesc_reg *reg = XCNEW (struct tdesc_reg);
-
-  reg->name = xstrdup (name);
-  reg->target_regnum = regnum;
-  reg->save_restore = save_restore;
-  reg->group = group ? xstrdup (group) : NULL;
-  reg->bitsize = bitsize;
-  reg->type = type ? xstrdup (type) : xstrdup ("<unknown>");
-
-  /* If the register's type is target-defined, look it up now.  We may not
-     have easy access to the containing feature when we want it later.  */
-  reg->tdesc_type = tdesc_named_type (feature, reg->type);
+  tdesc_reg *reg = new tdesc_reg (feature, name, regnum, save_restore,
+				  group, bitsize, type);
 
   VEC_safe_push (tdesc_reg_p, feature->registers, reg);
 }
 
-/* Subroutine of tdesc_free_feature to simplify it.
-   Note: We do not want to free any referenced types here (e.g., types of
-   fields of a struct).  All types of a feature are recorded in
-   feature->types and are freed that way.  */
-
-static void
-tdesc_free_type (struct tdesc_type *type)
-{
-  switch (type->kind)
-    {
-    case TDESC_TYPE_STRUCT:
-    case TDESC_TYPE_UNION:
-    case TDESC_TYPE_FLAGS:
-    case TDESC_TYPE_ENUM:
-      {
-	struct tdesc_type_field *f;
-	int ix;
-
-	for (ix = 0;
-	     VEC_iterate (tdesc_type_field, type->u.u.fields, ix, f);
-	     ix++)
-	  xfree (f->name);
-
-	VEC_free (tdesc_type_field, type->u.u.fields);
-      }
-      break;
-
-    default:
-      break;
-    }
-
-  xfree ((char *) type->name);
-  xfree (type);
-}
-
 struct tdesc_type *
 tdesc_create_vector (struct tdesc_feature *feature, const char *name,
 		     struct tdesc_type *field_type, int count)
 {
-  struct tdesc_type *type = XCNEW (struct tdesc_type);
+  struct tdesc_type *type = new tdesc_type (name, TDESC_TYPE_VECTOR);
 
-  type->name = xstrdup (name);
-  type->kind = TDESC_TYPE_VECTOR;
   type->u.v.type = field_type;
   type->u.v.count = count;
 
@@ -1359,10 +1387,7 @@ tdesc_create_vector (struct tdesc_feature *feature, const char *name,
 struct tdesc_type *
 tdesc_create_struct (struct tdesc_feature *feature, const char *name)
 {
-  struct tdesc_type *type = XCNEW (struct tdesc_type);
-
-  type->name = xstrdup (name);
-  type->kind = TDESC_TYPE_STRUCT;
+  struct tdesc_type *type = new tdesc_type (name, TDESC_TYPE_STRUCT);
 
   VEC_safe_push (tdesc_type_p, feature->types, type);
   return type;
@@ -1383,10 +1408,7 @@ tdesc_set_struct_size (struct tdesc_type *type, int size)
 struct tdesc_type *
 tdesc_create_union (struct tdesc_feature *feature, const char *name)
 {
-  struct tdesc_type *type = XCNEW (struct tdesc_type);
-
-  type->name = xstrdup (name);
-  type->kind = TDESC_TYPE_UNION;
+  struct tdesc_type *type = new tdesc_type (name, TDESC_TYPE_UNION);
 
   VEC_safe_push (tdesc_type_p, feature->types, type);
   return type;
@@ -1396,12 +1418,10 @@ struct tdesc_type *
 tdesc_create_flags (struct tdesc_feature *feature, const char *name,
 		    int size)
 {
-  struct tdesc_type *type = XCNEW (struct tdesc_type);
+  struct tdesc_type *type = new tdesc_type (name, TDESC_TYPE_FLAGS);
 
   gdb_assert (size > 0);
 
-  type->name = xstrdup (name);
-  type->kind = TDESC_TYPE_FLAGS;
   type->u.u.size = size;
 
   VEC_safe_push (tdesc_type_p, feature->types, type);
@@ -1412,12 +1432,10 @@ struct tdesc_type *
 tdesc_create_enum (struct tdesc_feature *feature, const char *name,
 		   int size)
 {
-  struct tdesc_type *type = XCNEW (struct tdesc_type);
+  struct tdesc_type *type = new tdesc_type (name, TDESC_TYPE_ENUM);
 
   gdb_assert (size > 0);
 
-  type->name = xstrdup (name);
-  type->kind = TDESC_TYPE_ENUM;
   type->u.u.size = size;
 
   VEC_safe_push (tdesc_type_p, feature->types, type);
@@ -1521,31 +1539,10 @@ tdesc_add_enum_value (struct tdesc_type *type, int value,
   VEC_safe_push (tdesc_type_field, type->u.u.fields, &f);
 }
 
-static void
-tdesc_free_feature (struct tdesc_feature *feature)
-{
-  struct tdesc_reg *reg;
-  struct tdesc_type *type;
-  int ix;
-
-  for (ix = 0; VEC_iterate (tdesc_reg_p, feature->registers, ix, reg); ix++)
-    tdesc_free_reg (reg);
-  VEC_free (tdesc_reg_p, feature->registers);
-
-  for (ix = 0; VEC_iterate (tdesc_type_p, feature->types, ix, type); ix++)
-    tdesc_free_type (type);
-  VEC_free (tdesc_type_p, feature->types);
-
-  xfree (feature->name);
-  xfree (feature);
-}
-
 struct tdesc_feature *
 tdesc_create_feature (struct target_desc *tdesc, const char *name)
 {
-  struct tdesc_feature *new_feature = XCNEW (struct tdesc_feature);
-
-  new_feature->name = xstrdup (name);
+  struct tdesc_feature *new_feature = new tdesc_feature (name);
 
   VEC_safe_push (tdesc_feature_p, tdesc->features, new_feature);
   return new_feature;
@@ -1568,7 +1565,7 @@ free_target_description (void *arg)
   for (ix = 0;
        VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature);
        ix++)
-    tdesc_free_feature (feature);
+    delete feature;
   VEC_free (tdesc_feature_p, target_desc->features);
 
   for (ix = 0;

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 06/25] Generate c for feature instead of tdesc
  2017-06-12  8:42 ` [PATCH 06/25] Generate c for feature instead of tdesc Yao Qi
  2017-06-12 14:48   ` Eli Zaretskii
@ 2017-06-20 10:59   ` Pedro Alves
  2017-06-22 14:49     ` Yao Qi
  2017-06-26 21:38   ` Simon Marchi
  2 siblings, 1 reply; 82+ messages in thread
From: Pedro Alves @ 2017-06-20 10:59 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

(this is not a full review)

On 06/12/2017 09:41 AM, Yao Qi wrote:
> +$(FEATURE_CFILES): %.c: %.xml.tmp
> +	$(GDB) -nx -q -batch \
> +	  -ex 'maint print c-tdesc $<' > $@.tmp
> +	sh ../../move-if-change $@.tmp $@
> +	rm $<
> +
> +%.xml.tmp: %.xml
> +	echo "<?xml version=\"1.0\"?>" > $@
> +	echo "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">" >> $@
> +	echo "<target>" >> $@
> +	echo "  <architecture>" >> $@
> +	if test $(findstring i386/32bit-,$@); then echo "i386" >> $@ ; fi;
> +	echo "  </architecture>" >> $@
> +	echo "  <xi:include href=\"$(notdir $<)\"/>" >> $@
> +	echo "</target>" >> $@
> +

Don't we need move-if-change here?

The findstring bits warrants a comment.

> +/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
> +  Original: 32bit-avx512.xml.tmp */

I don't think we should be pointing "Original" at a 
temporary file that does not exist in the repo?

On 06/12/2017 09:41 AM, Yao Qi wrote:
> -  print_c_tdesc v (filename_after_features);
> +  if (strncmp (filename_after_features.c_str(), "i386/32bit-", 11) == 0)

startswith

But again, this looks like needs at least a comment.  I'd
like to see an expanded rationale for this.  It's not
immediately obvious why/what's this special casing for.

> +    {
> +      print_c_feature v (filename_after_features);
> +
> +      tdesc->accept (v);
> +    }
> +  else
> +    {
> +      print_c_tdesc v (filename_after_features);
>  
> -  tdesc->accept (v);
> +      tdesc->accept (v);
> +    }


Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 07/25] Lazily and dynamically create i386-linux target descriptions
  2017-06-12  8:42 ` [PATCH 07/25] Lazily and dynamically create i386-linux target descriptions Yao Qi
@ 2017-06-20 11:01   ` Pedro Alves
  2017-06-20 14:07     ` Yao Qi
  0 siblings, 1 reply; 82+ messages in thread
From: Pedro Alves @ 2017-06-20 11:01 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

On 06/12/2017 09:41 AM, Yao Qi wrote:
> Instead of using pre-generated target descriptions, this patch
> changes GDB to lazily and dynamically create target descriptions
> according to the target hardware capability (xcr0 in i386).
> This support any combination of target features.
> 
> This patch also adds a unit test to make sure dynamically generated
> tdesc are identical to these generated from xml files.

I don't see the unit test in the patch.

Can you say something about the "regnum = %ld" change?  Is it
related to the rest of the patch?

> 
> 2017-04-27  Yao Qi  <yao.qi@linaro.org>
> 
> 	* i386-linux-tdep.c (i386_linux_read_description): Generate
> 	target description if it doesn't exist.
>         [GDB_SELF_TEST] (i386_linux_read_description_test): New unit test.
>         (_initialize_i386_linux_tdep) [GDB_SELF_TEST]: Register unit test.

Leading TAB vs spaces.

> +private:
> +  /* The register number to use for the next register we see.  */
> +  int next_regnum = 0;
>  };

"m_" prefix.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 00/25 V2] Make GDB builtin target descriptions more  flexible
  2017-06-19 19:59 ` [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Simon Marchi
@ 2017-06-20 11:02   ` Yao Qi
  2017-06-26 14:45   ` Tedeschi, Walfred
  1 sibling, 0 replies; 82+ messages in thread
From: Yao Qi @ 2017-06-20 11:02 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

Simon Marchi <simon.marchi@polymtl.ca> writes:

> Do you have a git branch we can pull from to look at this change?

I just create a branch, users/qiyao/target-desc-2

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 10/25] Adjust code generated by regformats/regdat.sh
  2017-06-12  8:42 ` [PATCH 10/25] Adjust code generated by regformats/regdat.sh Yao Qi
@ 2017-06-20 11:09   ` Pedro Alves
  2017-06-21 14:28     ` Yao Qi
  0 siblings, 1 reply; 82+ messages in thread
From: Pedro Alves @ 2017-06-20 11:09 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

On 06/12/2017 09:41 AM, Yao Qi wrote:
> regformats/regdat.sh generate some *-generated.c files when GDBserver
> is built.  Each .c file has some static variables, which are only used
> within function init_registers_XXX, like this,
> 
> static struct reg regs_i386_linux[] = {
>   { "eax", 0, 32 },
>   { "ecx", 32, 32 },
>   ...
> };
> 
> static const char *expedite_regs_i386_linux[] = { "ebp", "esp", "eip", 0 };
> static const char *xmltarget_i386_linux = "i386-linux.xml";
> 
> void
> init_registers_i386_linux (void)
> {
>   ...
> }
> 
> This patch moves these static variables' definitions to function
> init_registers_XXX, so the generated files look like this,
> 

The rationale misses stating why is this better than the status quo.
I presume this helps following patches?

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 02/25] Adjust the order of 32bit-linux.xml and 32bit-sse.xml in i386/i386-linux.xml
  2017-06-20 10:12             ` Pedro Alves
@ 2017-06-20 11:09               ` Yao Qi
  0 siblings, 0 replies; 82+ messages in thread
From: Yao Qi @ 2017-06-20 11:09 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Simon Marchi, gdb-patches

Pedro Alves <palves@redhat.com> writes:

> Ok, that's for gdbserver, while I was worrying more about gdb, but
> it's a good hint.  The feature xml files hardcode register numbers,
> and the move ends up being a nop.  Good.
>
>> 
>> This patch only changes the order of iterating features and registers in
>> GDB, however, the order doesn't matter.
>> 
>
>> The GDB's understanding to g/G packet layout is not changed, verified by
>> "maintenance print remote-registers",
>
> Great, thanks for confirming.

I pushed the patch in.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 07/25] Lazily and dynamically create i386-linux target descriptions
  2017-06-20 11:01   ` Pedro Alves
@ 2017-06-20 14:07     ` Yao Qi
  2017-06-28 15:30       ` Pedro Alves
  0 siblings, 1 reply; 82+ messages in thread
From: Yao Qi @ 2017-06-20 14:07 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

Pedro Alves <palves@redhat.com> writes:

> I don't see the unit test in the patch.
>

It is moved to patch 08/25.

> Can you say something about the "regnum = %ld" change?  Is it
> related to the rest of the patch?
>

Without this change, the lazily generated tdesc doesn't equal to the
original pre-generated tdesc if the register has regnum attribute, like

  <reg name="xmm0" bitsize="128" type="vec128" regnum="32"/>

most of the reg doesn't have "regnum" attribute so the number is
allocated sequentially.  If the reg has "regnum", it explicitly set the
register number.  I'll rewrite the commit log this way,

Instead of using pre-generated target descriptions, this patch
changes GDB to lazily and dynamically create target descriptions
according to the target hardware capability (xcr0 in i386).
This support any combination of target features.

Some reg in XML target description has attribute "regnum" which set the
register number explicitly rather than using the sequentially allocated
number,

  <reg name="xmm0" bitsize="128" type="vec128" regnum="32"/>

In order to handle this, this patch also changes the visitor to print
the code to set regnum when reg has attribute "regnum".

2017-06-20  Yao Qi  <yao.qi@linaro.org>

	* i386-linux-tdep.c: Don't include features/i386/i386-XXX-linux.c.
        include features/i386/32bit-XXX.c instead.
        (i386_linux_read_description): Generate
        target description if it doesn't exist.
        * target-descriptions.c (print_c_tdesc::visit): Print code to
        set regnum.
        (print_c_tdesc) <m_next_regnum>: New field.
        * features/i386/32bit-linux.c: Regenerated.
        * features/i386/32bit-sse.c: Regenerated.

>> 
>> 2017-04-27  Yao Qi  <yao.qi@linaro.org>
>> 
>> 	* i386-linux-tdep.c (i386_linux_read_description): Generate
>> 	target description if it doesn't exist.
>>         [GDB_SELF_TEST] (i386_linux_read_description_test): New unit test.
>>         (_initialize_i386_linux_tdep) [GDB_SELF_TEST]: Register unit test.
>
> Leading TAB vs spaces.
>

These two lines should be removed.

>> +private:
>> +  /* The register number to use for the next register we see.  */
>> +  int next_regnum = 0;
>>  };
>
> "m_" prefix.

I'll fix it.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 05/25] Use visitor pattern for "maint print c-tdesc"
  2017-06-12  8:42 ` [PATCH 05/25] Use visitor pattern for "maint print c-tdesc" Yao Qi
@ 2017-06-20 23:37   ` Simon Marchi
  0 siblings, 0 replies; 82+ messages in thread
From: Simon Marchi @ 2017-06-20 23:37 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

On 2017-06-12 10:41, Yao Qi wrote:
> diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
> index e2dcd1d..ac19792 100644
> --- a/gdb/target-descriptions.c
> +++ b/gdb/target-descriptions.c
> @@ -35,6 +35,23 @@
>  #include "hashtab.h"
>  #include "inferior.h"
> 
> +class tdesc_element_visitor
> +{
> +public:
> +  virtual void visit (const target_desc *e) = 0;
> +  virtual void visit_end (const target_desc *e) = 0;

For elements which children, and therefore can be visited before and 
after their children, I'd suggest using "visit_pre" and "visit_post" for 
the methods names.  It relates better to the terms pre-order and 
post-order.

> @@ -259,6 +287,30 @@ public:
> 
>    /* The types associated with this feature.  */
>    VEC(tdesc_type_p) *types = NULL;
> +
> +  void accept (tdesc_element_visitor &v) const override
> +  {
> +    v.visit (this);
> +
> +    struct tdesc_type *type;
> +
> +    for (int ix = 0;
> +	 VEC_iterate (tdesc_type_p, types, ix, type);
> +	 ix++)
> +      {
> +	type->accept (v);
> +      }

No need for braces here (and for all the ->accept calls in for loops).

> +
> +    struct tdesc_reg *reg;
> +
> +    for (int ix = 0;
> +	 VEC_iterate (tdesc_reg_p, registers, ix, reg);
> +	 ix++)
> +      {
> +	reg->accept (v);
> +      }
> +  }
> +
>  } *tdesc_feature_p;
>  DEF_VEC_P(tdesc_feature_p);
> 
> @@ -268,23 +320,67 @@ DEF_VEC_P(arch_p);
> 
>  /* A target description.  */
> 
> -struct target_desc
> +struct target_desc : tdesc_element
>  {

It's not a big deal, but the C++ification of target_desc would have 
fitted better in patch 03/25 I guess.

> +public:

You can remove public:.

> @@ -1707,279 +1783,288 @@ unset_tdesc_filename_cmd (char *args, int 
> from_tty)
>    target_find_description ();
>  }
> 
> -static void
> -maint_print_c_tdesc_cmd (char *args, int from_tty)
> +class print_c_tdesc : public tdesc_element_visitor

IWBN to have "visitor" in the class name: print_c_tdesc_visitor.

>  {
> -  const struct target_desc *tdesc;
> -  const struct bfd_arch_info *compatible;
> -  const char *filename, *inp;
> -  char *function, *outp;
> -  struct property *prop;
> -  struct tdesc_feature *feature;
> -  struct tdesc_reg *reg;
> -  struct tdesc_type *type;
> -  struct tdesc_type_field *f;
> -  int ix, ix2, ix3;
> -  int printed_field_type = 0;
> +public:
> +  print_c_tdesc (std::string &filename_after_features)
> +    : m_filename_after_features (filename_after_features)

Could you document the parameter filename_after_features?

I didn't read the whole visitor code (it's getting late here...), but I 
like the idea and the pattern.

Simon

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 10/25] Adjust code generated by regformats/regdat.sh
  2017-06-20 11:09   ` Pedro Alves
@ 2017-06-21 14:28     ` Yao Qi
  0 siblings, 0 replies; 82+ messages in thread
From: Yao Qi @ 2017-06-21 14:28 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

Pedro Alves <palves@redhat.com> writes:

> The rationale misses stating why is this better than the status quo.
> I presume this helps following patches?

Yes, it paves the way for patch 11.  I'll add it in the commit log.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 22/25] Regenerate two regformats/i386/.dat files
  2017-06-12  8:42 ` [PATCH 22/25] Regenerate two regformats/i386/.dat files Yao Qi
@ 2017-06-22 12:43   ` Yao Qi
  0 siblings, 0 replies; 82+ messages in thread
From: Yao Qi @ 2017-06-22 12:43 UTC (permalink / raw)
  To: gdb-patches; +Cc: walfred.tedeschi

Yao Qi <qiyaoltc@gmail.com> writes:

> The self tests which compare pre-generated target descriptions and dynamically
> created target descriptions fail, and it turns out that two pre-generated
> target descriptions are wrong, so regenerate them.
>
> gdb:
>
> 2017-06-09  Yao Qi  <yao.qi@linaro.org>
>
> 	* regformats/i386/amd64-avx-mpx-avx512-pku-linux.dat: Regenerated.
> 	* regformats/i386/amd64-avx-mpx-avx512-pku.dat: Regenerated.

I pushed it in.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 06/25] Generate c for feature instead of tdesc
  2017-06-20 10:59   ` Pedro Alves
@ 2017-06-22 14:49     ` Yao Qi
  2017-06-22 15:36       ` Pedro Alves
  0 siblings, 1 reply; 82+ messages in thread
From: Yao Qi @ 2017-06-22 14:49 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

Pedro Alves <palves@redhat.com> writes:

> On 06/12/2017 09:41 AM, Yao Qi wrote:
>> +$(FEATURE_CFILES): %.c: %.xml.tmp
>> +	$(GDB) -nx -q -batch \
>> +	  -ex 'maint print c-tdesc $<' > $@.tmp
>> +	sh ../../move-if-change $@.tmp $@
>> +	rm $<
>> +
>> +%.xml.tmp: %.xml
>> +	echo "<?xml version=\"1.0\"?>" > $@
>> +	echo "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">" >> $@
>> +	echo "<target>" >> $@
>> +	echo "  <architecture>" >> $@
>> +	if test $(findstring i386/32bit-,$@); then echo "i386" >> $@ ; fi;
>> +	echo "  </architecture>" >> $@
>> +	echo "  <xi:include href=\"$(notdir $<)\"/>" >> $@
>> +	echo "</target>" >> $@
>> +
>
> Don't we need move-if-change here?
>

move-if-change from what to what?  *.xml.tmp is removed after *.c is
generated.

> The findstring bits warrants a comment.
>

Yes, comment is needed.

>> +/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
>> +  Original: 32bit-avx512.xml.tmp */
>
> I don't think we should be pointing "Original" at a 
> temporary file that does not exist in the repo?

Fixed locally.

>
> On 06/12/2017 09:41 AM, Yao Qi wrote:
>> -  print_c_tdesc v (filename_after_features);
>> +  if (strncmp (filename_after_features.c_str(), "i386/32bit-", 11) == 0)
>
> startswith
>
> But again, this looks like needs at least a comment.  I'd
> like to see an expanded rationale for this.  It's not
> immediately obvious why/what's this special casing for.

OK.  Note that the special case and the findstring in Makefile are
needed during the target description transition.  Once we move all
targets to the flexible target description, we don't need them.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 06/25] Generate c for feature instead of tdesc
  2017-06-22 14:49     ` Yao Qi
@ 2017-06-22 15:36       ` Pedro Alves
  2017-06-22 15:58         ` Yao Qi
  0 siblings, 1 reply; 82+ messages in thread
From: Pedro Alves @ 2017-06-22 15:36 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches


On 06/22/2017 03:49 PM, Yao Qi wrote:
> Pedro Alves <palves@redhat.com> writes:
> 
>> > On 06/12/2017 09:41 AM, Yao Qi wrote:
>>> >> +$(FEATURE_CFILES): %.c: %.xml.tmp
>>> >> +	$(GDB) -nx -q -batch \
>>> >> +	  -ex 'maint print c-tdesc $<' > $@.tmp
>>> >> +	sh ../../move-if-change $@.tmp $@
>>> >> +	rm $<
>>> >> +
>>> >> +%.xml.tmp: %.xml
>>> >> +	echo "<?xml version=\"1.0\"?>" > $@
>>> >> +	echo "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">" >> $@
>>> >> +	echo "<target>" >> $@
>>> >> +	echo "  <architecture>" >> $@
>>> >> +	if test $(findstring i386/32bit-,$@); then echo "i386" >> $@ ; fi;
>>> >> +	echo "  </architecture>" >> $@
>>> >> +	echo "  <xi:include href=\"$(notdir $<)\"/>" >> $@
>>> >> +	echo "</target>" >> $@
>>> >> +
>> >
>> > Don't we need move-if-change here?
>> >
> move-if-change from what to what?  *.xml.tmp is removed after *.c is
> generated.

"*.xml.tmp.tmp" to "*.xml.tmp".  I.e., from $@.tmp to $@, just
like the rule further above.

I may be missing something, but AFAICS, the "%.xml.tmp: %.xml"
rule is writing to the target directly.  If the build
is interrupted in the middle of that rule, we end up with an
incomplete "%.xml.tmp" file left over in the file system.
Then the next time you invoke make, make will think that
the "%.xml.tmp" file is already up to date and won't rebuild it.
As a result, you'll pass a broken xml.tmp file to
"maint print c-tdesc".

Avoiding these issues is the whole point of move-if-change,
by atomically creating the target file.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 06/25] Generate c for feature instead of tdesc
  2017-06-22 15:36       ` Pedro Alves
@ 2017-06-22 15:58         ` Yao Qi
  0 siblings, 0 replies; 82+ messages in thread
From: Yao Qi @ 2017-06-22 15:58 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

Pedro Alves <palves@redhat.com> writes:

> "*.xml.tmp.tmp" to "*.xml.tmp".  I.e., from $@.tmp to $@, just
> like the rule further above.
>

Oh, I know what you mean.

> I may be missing something, but AFAICS, the "%.xml.tmp: %.xml"
> rule is writing to the target directly.  If the build
> is interrupted in the middle of that rule, we end up with an
> incomplete "%.xml.tmp" file left over in the file system.
> Then the next time you invoke make, make will think that
> the "%.xml.tmp" file is already up to date and won't rebuild it.
> As a result, you'll pass a broken xml.tmp file to
> "maint print c-tdesc".
>
> Avoiding these issues is the whole point of move-if-change,
> by atomically creating the target file.

move-if-change is needed here.  Let me add it.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 82+ messages in thread

* RE: [PATCH 00/25 V2] Make GDB builtin target descriptions more  flexible
  2017-06-19 19:59 ` [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Simon Marchi
  2017-06-20 11:02   ` Yao Qi
@ 2017-06-26 14:45   ` Tedeschi, Walfred
  2017-06-27 13:49     ` Alan Hayward
  2017-06-28  8:06     ` Yao Qi
  1 sibling, 2 replies; 82+ messages in thread
From: Tedeschi, Walfred @ 2017-06-26 14:45 UTC (permalink / raw)
  To: Simon Marchi, Yao Qi; +Cc: gdb-patches



-----Original Message-----
From: gdb-patches-owner@sourceware.org [mailto:gdb-patches-owner@sourceware.org] On Behalf Of Simon Marchi
Sent: Monday, June 19, 2017 9:00 PM
To: Yao Qi <qiyaoltc@gmail.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible

On 2017-06-12 10:41, Yao Qi wrote:
> This patch series is to change GDB and GDBserver builtin target 
> descriptions more flexible, by removing pre-generated ones.  Instead, 
> these builtin target descriptions can be got lazily and dynamically.
> GDB builtin target descriptions are created from initialize_tdesc_* 
> functions in features/*.c files, while GDBserver builtin target 
> descriptions are generated from regformats/*.dat files.
> 
> This patch series changes both GDB and GDBserver to create target 
> description dynamically from features, instead of using pre-generated 
> target descriptions.  This patch series only convert x86-linux ( 
> including i386-linux, amd64-linux and x32-linux) target description to 
> demonstrate the usefulness of the change.
> 
> Once one target architecture switches to the new flexible target 
> description,
> 
>  - only need xml feature files under gdb/features directory.  All  
> existing target description xml files can be kept for the tests.
>  Add new xml feature file if we want to support the new feature,  but 
> don't need to add new target description xml files.
> 
>  - All existing gdb/regformats/*.dat are not used, but kept for  the 
> tests.
> 
> This is the V2, and V1 is here
> https://sourceware.org/ml/gdb-patches/2017-05/msg00291.html,
> the differences are,
> 
>  - Change target descriptions for both GDB and GDBserver,
>  - Generate functions creating features from xml feature file
>    instead of feature name, so that don't have to worry about
>    different features with the same name (different features
>    with the same name still have different file names).
>  - Extend the changes for i386-linux to x86-linux (including,
>    {i386,amd64,x32}-linux)
> 
> The big design change in V2 is that use generate c files from xml 
> feature files, and use generate c files in both GDB and GDBserver.
> 
> In next step,  I want to remove the duplication of target descriptions 
> in GDB and GDBserver, and share more code on creating x86-linux target 
> descriptions in GDB and GDBserver.
> I also want people give comments on how to do unit/self tests in 
> GDBserver, see patch 14.  The purpose of this patch series is still to 
> demonstrate the design, so the changelog, NEWS entry, and doc may be 
> incomplete.  I'll complete them later.
> 
> Regression tested on x86_64-linux (both -m64 and -m32), native and 
> gdbserver, on aarch64-linux native and gdbserver.
> ppc64-linux, native.

Hi Yao,

Do you have a git branch we can pull from to look at this change?

Thanks,

Simon


Hello Yao,

I did some tests and they are looking fine for remote and native gdb.
I could tweak the XCR0 in GDB and GDBSERVER and see tests that also use cpu-id to detect features failing, as expected! Very nice!
Thanks again!

As an observation, in the gdbserver side there are calls to _get_ipa_tdesc. I suppose we could rename this to a more generic name.
About the design: GDBserver still uses the combination of cpu features to build the target description. 
                                     On the other hand, the improvement was huge, i.e. I would go to accept the patch and consider an additional patch series to address gdbserver tdesc creation. 

Best regards,
/Fred
  

Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Christian Lamprechter
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 06/25] Generate c for feature instead of tdesc
  2017-06-12  8:42 ` [PATCH 06/25] Generate c for feature instead of tdesc Yao Qi
  2017-06-12 14:48   ` Eli Zaretskii
  2017-06-20 10:59   ` Pedro Alves
@ 2017-06-26 21:38   ` Simon Marchi
  2017-06-29 15:24     ` Yao Qi
  2 siblings, 1 reply; 82+ messages in thread
From: Simon Marchi @ 2017-06-26 21:38 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

On 2017-06-12 10:41, Yao Qi wrote:
> diff --git a/gdb/features/Makefile b/gdb/features/Makefile
> index 3bc8b5a..28a7e20 100644
> --- a/gdb/features/Makefile
> +++ b/gdb/features/Makefile
> @@ -252,12 +252,39 @@ $(outdir)/%.dat: %.xml number-regs.xsl
> sort-regs.xsl gdbserver-regs.xsl
>  	  $(XSLTPROC) gdbserver-regs.xsl - >> $(outdir)/$*.tmp
>  	sh ../../move-if-change $(outdir)/$*.tmp $(outdir)/$*.dat
> 
> -cfiles: $(CFILES)
> -%.c: %.xml
> +FEATURE_XMLFILES = i386/32bit-core.xml \
> +	i386/32bit-sse.xml \
> +	i386/32bit-linux.xml \
> +	i386/32bit-avx.xml \
> +	i386/32bit-mpx.xml \
> +	i386/32bit-avx512.xml \
> +	i386/32bit-pkeys.xml
> +
> +FEATURE_CFILES = $(patsubst %.xml,%.c,$(FEATURE_XMLFILES))
> +
> +cfiles: $(CFILES) $(FEATURE_CFILES)

If we are going to have different kinds of CFILES, it would be nice to 
rename CFILES (to TDESC_CFILES I suppose) to clarify the purpose of each 
variable.

> +
> +$(CFILES): %.c: %.xml
>  	$(GDB) -nx -q -batch \
>  	  -ex "set tdesc filename $<" -ex 'maint print c-tdesc' > $@.tmp
>  	sh ../../move-if-change $@.tmp $@
> 
> +$(FEATURE_CFILES): %.c: %.xml.tmp
> +	$(GDB) -nx -q -batch \
> +	  -ex 'maint print c-tdesc $<' > $@.tmp
> +	sh ../../move-if-change $@.tmp $@
> +	rm $<
> +
> +%.xml.tmp: %.xml
> +	echo "<?xml version=\"1.0\"?>" > $@
> +	echo "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">" >> $@
> +	echo "<target>" >> $@
> +	echo "  <architecture>" >> $@
> +	if test $(findstring i386/32bit-,$@); then echo "i386" >> $@ ; fi;

Should this be

   test -n "$(findstring ...)"

Quotes would be important here, if findstring returns en empty string,

> +	echo "  </architecture>" >> $@
> +	echo "  <xi:include href=\"$(notdir $<)\"/>" >> $@
> +	echo "</target>" >> $@
> +

Instead of creating this temporary file, wouldn't it be simpler to make 
"maint print c-tdesc" (or a new "maint print c-feature") take directly a 
path to a feature XML, and generate the C from that?
> @@ -2033,38 +2040,123 @@ public:
>      printf_unfiltered ("%d, \"%s\");\n", reg->bitsize, reg->type);
>    }
> 
> +protected:
> +  std::string m_filename_after_features;
> +
>  private:
>    char *m_function;
> -  std::string m_filename_after_features;
>    bool m_printed_field_type = false;
>    bool m_printed_type = false;
>  };
> 
> +class print_c_feature : public print_c_tdesc

I am really not convinced that such an inheritance is appropriate here.  
To make print_c_feature inherit from print_c_tdesc, we should be able to 
say that a print_c_feature object _is_ a print_c_tdesc with further 
specialization.  I don't think it's the case here.  If they can share 
some code, I think it would be appropriate for them to have a common 
base class though.

Simon

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 00/25 V2] Make GDB builtin target descriptions more  flexible
  2017-06-26 14:45   ` Tedeschi, Walfred
@ 2017-06-27 13:49     ` Alan Hayward
  2017-06-28  8:28       ` Yao Qi
  2017-06-28  8:06     ` Yao Qi
  1 sibling, 1 reply; 82+ messages in thread
From: Alan Hayward @ 2017-06-27 13:49 UTC (permalink / raw)
  To: Yao Qi; +Cc: Simon Marchi, gdb-patches, Tedeschi, Walfred, nd


> On 26 Jun 2017, at 15:45, Tedeschi, Walfred <walfred.tedeschi@intel.com> wrote:
> 
> 
> 
> -----Original Message-----
> From: gdb-patches-owner@sourceware.org [mailto:gdb-patches-owner@sourceware.org] On Behalf Of Simon Marchi
> Sent: Monday, June 19, 2017 9:00 PM
> To: Yao Qi <qiyaoltc@gmail.com>
> Cc: gdb-patches@sourceware.org
> Subject: Re: [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible
> 
> On 2017-06-12 10:41, Yao Qi wrote:
>> This patch series is to change GDB and GDBserver builtin target 
>> descriptions more flexible, by removing pre-generated ones.  Instead, 
>> these builtin target descriptions can be got lazily and dynamically.
>> GDB builtin target descriptions are created from initialize_tdesc_* 
>> functions in features/*.c files, while GDBserver builtin target 
>> descriptions are generated from regformats/*.dat files.
>> 
>> This patch series changes both GDB and GDBserver to create target 
>> description dynamically from features, instead of using pre-generated 
>> target descriptions.  This patch series only convert x86-linux ( 
>> including i386-linux, amd64-linux and x32-linux) target description to 
>> demonstrate the usefulness of the change.
>> 
>> Once one target architecture switches to the new flexible target 
>> description,
>> 
>> - only need xml feature files under gdb/features directory.  All  
>> existing target description xml files can be kept for the tests.
>> Add new xml feature file if we want to support the new feature,  but 
>> don't need to add new target description xml files.
>> 
>> - All existing gdb/regformats/*.dat are not used, but kept for  the 
>> tests.
>> 
>> This is the V2, and V1 is here
>> https://sourceware.org/ml/gdb-patches/2017-05/msg00291.html,
>> the differences are,
>> 
>> - Change target descriptions for both GDB and GDBserver,
>> - Generate functions creating features from xml feature file
>>   instead of feature name, so that don't have to worry about
>>   different features with the same name (different features
>>   with the same name still have different file names).
>> - Extend the changes for i386-linux to x86-linux (including,
>>   {i386,amd64,x32}-linux)
>> 
>> The big design change in V2 is that use generate c files from xml 
>> feature files, and use generate c files in both GDB and GDBserver.
>> 
>> In next step,  I want to remove the duplication of target descriptions 
>> in GDB and GDBserver, and share more code on creating x86-linux target 
>> descriptions in GDB and GDBserver.
>> I also want people give comments on how to do unit/self tests in 
>> GDBserver, see patch 14.  The purpose of this patch series is still to 
>> demonstrate the design, so the changelog, NEWS entry, and doc may be 
>> incomplete.  I'll complete them later.
>> 
>> Regression tested on x86_64-linux (both -m64 and -m32), native and 
>> gdbserver, on aarch64-linux native and gdbserver.
>> ppc64-linux, native.
> 
> Hi Yao,
> 
> Do you have a git branch we can pull from to look at this change?
> 
> Thanks,
> 
> Simon
> 
> 
> Hello Yao,
> 
> I did some tests and they are looking fine for remote and native gdb.
> I could tweak the XCR0 in GDB and GDBSERVER and see tests that also use cpu-id to detect features failing, as expected! Very nice!
> Thanks again!
> 
> As an observation, in the gdbserver side there are calls to _get_ipa_tdesc. I suppose we could rename this to a more generic name.
> About the design: GDBserver still uses the combination of cpu features to build the target description. 
>                                     On the other hand, the improvement was huge, i.e. I would go to accept the patch and consider an additional patch series to address gdbserver tdesc creation. 
> 
> 

Yao -

I’ve been looking at this set using the branch (qiyao/target-desc-2),
instead of patch by patch.

Parts of gdbserver/linux-x86-tdesc.c is duplicated in i386-linux-tdep.c,
and the same for other -tdesc.c files.
Would it be better to move the -tdesc.c files into a common directory,
maybe nat/ ?

How is linux-x86-tdesc-ipa.o built? I can see the entry in configure.srv,
but I can’t find a .c either in my src or build directory.


Alan.







^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible
  2017-06-26 14:45   ` Tedeschi, Walfred
  2017-06-27 13:49     ` Alan Hayward
@ 2017-06-28  8:06     ` Yao Qi
  1 sibling, 0 replies; 82+ messages in thread
From: Yao Qi @ 2017-06-28  8:06 UTC (permalink / raw)
  To: Tedeschi, Walfred; +Cc: Simon Marchi, gdb-patches

"Tedeschi, Walfred" <walfred.tedeschi@intel.com> writes:

> Hello Yao,
>
> I did some tests and they are looking fine for remote and native gdb.
> I could tweak the XCR0 in GDB and GDBSERVER and see tests that also use cpu-id to detect features failing, as expected! Very nice!
> Thanks again!

Hi Walfred,
Thanks for playing with these patches, and good to hear that you like it :)

>
> As an observation, in the gdbserver side there are calls to _get_ipa_tdesc. I suppose we could rename this to a more generic name.
> About the design: GDBserver still uses the combination of cpu features to build the target description. 
>                                      On the other hand, the
> improvement was huge, i.e. I would go to accept the patch and consider
> an additional patch series to address gdbserver tdesc creation. 

I would like GDBserver creates target description in the same way as GDB
does, and then share the code creating target descriptions between GDB
and GDBserver.  It was mentioned in the bottom of cover letter, "share
more code on creating x86-linux target descriptions in GDB and
GDBserver" in next step.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible
  2017-06-27 13:49     ` Alan Hayward
@ 2017-06-28  8:28       ` Yao Qi
  0 siblings, 0 replies; 82+ messages in thread
From: Yao Qi @ 2017-06-28  8:28 UTC (permalink / raw)
  To: Alan Hayward; +Cc: Simon Marchi, gdb-patches, Tedeschi, Walfred, nd

Alan Hayward <Alan.Hayward@arm.com> writes:

Hi Alan,

> Parts of gdbserver/linux-x86-tdesc.c is duplicated in i386-linux-tdep.c,
> and the same for other -tdesc.c files.
> Would it be better to move the -tdesc.c files into a common directory,
> maybe nat/ ?

Yes, there is a duplication, Walfred asked it too.  See my reply
https://sourceware.org/ml/gdb-patches/2017-06/msg00758.html

The code creating target descriptions for each target should be shared
somewhere, in arch/?.  We need to change each backend to migrate to the
new style of creating target descriptions, and share code with GDBserver
if needed.  This project needs help converting interesting backends to
the new style of target description creation.

>
> How is linux-x86-tdesc-ipa.o built? I can see the entry in configure.srv,
> but I can’t find a .c either in my src or build directory.

linux-x86-tdesc-ipa.o is built from linux-x86-tdesc.c for IPA.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 07/25] Lazily and dynamically create i386-linux target descriptions
  2017-06-20 14:07     ` Yao Qi
@ 2017-06-28 15:30       ` Pedro Alves
  0 siblings, 0 replies; 82+ messages in thread
From: Pedro Alves @ 2017-06-28 15:30 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches


On 06/20/2017 03:07 PM, Yao Qi wrote:
> Pedro Alves <palves@redhat.com> writes:

>> Can you say something about the "regnum = %ld" change?  Is it
>> related to the rest of the patch?
>>

...

> Some reg in XML target description has attribute "regnum" which set the
> register number explicitly rather than using the sequentially allocated
> number,
> 
>   <reg name="xmm0" bitsize="128" type="vec128" regnum="32"/>
> 
> In order to handle this, this patch also changes the visitor to print
> the code to set regnum when reg has attribute "regnum".

I see.

   void visit (const tdesc_reg *reg) override
   {
+    if (reg->target_regnum > next_regnum)
+      {
+	printf_unfiltered ("  regnum = %ld;\n", reg->target_regnum);
+	next_regnum = reg->target_regnum;
+      }

I guess "reg->target_regnum < next_regnum" shouldn't ever
happen, right?  Should we add an assert?

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 08/25] Add "maint check xml-descriptions" to test builtin xml target descriptions
  2017-06-12  8:42 ` [PATCH 08/25] Add "maint check xml-descriptions" to test builtin xml target descriptions Yao Qi
@ 2017-06-28 16:13   ` Pedro Alves
  0 siblings, 0 replies; 82+ messages in thread
From: Pedro Alves @ 2017-06-28 16:13 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

On 06/12/2017 09:41 AM, Yao Qi wrote:

>  
> +@kindex maint check xml-descriptions
> +@item maint check xml-descriptions @var{dir}
> +Check the target descriptions created by @value{GDBN} equal to these
> +which are created from XML files in @var{dir}.

I'd suggest:

 Check that the target descriptions created dynamically by
 @value{GDBN} equal the descriptions created from XML files
 found in @var{dir}.

>    }
> +  bool operator!= (const tdesc_feature &other) const
> +  {

(Missing empty line just above the method.)

Nit, it's a bit more conventional to define operator==
instead, and then operator!= in terms of operator==,
like you had in other cases.  Can you do the same here?
It'd just mean swapping true/false in the body of this
function, I think.


> +
> +  bool operator!= (const target_desc &other) const
> +  {

Ditto.

>  
> +namespace selftests {
> +
> +static std::vector<std::pair<const char*, const target_desc *>> xml_tdesc;
> +
> +#if GDB_SELF_TEST
> +void
> +record_xml_tdesc (const char *xml_file, const struct target_desc *tdesc)
> +{
> +  xml_tdesc.emplace_back (xml_file, tdesc);
> +}
> +#endif
> +

Missing intro comments.

> +}
> +
> +/* Test these GDB builtin target descriptions equal to these which
> +   are generated by the corresponding xml files.  */

"these" here isn't specified (two times).  Can you name what
"these" are instead, avoiding indirection?  Maybe:

 Check that the target descriptions created dynamically by
 architecture-specific code, as registered in XML_TDESC,
 equal the descriptions created from XML files found in the
 specified directory.

> +
> +static void
> +maintenance_check_xml_descriptions (char *name, int from_tty)
> +{
> +  if (name == NULL)
> +    error (_("Missing dir name"));
> +
> +  std::string feature_dir (name);
> +  unsigned int failed = 0;

I'd suggest s/name/dir/ for a tiny bit more clarify.

> +
> +  for (auto const &e : selftests::xml_tdesc)
> +    {
> +      std::string tdesc_xml = (feature_dir + SLASH_STRING + e.first);
> +      const target_desc *tdesc
> +	= file_read_description_xml (tdesc_xml.data ());
> +
> +      if (tdesc == NULL || *tdesc != *e.second)
> +	failed++;
> +    }
> +  printf_filtered (_("%lu XML are tested, %d failed\n"),
> +		   (long) selftests::xml_tdesc.size (), failed);

s/are/were/.  Or better, I think:

  printf_filtered (_("Tested %lu XML files, %d failed\n"),
		   (long) selftests::xml_tdesc.size (), failed);

In the same spirit of "maint selftest"'s output.


> +
> +  add_cmd ("xml-descriptions", class_maintenance,
> +	   maintenance_check_xml_descriptions, _("\
> +Check the target descriptions.\n\
> +Takes a directory parameter."),

Can you expand this a little bit?

> +	   &maintenancechecklist);

Also, I tried the command manually, and noticed that it doesn't
support filename TAB completion.  You can fix that with:

  set_cmd_completer (c, filename_completer);

It'd be convenient too if it support tilde expansion:

 (gdb) maintenance check xml-descriptions ~/gdb/mygit/src/gdb/features
 warning: Could not open "~/gdb/mygit/src/gdb/features/i386/i386-linux.xml"
 warning: Could not open "~/gdb/mygit/src/gdb/features/i386/i386-mmx-linux.xml"
 warning: Could not open "~/gdb/mygit/src/gdb/features/i386/i386-avx-linux.xml"
 warning: Could not open "~/gdb/mygit/src/gdb/features/i386/i386-mpx-linux.xml"
 warning: Could not open "~/gdb/mygit/src/gdb/features/i386/i386-avx-mpx-linux.xml"
 warning: Could not open "~/gdb/mygit/src/gdb/features/i386/i386-avx-avx512-linux.xml"
 warning: Could not open "~/gdb/mygit/src/gdb/features/i386/i386-avx-mpx-avx512-pku-linux.xml"
 7 XML are tested, 7 failed
 (gdb) maintenance check xml-descriptions /home/pedro/gdb/mygit/src/gdb/features
 7 XML are tested, 0 failed

You can fix that by simply calling tilde_expand.


>  
> +#if GDB_SELF_TEST
> +namespace selftests {
> +
> +/* Record the target description TDESC generated by XML_FILE.  */

"record for what?" is a reasonable question that the comment
doesn't help with.  Maybe write something like this:

 Record that XML_FILE should generate a target description that
 equals TDESC, to be verified by the "maintenance check xml-descriptions"
 command.

> +
> +void record_xml_tdesc (const char *xml_file,
> +		       const struct target_desc *tdesc);
> +}
> +#endif
> +

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 09/25] Use target_desc fields expedite_regs and xmltarget ifndef IN_PROCESS_AGENT
  2017-06-12  8:42 ` [PATCH 09/25] Use target_desc fields expedite_regs and xmltarget ifndef IN_PROCESS_AGENT Yao Qi
@ 2017-06-28 16:16   ` Pedro Alves
  2017-06-28 17:42     ` Pedro Alves
  2017-06-29 11:45     ` Yao Qi
  0 siblings, 2 replies; 82+ messages in thread
From: Pedro Alves @ 2017-06-28 16:16 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

On 06/12/2017 09:41 AM, Yao Qi wrote:
> struct target_desc is used by both GDBserver and IPA, but fields expedite_regs
> and xmltarget are only used in GDBserver, so this patch wraps these two fields
> by ifndef IN_PROCESS_AGENT.  This patch also changes regformats/regdat.sh to
> generate .c files in this way too.

OK.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 14/25] [RFC] GDBserver self test
  2017-06-12  8:42 ` [PATCH 14/25] [RFC] GDBserver self test Yao Qi
@ 2017-06-28 17:09   ` Pedro Alves
  2017-06-29  9:08     ` Yao Qi
  0 siblings, 1 reply; 82+ messages in thread
From: Pedro Alves @ 2017-06-28 17:09 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

On 06/12/2017 09:41 AM, Yao Qi wrote:
> This patch uses GDB self test in GDBserver.  The self tests are run if
> GDBserver is started with option --self-test.

The name of the corresponding gdb command is "maint selftest",
i.e., no hyphen.  If wonder if we should be consistent.

> 
> gdb/gdbserver:
> 
> 2017-05-26  Yao Qi  <yao.qi@linaro.org>
> 
> 	* configure.ac: AC_DEFINE GDB_SELF_TEST if $development.
> 	* configure, config.in: Re-generated.
> 	* server.c: Include sefltest.h and selftest.c.
> 	(captured_main): Handle option --self-test.
> gdb:
> 
> 2017-05-26  Yao Qi  <yao.qi@linaro.org>
> 
> 	* selftest.c: Adjust it for GDBserver.
> 
> gdb/testsuite:
> 
> 2017-05-26  Yao Qi  <yao.qi@linaro.org>
> 
> 	* gdb.server/unittest.exp: New.

I like the idea of running unit tests in gdbserver
(and we briefly discussed it when we introduced selftest-arch.c
IIRC).

But I don't know whether you're proposing the patch as
is, or whether it's really just for comments on the idea.
I say this because there are several hacks in the patch
that ideally we'd avoid.

> +#include "../selftest.h"
> +#include "../selftest.c"

E.g., we should really move these to common/ and void
the #ifdefery within them.

> +global server_spawn_id
> +
> +set gdbserver [find_gdbserver]
> +set gdbserver_command "$gdbserver --self-test"
> +
> +set server_spawn_id [remote_spawn target $gdbserver_command]
> +
> +gdb_expect {
> +    -i $server_spawn_id
> +    -re "Ran $decimal unit tests, 0 failed" {
> +	pass "unit tests"
> +    }
> +    -re "Ran $decimal unit tests, $decimal failed" {
> +	fail "unit tests"
> +    }

Shouldn't this have a "default" case that fails instead
of only handling one specific failure mode?

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 15/25] [RFC] GDBserver unit test to i386_tdesc
  2017-06-12  8:42 ` [PATCH 15/25] [RFC] GDBserver unit test to i386_tdesc Yao Qi
@ 2017-06-28 17:22   ` Pedro Alves
  2017-06-29  9:27     ` Yao Qi
  0 siblings, 1 reply; 82+ messages in thread
From: Pedro Alves @ 2017-06-28 17:22 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

On 06/12/2017 09:41 AM, Yao Qi wrote:
> This patch adds a unit test in GDBserver to test dynamically created
> target descriptions equal to these pre-generated ones.
> 
> gdb/gdbserver:

Are these temporary tests?  What's the plan for the pre-generated ones?

> +#if defined GDB_SELF_TEST && !defined IN_PROCESS_AGENT
> +#include "selftest.h"
> +
> +namespace selftests {
> +namespace gdbserver {

Considering that at some point we may want to wrap
all of gdbserver under "namespace gdbserver", this
namespace choice here seems like a poor choice.
s/gdbserver/tdesc_tests/ or some such?


> +static void
> +i386_tdesc_test ()
> +{
> +  const struct target_desc *tdesc = i386_get_ipa_tdesc (X86_TDESC_MMX);
> +
> +  SELF_CHECK (*tdesc == *tdesc_i386_mmx_linux);
> +  delete tdesc;
> +
> +  tdesc = i386_get_ipa_tdesc (X86_TDESC_SSE);
> +  SELF_CHECK (*tdesc == *tdesc_i386_linux);
> +  delete tdesc;
> +
> +  tdesc = i386_get_ipa_tdesc (X86_TDESC_AVX);
> +  SELF_CHECK (*tdesc == *tdesc_i386_avx_linux);
> +  delete tdesc;
> +
> +  tdesc = i386_get_ipa_tdesc (X86_TDESC_MPX);
> +  SELF_CHECK (*tdesc == *tdesc_i386_mpx_linux);
> +  delete tdesc;
> +
> +  tdesc = i386_get_ipa_tdesc (X86_TDESC_AVX_MPX);
> +  SELF_CHECK (*tdesc == *tdesc_i386_avx_mpx_linux);
> +  delete tdesc;
> +
> +  tdesc = i386_get_ipa_tdesc (X86_TDESC_AVX_AVX512);
> +  SELF_CHECK (*tdesc == *tdesc_i386_avx_avx512_linux);
> +  delete tdesc;
> +
> +  tdesc = i386_get_ipa_tdesc (X86_TDESC_AVX_MPX_AVX512_PKU);
> +  SELF_CHECK (*tdesc == *tdesc_i386_avx_mpx_avx512_pku_linux);
> +  delete tdesc;

Would something like this, based on an array, work? :

  struct 
    {
      int idx;
      const target_desc *tdesc;
    }
  tdesc_tests[] = {
      { X86_TDESC_MMX, tdesc_i386_mmx_linux },
      { X86_TDESC_SSE, tdesc_i386_linux },
      ...
  };

  for (auto &elem : tdesc_tests)
    {
      std::unique_ptr<const target_desc> tdesc (i386_get_ipa_tdesc (elem.idx));
      SELF_CHECK (*elem.tdesc == *tdesc);
    }

> diff --git a/gdb/gdbserver/tdesc.h b/gdb/gdbserver/tdesc.h
> index 2d4cbfa..e64f0b3 100644
> --- a/gdb/gdbserver/tdesc.h
> +++ b/gdb/gdbserver/tdesc.h
> @@ -19,7 +19,8 @@
>  #ifndef TDESC_H
>  #define TDESC_H
>  
> -struct reg;
> +#include "regdef.h"
> +#include <cstring>

Odd that you needed cstring?  string.h is one of the
system headers always pulled in by common/common-defs.h.

>  
>  typedef struct reg *tdesc_reg_p;
>  DEF_VEC_P(tdesc_reg_p);
> @@ -60,6 +61,45 @@ public:
>        xfree (reg);
>      VEC_free (tdesc_reg_p, reg_defs);
>    }
> +  bool operator!= (const target_desc &other) const

Same comment about "operator!=" vs "operator==" as in
a previous patch.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 09/25] Use target_desc fields expedite_regs and xmltarget ifndef IN_PROCESS_AGENT
  2017-06-28 16:16   ` Pedro Alves
@ 2017-06-28 17:42     ` Pedro Alves
  2017-06-28 17:45       ` Pedro Alves
  2017-06-29 11:45     ` Yao Qi
  1 sibling, 1 reply; 82+ messages in thread
From: Pedro Alves @ 2017-06-28 17:42 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

On 06/28/2017 05:15 PM, Pedro Alves wrote:
> On 06/12/2017 09:41 AM, Yao Qi wrote:
>> struct target_desc is used by both GDBserver and IPA, but fields expedite_regs
>> and xmltarget are only used in GDBserver, so this patch wraps these two fields
>> by ifndef IN_PROCESS_AGENT.  This patch also changes regformats/regdat.sh to
>> generate .c files in this way too.
> 
> OK.

Actually, I tried building the series at some intermediate patch,
and noticed that the build was broken.  This is the first patch
that breaks it:

...
amd64-linux.c: In function ‘void init_registers_amd64_linux()’:
amd64-linux.c:103:11: error: ‘struct target_desc’ has no member named
‘expedite_regs’
   result->expedite_regs = expedite_regs_amd64_linux;
           ^
amd64-linux.c:104:11: error: ‘struct target_desc’ has no member named
‘xmltarget’
   result->xmltarget = xmltarget_amd64_linux;
           ^
...

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 09/25] Use target_desc fields expedite_regs and xmltarget ifndef IN_PROCESS_AGENT
  2017-06-28 17:42     ` Pedro Alves
@ 2017-06-28 17:45       ` Pedro Alves
  0 siblings, 0 replies; 82+ messages in thread
From: Pedro Alves @ 2017-06-28 17:45 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

On 06/28/2017 06:42 PM, Pedro Alves wrote:
> On 06/28/2017 05:15 PM, Pedro Alves wrote:
>> On 06/12/2017 09:41 AM, Yao Qi wrote:
>>> struct target_desc is used by both GDBserver and IPA, but fields expedite_regs
>>> and xmltarget are only used in GDBserver, so this patch wraps these two fields
>>> by ifndef IN_PROCESS_AGENT.  This patch also changes regformats/regdat.sh to
>>> generate .c files in this way too.
>>
>> OK.
> 
> Actually, I tried building the series at some intermediate patch,
> and noticed that the build was broken.  This is the first patch
> that breaks it:
> 
> ...
> amd64-linux.c: In function ‘void init_registers_amd64_linux()’:
> amd64-linux.c:103:11: error: ‘struct target_desc’ has no member named
> ‘expedite_regs’
>    result->expedite_regs = expedite_regs_amd64_linux;
>            ^
> amd64-linux.c:104:11: error: ‘struct target_desc’ has no member named
> ‘xmltarget’
>    result->xmltarget = xmltarget_amd64_linux;
>            ^
> ...


Hmm, turns out that I need to remove the generated .c files
manually.  "make clean" didn't remove them.  Now that they're
gone, gdbserver builds cleanly.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 23/25] [GDBserver] Convert amd64-linux target descriptions
  2017-06-12  8:42 ` [PATCH 23/25] [GDBserver] Convert amd64-linux target descriptions Yao Qi
@ 2017-06-28 19:00   ` Pedro Alves
  0 siblings, 0 replies; 82+ messages in thread
From: Pedro Alves @ 2017-06-28 19:00 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

On 06/12/2017 09:41 AM, Yao Qi wrote:
> +static const struct target_desc *amd64_tdescs[X86_TDESC_LAST] = { };
> +static const struct target_desc *x32_tdescs[X86_TDESC_LAST] = { };
> +


> +
> +  if (is_x32)
> +    tdesc = (struct target_desc **) &x32_tdescs[idx];
> +  else
> +    tdesc = (struct target_desc **) &amd64_tdescs[idx];
> +
> +  if (*tdesc == NULL)
> +    {
> +      *tdesc = new target_desc ();


You can't cast away constness of really-const objects and
write to them.  The compiler is free to place the array
in read-only storage.  If this doesn't crash at run time,
it's sheer luck.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 11/25] Use VEC for target_desc.reg_defs
  2017-06-12  8:42 ` [PATCH 11/25] Use VEC for target_desc.reg_defs Yao Qi
@ 2017-06-28 19:01   ` Pedro Alves
  2017-06-29 11:05     ` Yao Qi
  0 siblings, 1 reply; 82+ messages in thread
From: Pedro Alves @ 2017-06-28 19:01 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

On 06/12/2017 09:41 AM, Yao Qi wrote:
> Nowadays, target_desc.reg_defs is a pointer points to a pre-generated
> array, which is not flexible.  This patch changes it from an array
> to a VEC so that GDBserver can create target descriptions dynamically
> later.  Instead of using pre-generated array, the -generated.c calls
> VEC_safe_push to add each register to vector.
> 
> Since target_desc.reg_defs is used in IPA, we need to build common/vec.c
> for IPA too.

Can you say more about the choice of VEC?  It feels
like new uses should come with a rationale for why it'd
be preferred over std::vector.

I'm guessing that it's because the gdb side uses VEC too?
Or is it something else?  (I can guess other reasons, but
the point is that we shouldn't have to guess.)

[Note that the IPA avoids calling the inferior's malloc during
normal operation, to avoid deadlocking the inferior.
This is initialization code, so it's not covered by the exact
same level of concern, even though one of the original goals was
to also be able to inject the IPA into a running inferior (e.g., by
calling dlopen via gdb).  That does work (or at least used to),
but it's a little unsafe because the IPA initialization code
already calls malloc and other non-async-signal-safe functions.
I guess std::vector would make it possible to use a custom
allocator in the IPA that would allocate memory with mmap
directly (or we'd make the IPA's xmalloc allocate with mmap,
and then the allocator would use xmalloc).]

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible
  2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
                   ` (25 preceding siblings ...)
  2017-06-19 19:59 ` [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Simon Marchi
@ 2017-06-28 19:06 ` Pedro Alves
  26 siblings, 0 replies; 82+ messages in thread
From: Pedro Alves @ 2017-06-28 19:06 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

Hi Yao,

In general, I'm happy with the direction of the series.
I was having a bit of trouble grokking the individual patches,
because of missing comments, etc.  I expect this will all see
more polish in v3.

So diffing the whole series instead, here are some comments.
Nothing major, though I don't claim that I've grokked
everything, yet.

-- a/gdb/gdbserver/linux-x86-low.c
+++ b/gdb/gdbserver/linux-x86-low.c
@@ -757,7 +757,7 @@ x86_linux_read_description (void)
        {
          have_ptrace_getfpxregs = 0;
          have_ptrace_getregset = 0;
-         return tdesc_i386_mmx_linux;
+         return i386_get_ipa_tdesc (X86_TDESC_MMX);
        }
       else
        have_ptrace_getfpxregs = 1;

Seems odd that these functions have "_ipa_" in their
name when they're not IPA specific.




int
+i386_get_ipa_tdesc_idx (const struct target_desc *tdesc)
+{
+  for (int i = 0; i < X86_TDESC_LAST; i++)
+    {
+      if (tdesc == i386_tdescs[i])
+       return i;
+    }
+
+  return 0;
+}


Do you really want to return 0?  That's a valid index:

enum x86_linux_tdesc {
  X86_TDESC_MMX = 0,
  ...


@@ -3639,6 +3645,11 @@ captured_main (int argc, char *argv[])
        startup_with_shell = false;
       else if (strcmp (*next_arg, "--once") == 0)
        run_once = 1;
+      else if (strcmp (*next_arg, "--self-test") == 0)
+       {
+         selftest = true;
+         break;
+       }

This "break" means that 

 $ gdbserver --self-self asdfausidpoasduifa

works.  Is that expected?  Might be useful to pass down
the remaining arguments to the self tests infrastructure,
but you're not doing that.

- Missing "m_" prefix in private fields.

- Missing comments throughout; function intros, struct fields, etc.

- Missing empty lines between functions in several places.

- Nit but I think you should be able to replace the 
  "std::pair" uses with unnamed structs, avoiding the
  mostly meaningless "first" vs "second":

   - std::pair<type1, type2> array_name[] = ...
   + struct { type1 field1; type2 field2; } array_name[] = ...

- Can we do something about the #ifdefery in the selftests framework.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 14/25] [RFC] GDBserver self test
  2017-06-28 17:09   ` Pedro Alves
@ 2017-06-29  9:08     ` Yao Qi
  0 siblings, 0 replies; 82+ messages in thread
From: Yao Qi @ 2017-06-29  9:08 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

Pedro Alves <palves@redhat.com> writes:

> The name of the corresponding gdb command is "maint selftest",
> i.e., no hyphen.  If wonder if we should be consistent.
>

I chose "--self-test" because gcc uses "-fself-test".  I am fine to use
"--selftest" to align with GDB command "maint selftest".

>> 
>> gdb/gdbserver:
>> 
>> 2017-05-26  Yao Qi  <yao.qi@linaro.org>
>> 
>> 	* configure.ac: AC_DEFINE GDB_SELF_TEST if $development.
>> 	* configure, config.in: Re-generated.
>> 	* server.c: Include sefltest.h and selftest.c.
>> 	(captured_main): Handle option --self-test.
>> gdb:
>> 
>> 2017-05-26  Yao Qi  <yao.qi@linaro.org>
>> 
>> 	* selftest.c: Adjust it for GDBserver.
>> 
>> gdb/testsuite:
>> 
>> 2017-05-26  Yao Qi  <yao.qi@linaro.org>
>> 
>> 	* gdb.server/unittest.exp: New.
>
> I like the idea of running unit tests in gdbserver
> (and we briefly discussed it when we introduced selftest-arch.c
> IIRC).

Yes, we discussed this _idea_ before, but we didn't know how to do the
unit tests in GDBserver.  I remembered that some one said GDBserver unit
tests can be triggered by a special packet sent by GDB.  When I wrote
this patch, it was still an open question to me.  I chose a new command
line option to trigger the tests, post this patch, and see if people
like this way.

>
> But I don't know whether you're proposing the patch as
> is, or whether it's really just for comments on the idea.

The latter.  The whole patch series is about collecting comments on the
flexible target description, and GDBserver unit tests are used to make
sure my patches don't break target descriptions on GDBserver.  It is of
hacks, and I'll fix them in v3, definitely.

> I say this because there are several hacks in the patch
> that ideally we'd avoid.
>
>> +#include "../selftest.h"
>> +#include "../selftest.c"
>
> E.g., we should really move these to common/ and void
> the #ifdefery within them.
>

Yes, I'll move them to common/.

>> +global server_spawn_id
>> +
>> +set gdbserver [find_gdbserver]
>> +set gdbserver_command "$gdbserver --self-test"
>> +
>> +set server_spawn_id [remote_spawn target $gdbserver_command]
>> +
>> +gdb_expect {
>> +    -i $server_spawn_id
>> +    -re "Ran $decimal unit tests, 0 failed" {
>> +	pass "unit tests"
>> +    }
>> +    -re "Ran $decimal unit tests, $decimal failed" {
>> +	fail "unit tests"
>> +    }
>
> Shouldn't this have a "default" case that fails instead
> of only handling one specific failure mode?

OK, I'll fix it too.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 15/25] [RFC] GDBserver unit test to i386_tdesc
  2017-06-28 17:22   ` Pedro Alves
@ 2017-06-29  9:27     ` Yao Qi
  0 siblings, 0 replies; 82+ messages in thread
From: Yao Qi @ 2017-06-29  9:27 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

Pedro Alves <palves@redhat.com> writes:

> On 06/12/2017 09:41 AM, Yao Qi wrote:
>> This patch adds a unit test in GDBserver to test dynamically created
>> target descriptions equal to these pre-generated ones.
>> 
>> gdb/gdbserver:
>
> Are these temporary tests?  What's the plan for the pre-generated ones?

They are not temporary tests, we'll keep the tests, but they won't
change.  We also keep these pre-generated target descriptions, as legacy
target descriptions, for the tests.  Once we finish the target
description transition, we can move these pre-generated target
descriptions into testsuite/ directory.

Note that, after we finish the change for a given architecture, all
target descriptions are dynamically generated, so there is no new
pre-generated target description, and we don't update the tests.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 11/25] Use VEC for target_desc.reg_defs
  2017-06-28 19:01   ` Pedro Alves
@ 2017-06-29 11:05     ` Yao Qi
  2017-06-29 11:31       ` Pedro Alves
  0 siblings, 1 reply; 82+ messages in thread
From: Yao Qi @ 2017-06-29 11:05 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

Pedro Alves <palves@redhat.com> writes:

> Can you say more about the choice of VEC?  It feels
> like new uses should come with a rationale for why it'd
> be preferred over std::vector.
>
> I'm guessing that it's because the gdb side uses VEC too?
> Or is it something else?  (I can guess other reasons, but
> the point is that we shouldn't have to guess.)

Yes, GDB target description uses VEC, so I chose VEC for GDBserver
target description too.

>
> [Note that the IPA avoids calling the inferior's malloc during
> normal operation, to avoid deadlocking the inferior.
> This is initialization code, so it's not covered by the exact
> same level of concern, even though one of the original goals was
> to also be able to inject the IPA into a running inferior (e.g., by
> calling dlopen via gdb).  That does work (or at least used to),
> but it's a little unsafe because the IPA initialization code
> already calls malloc and other non-async-signal-safe functions.

Such usage is documented, at least,
https://sourceware.org/gdb/onlinedocs/gdb/Server.html

> I guess std::vector would make it possible to use a custom
> allocator in the IPA that would allocate memory with mmap
> directly (or we'd make the IPA's xmalloc allocate with mmap,
> and then the allocator would use xmalloc).]

Do you suggest that we need to use std::vector plus a customized
allocator which uses mmap?

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 11/25] Use VEC for target_desc.reg_defs
  2017-06-29 11:05     ` Yao Qi
@ 2017-06-29 11:31       ` Pedro Alves
  2017-06-29 13:24         ` Yao Qi
  0 siblings, 1 reply; 82+ messages in thread
From: Pedro Alves @ 2017-06-29 11:31 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches


On 06/29/2017 12:05 PM, Yao Qi wrote:
> Pedro Alves <palves@redhat.com> writes:
> 
>> Can you say more about the choice of VEC?  It feels
>> like new uses should come with a rationale for why it'd
>> be preferred over std::vector.
>>
>> I'm guessing that it's because the gdb side uses VEC too?
>> Or is it something else?  (I can guess other reasons, but
>> the point is that we shouldn't have to guess.)
> 
> Yes, GDB target description uses VEC, so I chose VEC for GDBserver
> target description too.

OK.

> 
>>
>> [Note that the IPA avoids calling the inferior's malloc during
>> normal operation, to avoid deadlocking the inferior.
>> This is initialization code, so it's not covered by the exact
>> same level of concern, even though one of the original goals was
>> to also be able to inject the IPA into a running inferior (e.g., by
>> calling dlopen via gdb).  That does work (or at least used to),
>> but it's a little unsafe because the IPA initialization code
>> already calls malloc and other non-async-signal-safe functions.
> 
> Such usage is documented, at least,
> https://sourceware.org/gdb/onlinedocs/gdb/Server.html

Yeah.  We also call "malloc" in the inferior (value_allocate_space_in_inferior)
for coercing arrays, etc. to the inferior ('print "hello"', etc.) which
suffers from the same problem.  I'm often surprised how we
don't hear more bug reports about that.

> 
>> I guess std::vector would make it possible to use a custom
>> allocator in the IPA that would allocate memory with mmap
>> directly (or we'd make the IPA's xmalloc allocate with mmap,
>> and then the allocator would use xmalloc).]
> 
> Do you suggest that we need to use std::vector plus a customized
> allocator which uses mmap?

No, not now, at least.  At first I thought that using VEC instead of
static arrays would be the introducing the problem of using
malloc in the initialization path.  Then while writing a
review in that direction I looked at the code and
realized/remembered that it's not really a new problem.
But I chose to dump my thoughts on how that might
be fixable in the future as a parenthesis.  I don't mean
to go fix that now.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 09/25] Use target_desc fields expedite_regs and xmltarget ifndef IN_PROCESS_AGENT
  2017-06-28 16:16   ` Pedro Alves
  2017-06-28 17:42     ` Pedro Alves
@ 2017-06-29 11:45     ` Yao Qi
  1 sibling, 0 replies; 82+ messages in thread
From: Yao Qi @ 2017-06-29 11:45 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

Pedro Alves <palves@redhat.com> writes:

> On 06/12/2017 09:41 AM, Yao Qi wrote:
>> struct target_desc is used by both GDBserver and IPA, but fields expedite_regs
>> and xmltarget are only used in GDBserver, so this patch wraps these two fields
>> by ifndef IN_PROCESS_AGENT.  This patch also changes regformats/regdat.sh to
>> generate .c files in this way too.
>
> OK.

I cherry-pick it to master, and rebuilt GDBserver.  Push it in.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 11/25] Use VEC for target_desc.reg_defs
  2017-06-29 11:31       ` Pedro Alves
@ 2017-06-29 13:24         ` Yao Qi
  0 siblings, 0 replies; 82+ messages in thread
From: Yao Qi @ 2017-06-29 13:24 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

Pedro Alves <palves@redhat.com> writes:

>>> [Note that the IPA avoids calling the inferior's malloc during
>>> normal operation, to avoid deadlocking the inferior.
>>> This is initialization code, so it's not covered by the exact
>>> same level of concern, even though one of the original goals was
>>> to also be able to inject the IPA into a running inferior (e.g., by
>>> calling dlopen via gdb).  That does work (or at least used to),
>>> but it's a little unsafe because the IPA initialization code
>>> already calls malloc and other non-async-signal-safe functions.
>> 
>> Such usage is documented, at least,
>> https://sourceware.org/gdb/onlinedocs/gdb/Server.html
>
> Yeah.  We also call "malloc" in the inferior (value_allocate_space_in_inferior)
> for coercing arrays, etc. to the inferior ('print "hello"', etc.) which
> suffers from the same problem.  I'm often surprised how we
> don't hear more bug reports about that.
>

I can understand IPA calls malloc may cause deadlock in the inferior, if
the inferior has already acquired the lock for malloc.  Think it a bit
more during lunch, I don't understand how it is related to
non-async-signal-safe functions?  Is it that main program executed some
non-async-signal-safe function, signal arrives, goes to signal handler,
hits a breakpoint or fast tracepoint here.  Then, the
non-async-signal-safe functions may be executed again either by gdb
inferior call or IPA.  If this is the problem, ...

>> 
>>> I guess std::vector would make it possible to use a custom
>>> allocator in the IPA that would allocate memory with mmap
>>> directly (or we'd make the IPA's xmalloc allocate with mmap,
>>> and then the allocator would use xmalloc).]
>> 
>> Do you suggest that we need to use std::vector plus a customized
>> allocator which uses mmap?
>
> No, not now, at least.  At first I thought that using VEC instead of
> static arrays would be the introducing the problem of using
> malloc in the initialization path.  Then while writing a
> review in that direction I looked at the code and
> realized/remembered that it's not really a new problem.
> But I chose to dump my thoughts on how that might
> be fixable in the future as a parenthesis.  I don't mean
> to go fix that now.

... then, we can't use std::vector either, because it may throw
exception, or we somehow need to guarantee that the std::vector we used
doesn't throw exception.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 82+ messages in thread

* Re: [PATCH 06/25] Generate c for feature instead of tdesc
  2017-06-26 21:38   ` Simon Marchi
@ 2017-06-29 15:24     ` Yao Qi
  0 siblings, 0 replies; 82+ messages in thread
From: Yao Qi @ 2017-06-29 15:24 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

Simon Marchi <simon.marchi@polymtl.ca> writes:

>> +FEATURE_CFILES = $(patsubst %.xml,%.c,$(FEATURE_XMLFILES))
>> +
>> +cfiles: $(CFILES) $(FEATURE_CFILES)
>
> If we are going to have different kinds of CFILES, it would be nice to
> rename CFILES (to TDESC_CFILES I suppose) to clarify the purpose of
> each variable.
>

OK, I'll rename CFILES.

>> +
>> +$(CFILES): %.c: %.xml
>>  	$(GDB) -nx -q -batch \
>>  	  -ex "set tdesc filename $<" -ex 'maint print c-tdesc' > $@.tmp
>>  	sh ../../move-if-change $@.tmp $@
>>
>> +$(FEATURE_CFILES): %.c: %.xml.tmp
>> +	$(GDB) -nx -q -batch \
>> +	  -ex 'maint print c-tdesc $<' > $@.tmp
>> +	sh ../../move-if-change $@.tmp $@
>> +	rm $<
>> +
>> +%.xml.tmp: %.xml
>> +	echo "<?xml version=\"1.0\"?>" > $@
>> +	echo "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">" >> $@
>> +	echo "<target>" >> $@
>> +	echo "  <architecture>" >> $@
>> +	if test $(findstring i386/32bit-,$@); then echo "i386" >> $@ ; fi;
>
> Should this be
>
>   test -n "$(findstring ...)"
>
> Quotes would be important here, if findstring returns en empty string,
>

I update the code here, and find the "test findstring" is no longer needed.

>> +	echo "  </architecture>" >> $@
>> +	echo "  <xi:include href=\"$(notdir $<)\"/>" >> $@
>> +	echo "</target>" >> $@
>> +
>
> Instead of creating this temporary file, wouldn't it be simpler to
> make "maint print c-tdesc" (or a new "maint print c-feature") take
> directly a path to a feature XML, and generate the C from that?

Actually, I thought about adding a new command, but I find adding temp
file is simpler than modifying GDB to add a new command and accept a
feature XML.  It is just some lines of code in Makefile, with the "test"
"findstring" stuff removed, they are quite simple.

>> @@ -2033,38 +2040,123 @@ public:
>>      printf_unfiltered ("%d, \"%s\");\n", reg->bitsize, reg->type);
>>    }
>>
>> +protected:
>> +  std::string m_filename_after_features;
>> +
>>  private:
>>    char *m_function;
>> -  std::string m_filename_after_features;
>>    bool m_printed_field_type = false;
>>    bool m_printed_type = false;
>>  };
>>
>> +class print_c_feature : public print_c_tdesc
>
> I am really not convinced that such an inheritance is appropriate
> here.  To make print_c_feature inherit from print_c_tdesc, we should
> be able to say that a print_c_feature object _is_ a print_c_tdesc with
> further specialization.  I don't think it's the case here.  If they

No, there is no is-a relationship between print_c_feature and
print_c_tdesc, so it is inheritance, not subtying.

https://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)

"Inheritance should not be confused with subtyping....in general,
subtyping establishes an is-a relationship, whereas inheritance only
reuses implementation and establishes a syntactic relationship..."

and

"In object-oriented programming, inheritance is when an object or class
is based on another object (prototypal inheritance) or class
(class-based inheritance), using the same implementation (...) or
specifying a new implementation to maintain the same behavior (...)",

> can share some code, I think it would be appropriate for them to have
> a common base class though.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 82+ messages in thread

end of thread, other threads:[~2017-06-29 15:24 UTC | newest]

Thread overview: 82+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
2017-06-12  8:42 ` [PATCH 04/25] Centralize i386 linux target descriptions Yao Qi
2017-06-19 21:27   ` Simon Marchi
2017-06-12  8:42 ` [PATCH 06/25] Generate c for feature instead of tdesc Yao Qi
2017-06-12 14:48   ` Eli Zaretskii
2017-06-13 12:07     ` Yao Qi
2017-06-13 14:49       ` Eli Zaretskii
2017-06-13 15:31         ` Yao Qi
2017-06-13 15:41           ` Eli Zaretskii
2017-06-14 16:21             ` Yao Qi
2017-06-14 16:32               ` Eli Zaretskii
2017-06-15 13:19                 ` Yao Qi
2017-06-15 14:45                   ` Eli Zaretskii
2017-06-20 10:59   ` Pedro Alves
2017-06-22 14:49     ` Yao Qi
2017-06-22 15:36       ` Pedro Alves
2017-06-22 15:58         ` Yao Qi
2017-06-26 21:38   ` Simon Marchi
2017-06-29 15:24     ` Yao Qi
2017-06-12  8:42 ` [PATCH 18/25] [GDBserver] Use pre-generated tdesc as test Yao Qi
2017-06-12  8:42 ` [PATCH 12/25] [GDBserver] Centralize tdesc for i386-linux Yao Qi
2017-06-12  8:42 ` [PATCH 25/25] Remove features/i386/amd64-*linux.c and features/i386/x32-*linux.c Yao Qi
2017-06-12  8:42 ` [PATCH 11/25] Use VEC for target_desc.reg_defs Yao Qi
2017-06-28 19:01   ` Pedro Alves
2017-06-29 11:05     ` Yao Qi
2017-06-29 11:31       ` Pedro Alves
2017-06-29 13:24         ` Yao Qi
2017-06-12  8:42 ` [PATCH 08/25] Add "maint check xml-descriptions" to test builtin xml target descriptions Yao Qi
2017-06-28 16:13   ` Pedro Alves
2017-06-12  8:42 ` [PATCH 05/25] Use visitor pattern for "maint print c-tdesc" Yao Qi
2017-06-20 23:37   ` Simon Marchi
2017-06-12  8:42 ` [PATCH 17/25] Remove features/i386/i386-*linux.c Yao Qi
2017-06-12  8:42 ` [PATCH 23/25] [GDBserver] Convert amd64-linux target descriptions Yao Qi
2017-06-28 19:00   ` Pedro Alves
2017-06-12  8:42 ` [PATCH 15/25] [RFC] GDBserver unit test to i386_tdesc Yao Qi
2017-06-28 17:22   ` Pedro Alves
2017-06-29  9:27     ` Yao Qi
2017-06-12  8:42 ` [PATCH 20/25] Centralize amd64-linux target descriptions Yao Qi
2017-06-12  8:42 ` [PATCH 02/25] Adjust the order of 32bit-linux.xml and 32bit-sse.xml in i386/i386-linux.xml Yao Qi
2017-06-19 20:22   ` Simon Marchi
2017-06-19 21:24     ` Pedro Alves
2017-06-19 21:48       ` Simon Marchi
2017-06-19 21:56         ` Pedro Alves
2017-06-20  9:20           ` Yao Qi
2017-06-20 10:12             ` Pedro Alves
2017-06-20 11:09               ` Yao Qi
2017-06-12  8:42 ` [PATCH 14/25] [RFC] GDBserver self test Yao Qi
2017-06-28 17:09   ` Pedro Alves
2017-06-29  9:08     ` Yao Qi
2017-06-12  8:42 ` [PATCH 01/25] Move initialize_tdesc_mips* calls from mips-linux-nat.c to mips-linux-tdep.c Yao Qi
2017-06-12 15:25   ` Maciej W. Rozycki
2017-06-13  8:07     ` Yao Qi
2017-06-12  8:42 ` [PATCH 03/25] Class-fy tdesc_reg tdesc_type and tdesc_feature Yao Qi
2017-06-19 20:55   ` Simon Marchi
2017-06-19 21:30   ` Simon Marchi
2017-06-20 10:31     ` Yao Qi
2017-06-12  8:42 ` [PATCH 19/25] GDBserver: remove srv_i386_linux_xmlfiles Yao Qi
2017-06-12  8:42 ` [PATCH 10/25] Adjust code generated by regformats/regdat.sh Yao Qi
2017-06-20 11:09   ` Pedro Alves
2017-06-21 14:28     ` Yao Qi
2017-06-12  8:42 ` [PATCH 07/25] Lazily and dynamically create i386-linux target descriptions Yao Qi
2017-06-20 11:01   ` Pedro Alves
2017-06-20 14:07     ` Yao Qi
2017-06-28 15:30       ` Pedro Alves
2017-06-12  8:42 ` [PATCH 09/25] Use target_desc fields expedite_regs and xmltarget ifndef IN_PROCESS_AGENT Yao Qi
2017-06-28 16:16   ` Pedro Alves
2017-06-28 17:42     ` Pedro Alves
2017-06-28 17:45       ` Pedro Alves
2017-06-29 11:45     ` Yao Qi
2017-06-12  8:42 ` [PATCH 22/25] Regenerate two regformats/i386/.dat files Yao Qi
2017-06-22 12:43   ` Yao Qi
2017-06-12  8:42 ` [PATCH 21/25] Lazily and dynamically create amd64-linux target descriptions Yao Qi
2017-06-12  8:42 ` [PATCH 13/25] Dynamically create tdesc in GDBserver Yao Qi
2017-06-12  8:42 ` [PATCH 24/25] [GDBserver] Use pre-generated amd64-linux tdesc as test Yao Qi
2017-06-12  8:42 ` [PATCH 16/25] Dynamically composite xml in reply to GDB Yao Qi
2017-06-19 19:59 ` [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Simon Marchi
2017-06-20 11:02   ` Yao Qi
2017-06-26 14:45   ` Tedeschi, Walfred
2017-06-27 13:49     ` Alan Hayward
2017-06-28  8:28       ` Yao Qi
2017-06-28  8:06     ` Yao Qi
2017-06-28 19:06 ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).