2004-07-27 Andrew Cagney <cagney@gnu.org>
authorAndrew Cagney <cagney@redhat.com>
Wed, 28 Jul 2004 02:46:24 +0000 (02:46 +0000)
committerAndrew Cagney <cagney@redhat.com>
Wed, 28 Jul 2004 02:46:24 +0000 (02:46 +0000)
* defs.h (enum language): Add nr_languages.
* language.h (struct language_arch_info): Define.
(struct language_defn): Add la_language_arch_info.
(language_lookup_primative_type_by_name): Declare.
(language_string_char_type): Declare.
* language.c (_initialize_language, language_gdbarch_post_init)
(struct language_gdbarch, language_gdbarch_data): Implement
per-architecture language information.
(unknown_language_arch_info, language_string_char_type)
(language_lookup_primative_type_by_name): New functions.
(unknown_language_defn, auto_language_defn)
(local_language_defn): Set la_language_arch_info to
unknown_language_arch_info.
(unknown_builtin_types): Delete.
* gdbtypes.c (lookup_primitive_typename): Use
language_lookup_primative_type_by_name.
(create_string_type): Use language_string_char_type.
* values.c (value_from_string): Use language_string_char_type.
* scm-lang.c (scm_language_defn): Add NULL la_language_arch_info.
* p-lang.c (pascal_language_defn): Ditto.
* m2-lang.c (m2_language_defn): Ditto.
* jv-lang.c (java_language_defn): Ditto.
* objc-lang.c (objc_language_defn): Ditto.
* f-lang.c (f_language_defn): Ditto.
* c-lang.c (c_language_defn, cplus_language_defn)
(asm_language_defn, minimal_language_defn): Ditto.

13 files changed:
gdb/ChangeLog
gdb/c-lang.c
gdb/defs.h
gdb/f-lang.c
gdb/gdbtypes.c
gdb/jv-lang.c
gdb/language.c
gdb/language.h
gdb/m2-lang.c
gdb/objc-lang.c
gdb/p-lang.c
gdb/scm-lang.c
gdb/values.c

index b64f3a513cd907d5196c14beb51012683326cfc4..4e81d906a99a0289962f260e172c1d46ae98a254 100644 (file)
@@ -1,3 +1,32 @@
+2004-07-27  Andrew Cagney  <cagney@gnu.org>
+
+       * defs.h (enum language): Add nr_languages.
+       * language.h (struct language_arch_info): Define.
+       (struct language_defn): Add la_language_arch_info.
+       (language_lookup_primative_type_by_name): Declare.
+       (language_string_char_type): Declare.
+       * language.c (_initialize_language, language_gdbarch_post_init)
+       (struct language_gdbarch, language_gdbarch_data): Implement
+       per-architecture language information.
+       (unknown_language_arch_info, language_string_char_type)
+       (language_lookup_primative_type_by_name): New functions.
+       (unknown_language_defn, auto_language_defn)
+       (local_language_defn): Set la_language_arch_info to
+       unknown_language_arch_info.
+       (unknown_builtin_types): Delete.
+       * gdbtypes.c (lookup_primitive_typename): Use
+       language_lookup_primative_type_by_name.
+       (create_string_type): Use language_string_char_type.
+       * values.c (value_from_string): Use language_string_char_type.
+       * scm-lang.c (scm_language_defn): Add NULL la_language_arch_info.
+       * p-lang.c (pascal_language_defn): Ditto.
+       * m2-lang.c (m2_language_defn): Ditto.
+       * jv-lang.c (java_language_defn): Ditto.
+       * objc-lang.c (objc_language_defn): Ditto.
+       * f-lang.c (f_language_defn): Ditto.
+       * c-lang.c (c_language_defn, cplus_language_defn) 
+       (asm_language_defn, minimal_language_defn): Ditto.
+       
 2004-07-27  Andrew Cagney  <cagney@gnu.org>
 
        * gdbtypes.h (struct builtin_type): Declare.
index 19c08dc44155a6311356cd676bb454d026c5bfad..a9b3ab0e4ac8c3d82ce1e64639567ee8f0bc1bef 100644 (file)
@@ -569,6 +569,7 @@ const struct language_defn c_language_defn =
   0,                           /* String lower bound */
   &builtin_type_char,          /* Type of string elements */
   default_word_break_characters,
+  NULL, /* FIXME: la_language_arch_info.  */
   LANG_MAGIC
 };
 
