This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: Cache types from target description


On Thu, Feb 04, 2010 at 05:14:47PM -0800, H.J. Lu wrote:
> I am resending this patch. The motivation is I am working on x86 xml
> target descriptions.  x86 has i387_ext type. I added
> 
>   case TDESC_TYPE_I387_EXT:
>      return arch_float_type (gdbarch, -1, "builtin_type_i387_ext",
>                              floatformats_i387_ext);
> 
> to tdesc_gdb_type. I would up 8 i387_ext types at 8 different addresses
> with the same bits. x86 does
> 
> if (i386_fp_regnum_p (gdbarch, regnum))
>    {
>      /* Floating point registers must be converted unless we are
>         accessing them in their hardware type.  */
>      if (type == i387_ext_type (gdbarch))
>        return 0;
>      else
>        return 1;
>    }
> 
> It expects 2  i387_ext types should have the same address.  This
> patch caches ieee_single, ieee_double and i387_ext. OK to install?
> 


Here is a different patch to cache types from target description. 
tdesc_find_type will be used in i387_ext_type to lookup "i387_ext".
OK to install?

Thanks.


H.J.
---
2010-02-08  H.J. Lu  <hongjiu.lu@intel.com>

	* target-descriptions.c (tdesc_type): Add TDESC_TYPE_I387_EXT,
	TDESC_TYPE_I386_EFLAGS and TDESC_TYPE_I386_MXCSR.
	(tdesc_predefined_types): Add i387_ext, i386_eflags and
	i386_mxcsr.
	(tdesc_find_type): New.
	(tdesc_gdb_type): Use tdesc_find_type.  Handle TDESC_TYPE_I387_EXT,
	TDESC_TYPE_I386_EFLAGS and TDESC_TYPE_I386_MXCSR.

diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
index 4fbc72c..ae22163 100644
--- a/gdb/target-descriptions.c
+++ b/gdb/target-descriptions.c
@@ -117,6 +117,9 @@ typedef struct tdesc_type
     TDESC_TYPE_IEEE_SINGLE,
     TDESC_TYPE_IEEE_DOUBLE,
     TDESC_TYPE_ARM_FPA_EXT,
+    TDESC_TYPE_I387_EXT,
+    TDESC_TYPE_I386_EFLAGS,
+    TDESC_TYPE_I386_MXCSR,
 
     /* Types defined by a target feature.  */
     TDESC_TYPE_VECTOR,
@@ -461,7 +464,10 @@ static struct tdesc_type tdesc_predefined_types[] =
   { "data_ptr", TDESC_TYPE_DATA_PTR },
   { "ieee_single", TDESC_TYPE_IEEE_SINGLE },
   { "ieee_double", TDESC_TYPE_IEEE_DOUBLE },