@@ -629,6 +630,7 @@ const struct language_defn cplus_language_defn =
   0,                           /* String lower bound */
   &builtin_type_char,          /* Type of string elements */
   default_word_break_characters,
+  NULL, /* FIXME: la_language_arch_info.  */
   LANG_MAGIC
 };
 
@@ -666,6 +668,7 @@ const struct language_defn asm_language_defn =
   0,                           /* String lower bound */
   &builtin_type_char,          /* Type of string elements */
   default_word_break_characters,
+  NULL, /* FIXME: la_language_arch_info.  */
   LANG_MAGIC
 };
 
@@ -708,6 +711,7 @@ const struct language_defn minimal_language_defn =
   0,                           /* String lower bound */
   &builtin_type_char,          /* Type of string elements */
   default_word_break_characters,
+  NULL, /* FIXME: la_language_arch_info.  */
   LANG_MAGIC
 };
 
index deee6bfd4dc31aa4e34ff439f15310c3f31e90f0..95b7e818959d946be6c01bebc2b4bfd0b1210717 100644 (file)
@@ -220,7 +220,8 @@ enum language
     language_asm,              /* Assembly language */
     language_scm,              /* Scheme / Guile */
     language_pascal,           /* Pascal */
-    language_minimal           /* All other languages, minimal support only */
+    language_minimal,          /* All other languages, minimal support only */
+    nr_languages
   };
 
 enum precision_type
index 4219d4539e4da195d8e0f606882192a89ce14d50..e354cad00e55b9cf09f4e3edb20470135e43f0d3 100644 (file)
@@ -488,6 +488,7 @@ const struct language_defn f_language_defn =
   1,                           /* String lower bound */
   &builtin_type_f_character,   /* Type of string elements */
   default_word_break_characters,
+  NULL, /* FIXME: la_language_arch_info.  */
   LANG_MAGIC
 };
 
index 3a28a299fcae236adf01de3ba97a6d4af03f33e3..c626e9bd636c49de839a1851f633b4d722c0d0eb 100644 (file)
@@ -774,8 +774,12 @@ create_array_type (struct type *result_type, struct type *element_type,
 struct type *
 create_string_type (struct type *result_type, struct type *range_type)
 {
+  struct type *string_char_type;
+      
+  string_char_type = language_string_char_type (current_language,
+                                               current_gdbarch);
   result_type = create_array_type (result_type,
-                                  *current_language->string_char_type,
+                                  string_char_type,
                                   range_type);
   TYPE_CODE (result_type) = TYPE_CODE_STRING;
   return (result_type);
@@ -1032,16 +1036,9 @@ type_name_no_tag (const struct type *type)
 struct type *
 lookup_primitive_typename (char *name)
 {
-  struct type **const *p;
-
-  for (p = current_language->la_builtin_type_vector; *p != NULL; p++)
-    {
-      if (strcmp (TYPE_NAME (**p), name) == 0)
-       {
-         return (**p);
-       }
-    }
-  return (NULL);
+  return language_lookup_primative_type_by_name (current_language,
+                                                current_gdbarch,
+                                                name);
 }
 
 /* Lookup a typedef or primitive type named NAME,
index 1fb8cd2d2ba1db04da66dfb8d9fcd3f3dbd664f1..3f68ec4051ffeba1d3cf079236fec9410c0db595 100644 (file)
@@ -1114,6 +1114,7 @@ const struct language_defn java_language_defn =
   0,                           /* String lower bound */
   &builtin_type_char,          /* Type of string elements */
   default_word_break_characters,
+  NULL, /* FIXME: la_language_arch_info.  */
   LANG_MAGIC
 };
 
index ec03a47879c9238dc5900cfe1110c9bbec78d8a3..b8ef8c9cb14b85fcea63bc111184162bfbee7efe 100644 (file)
@@ -1273,20 +1273,25 @@ static char *unk_lang_class_name (const char *mangled)
   return NULL;
 }
 
-static struct type **const (unknown_builtin_types[]) =
-{
-  0
-};
 static const struct op_print unk_op_print_tab[] =
 {
   {NULL, OP_NULL, PREC_NULL, 0}
 };
 