-  { "arm_fpa_ext", TDESC_TYPE_ARM_FPA_EXT }
+  { "arm_fpa_ext", TDESC_TYPE_ARM_FPA_EXT },
+  { "i387_ext", TDESC_TYPE_I387_EXT },
+  { "i386_eflags", TDESC_TYPE_I386_EFLAGS },
+  { "i386_mxcsr", TDESC_TYPE_I386_MXCSR }
 };
 
 /* Return the type associated with ID in the context of FEATURE, or
@@ -486,12 +492,38 @@ tdesc_named_type (const struct tdesc_feature *feature, const char *id)
   return NULL;
 }
 
+/* Lookup type associated with ID.  */
+
+struct type *
+tdesc_find_type (struct gdbarch *gdbarch, const char *id)
+{
+  struct tdesc_arch_reg *reg;
+  struct tdesc_arch_data *data;
+  int i, num_regs;
+
+  data = gdbarch_data (gdbarch, tdesc_data);
+  num_regs = VEC_length (tdesc_arch_reg, data->arch_regs);
+  for (i = 0; i < num_regs; i++)
+    {
+      reg = VEC_index (tdesc_arch_reg, data->arch_regs, i);
+      if (reg->reg
+	  && reg->reg->tdesc_type
+	  && reg->type
+	  && strcmp (id, reg->reg->tdesc_type->name) == 0)
+	return reg->type;
+    }
+
+  return NULL;
+}
+
 /* Construct, if necessary, and return the GDB type implementing target
    type TDESC_TYPE for architecture GDBARCH.  */
 
 static struct type *
 tdesc_gdb_type (struct gdbarch *gdbarch, struct tdesc_type *tdesc_type)
 {
+  struct type *type;
+
   switch (tdesc_type->kind)
     {
     /* Predefined types.  */
@@ -531,6 +563,16 @@ tdesc_gdb_type (struct gdbarch *gdbarch, struct tdesc_type *tdesc_type)
     case TDESC_TYPE_DATA_PTR:
       return builtin_type (gdbarch)->builtin_data_ptr;
 
+    default:
+      break;
+    }
+
+  type = tdesc_find_type (gdbarch, tdesc_type->name);
+  if (type)
+    return type;
+
+  switch (tdesc_type->kind)
+    {
     case TDESC_TYPE_IEEE_SINGLE:
       return arch_float_type (gdbarch, -1, "builtin_type_ieee_single",
 			      floatformats_ieee_single);
@@ -543,6 +585,58 @@ tdesc_gdb_type (struct gdbarch *gdbarch, struct tdesc_type *tdesc_type)
       return arch_float_type (gdbarch, -1, "builtin_type_arm_ext",
 			      floatformats_arm_ext);
 
+    case TDESC_TYPE_I387_EXT:
+      return arch_float_type (gdbarch, -1, "builtin_type_i387_ext",
+			      floatformats_i387_ext);
+
+    case TDESC_TYPE_I386_EFLAGS:
+      {
+	struct type *type;
+
+	type = arch_flags_type (gdbarch, "builtin_type_i386_mxcsr", 4);
+	append_flags_type_flag (type, 0, "IE");
+	append_flags_type_flag (type, 1, "DE");
+	append_flags_type_flag (type, 2, "ZE");
+	append_flags_type_flag (type, 3, "OE");
+	append_flags_type_flag (type, 4, "UE");
+	append_flags_type_flag (type, 5, "PE");
+	append_flags_type_flag (type, 6, "DAZ");
+	append_flags_type_flag (type, 7, "IM");
+	append_flags_type_flag (type, 8, "DM");
+	append_flags_type_flag (type, 9, "ZM");
+	append_flags_type_flag (type, 10, "OM");
+	append_flags_type_flag (type, 11, "UM");
+	append_flags_type_flag (type, 12, "PM");
+	append_flags_type_flag (type, 15, "FZ");
+
+	return type;
+      }
+    break;
+
+    case TDESC_TYPE_I386_MXCSR:
+      {
+	struct type *type;
+
+	type = arch_flags_type (gdbarch, "builtin_type_i386_mxcsr", 4);
+	append_flags_type_flag (type, 0, "IE");
+	append_flags_type_flag (type, 1, "DE");
+	append_flags_type_flag (type, 2, "ZE");
+	append_flags_type_flag (type, 3, "OE");
+	append_flags_type_flag (type, 4, "UE");
+	append_flags_type_flag (type, 5, "PE");
+	append_flags_type_flag (type, 6, "DAZ");
+	append_flags_type_flag (type, 7, "IM");
+	append_flags_type_flag (type, 8, "DM");
+	append_flags_type_flag (type, 9, "ZM");
+	append_flags_type_flag (type, 10, "OM");
+	append_flags_type_flag (type, 11, "UM");
+	append_flags_type_flag (type, 12, "PM");
+	append_flags_type_flag (type, 15, "FZ");
+
+	return type;
+      }
+    break;
+
     /* Types defined by a target feature.  */
     case TDESC_TYPE_VECTOR:
       {
diff --git a/gdb/target-descriptions.h b/gdb/target-descriptions.h
index 17f52eb..da0564b 100644
--- a/gdb/target-descriptions.h
+++ b/gdb/target-descriptions.h
@@ -176,6 +176,10 @@ const char *tdesc_register_name (struct gdbarch *gdbarch, int regno);
 
 struct type *tdesc_register_type (struct gdbarch *gdbarch, int regno);
 
+/* Return the type associated with ID, from the target description. */
+
+struct type *tdesc_find_type (struct gdbarch *gdbarch, const char *id);
+
 /* Check whether REGNUM is a member of REGGROUP using the target
    description.  Return -1 if the target description does not
    specify a group.  */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]