+static void
+unknown_language_arch_info (struct gdbarch *gdbarch,
+                           struct language_arch_info *lai)
+{
+  lai->string_char_type = builtin_type (gdbarch)->builtin_char;
+  lai->primative_type_vector = GDBARCH_OBSTACK_CALLOC (gdbarch, 1,
+                                                      struct type *);
+}
+
 const struct language_defn unknown_language_defn =
 {
   "unknown",
   language_unknown,
-  &unknown_builtin_types[0],
+  NULL,
   range_check_off,
   type_check_off,
   case_sensitive_on,
@@ -1314,8 +1319,9 @@ const struct language_defn unknown_language_defn =
   unk_op_print_tab,            /* expression operators for printing */
   1,                           /* c-style arrays */
   0,                           /* String lower bound */
-  &builtin_type_char,          /* Type of string elements */
+  NULL,
   default_word_break_characters,
+  unknown_language_arch_info,  /* la_language_arch_info.  */
   LANG_MAGIC
 };
 
@@ -1324,7 +1330,7 @@ const struct language_defn auto_language_defn =
 {
   "auto",
   language_auto,
-  &unknown_builtin_types[0],
+  NULL,
   range_check_off,
   type_check_off,
   case_sensitive_on,
@@ -1352,8 +1358,9 @@ const struct language_defn auto_language_defn =
   unk_op_print_tab,            /* expression operators for printing */
   1,                           /* c-style arrays */
   0,                           /* String lower bound */
-  &builtin_type_char,          /* Type of string elements */
+  NULL,
   default_word_break_characters,
+  unknown_language_arch_info,  /* la_language_arch_info.  */
   LANG_MAGIC
 };
 
@@ -1361,7 +1368,7 @@ const struct language_defn local_language_defn =
 {
   "local",
   language_auto,
-  &unknown_builtin_types[0],
+  NULL,
   range_check_off,
   type_check_off,
   case_sensitive_on,
@@ -1389,11 +1396,82 @@ const struct language_defn local_language_defn =
   unk_op_print_tab,            /* expression operators for printing */
   1,                           /* c-style arrays */
   0,                           /* String lower bound */
-  &builtin_type_char,          /* Type of string elements */
+  NULL,
   default_word_break_characters,
+  unknown_language_arch_info,  /* la_language_arch_info.  */
   LANG_MAGIC
 };
 \f
+/* Per-architecture language information.  */
+
+static struct gdbarch_data *language_gdbarch_data;
+
+struct language_gdbarch
+{
+  /* A vector of per-language per-architecture info.  Indexed by "enum
+     language".  */
+  struct language_arch_info arch_info[nr_languages];
+};
+
+static void *
+language_gdbarch_post_init (struct gdbarch *gdbarch)
+{
+  struct language_gdbarch *l;
+  int i;
+
+  l = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct language_gdbarch);
+  for (i = 0; i <= languages_size; i++)
+    {
+      if (languages[i] != NULL
+         && languages[i]->la_language_arch_info != NULL)
+       languages[i]->la_language_arch_info
+         (gdbarch, l->arch_info + languages[i]->la_language);
+    }
+  return l;
+}
+
+struct type *
+language_string_char_type (const struct language_defn *la,
+                          struct gdbarch *gdbarch)
+{
+  struct language_gdbarch *ld = gdbarch_data (gdbarch,
+                                             language_gdbarch_data);
+  if (ld->arch_info[la->la_language].string_char_type != NULL)
+    return ld->arch_info[la->la_language].string_char_type;
+  else
+    return (*la->string_char_type);
+}
+
+struct type *
+language_lookup_primative_type_by_name (const struct language_defn *la,
+                                       struct gdbarch *gdbarch,
+                                       const char *name)
+{
+  struct language_gdbarch *ld = gdbarch_data (gdbarch,
+                                             language_gdbarch_data);
+  if (ld->arch_info[la->la_language].primative_type_vector != NULL)
+    {
+      struct type *const *p;
+      for (p = ld->arch_info[la->la_language].primative_type_vector;
+          (*p) != NULL;
+          p++)
+       {
+         if (strcmp (TYPE_NAME (*p), name) == 0)
+           return (*p);
+       }
+    }
+  else
+    {
+      struct type **const *p;
+      for (p = current_language->la_builtin_type_vector; *p != NULL; p++)
+       {
+         if (strcmp (TYPE_NAME (**p), name) == 0)
+           return (**p);
+       }
+    }
+  return (NULL);
+}
+
 /* Initialize the language routines */
 
 void
@@ -1401,6 +1479,9 @@ _initialize_language (void)
 {
   struct cmd_list_element *set, *show;
 
+  language_gdbarch_data
+    = gdbarch_data_register_post_init (language_gdbarch_post_init);
+
   /* GDB commands for language specific stuff */
 
   set = add_set_cmd ("language", class_support, var_string_noescape,
index bbb45f6c7b892f9f86f877118368b4fcf02ee652..511c1cbe0ea67e071fd7425c855b2aefb0191361 100644 (file)
@@ -137,6 +137,26 @@ struct language_format_info
     char *la_format_suffix;    /* Suffix for custom format string */
   };
 
+/* Per architecture (OS/ABI) language information.  */
+
+struct language_arch_info
+{
+  /* Its primative types.  This is a vector ended by a NULL pointer.
+     These types can be specified by name in parsing types in
+     expressions, regardless of whether the program being debugged
+     actually defines such a type.  */
+  struct type **primative_type_vector;
+  /* Type of elements of strings. */
+  struct type *string_char_type;
+};
+
+struct type *language_string_char_type (const struct language_defn *l,
+                                       struct gdbarch *gdbarch);
+
+struct type *language_lookup_primative_type_by_name (const struct language_defn *l,
+                                                    struct gdbarch *gdbarch,
+                                                    const char *name);
+
 /* Structure tying together assorted information about a language.  */
 
 struct language_defn
@@ -284,6 +304,10 @@ struct language_defn
     /* The list of characters forming word boundaries.  */
     char *(*la_word_break_characters) (void);
 
+    /* The per-architecture (OS/ABI) language information.  */
+    void (*la_language_arch_info) (struct gdbarch *,
+                                  struct language_arch_info *);
+
     /* Add fields above this point, so the magic number is always last. */
     /* Magic number for compat checking */
 
index 1ab5d3b7a4e29c243606bc4eb0ab5ab6ecda2ee2..722805e2faf31e2839ef61a84c03679b97045ca2 100644 (file)
@@ -441,6 +441,7 @@ const struct language_defn m2_language_defn =
   0,                           /* String lower bound */
   &builtin_type_m2_char,       /* Type of string elements */
   default_word_break_characters,
+  NULL, /* FIXME: la_language_arch_info.  */
   LANG_MAGIC
 };
 
index bcd487378bc248b9ecc49947ebfdebadffe8bb77..b9e48971533e99e8ad972b3e3d918e268876ee73 100644 (file)
@@ -685,6 +685,7 @@ const struct language_defn objc_language_defn = {
   0,                           /* String lower bound */
   &builtin_type_char,          /* Type of string elements */
   default_word_break_characters,
+  NULL, /* FIXME: la_language_arch_info.  */
   LANG_MAGIC
 };
 
index 3866e2cd6600ea2b588167baa391be873b38cc7f..115bfe106fa2843f0c38d39b0615e27bf0b8e87a 100644 (file)
@@ -477,6 +477,7 @@ const struct language_defn pascal_language_defn =
   0,                           /* String lower bound */
   &builtin_type_char,          /* Type of string elements */
   default_word_break_characters,
+  NULL, /* FIXME: la_language_arch_info.  */
   LANG_MAGIC
 };
 
index 665ac1b96bf56f9a7fbcf76bbea4913002dd3f87..809f70304306c7e198e4efa0e6424620c2f747fd 100644 (file)
@@ -276,6 +276,7 @@ const struct language_defn scm_language_defn =
   0,                           /* String lower bound */
   &builtin_type_char,          /* Type of string elements */
   default_word_break_characters,
+  NULL, /* FIXME: la_language_arch_info.  */
   LANG_MAGIC
 };
 
index a42e53a298b980ddc696ad602d6dd389372f1912..eaf3765c31aee7bf7fe0fd6256d4b9d3aa26a5d9 100644 (file)
@@ -1170,15 +1170,18 @@ value_from_string (char *ptr)
   struct value *val;
   int len = strlen (ptr);
   int lowbound = current_language->string_lower_bound;
-  struct type *rangetype =
-  create_range_type ((struct type *) NULL,
-                    builtin_type_int,
-                    lowbound, len + lowbound - 1);
-  struct type *stringtype =
-  create_array_type ((struct type *) NULL,
-                    *current_language->string_char_type,
-                    rangetype);
-
+  struct type *string_char_type;
+  struct type *rangetype;
+  struct type *stringtype;
+
+  rangetype = create_range_type ((struct type *) NULL,
+                                builtin_type_int,
+                                lowbound, len + lowbound - 1);
+  string_char_type = language_string_char_type (current_language,
+                                               current_gdbarch);
+  stringtype = create_array_type ((struct type *) NULL,
+                                 string_char_type,
+                                 rangetype);
   val = allocate_value (stringtype);
   memcpy (VALUE_CONTENTS_RAW (val), ptr, len);
   return val;