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]

[10/10] Convert Modula-2 types to per-gdbarch data


Hello,

the Modula-2 language defines a set of builtin types that are not even
gdbarch-swapped, even though they depend on platform settings!

This patch fixes them by introducing a builtin_m2_type per-gdbarch
structure, just like the builtin_f_type one.

Bye,
Ulrich


ChangeLog:

	* gdbtypes.h (builtin_type_m2_char, builtin_type_m2_int,
	builtin_type_m2_card, builtin_type_m2_real, builtin_type_m2_bool):
	Replace global variable declaration with compatibility macro.
        (struct builtin_m2_type): New data type.
        (builtin_m2_type): Add prototype.
	* m2-lang.c (builtin_type_m2_char, builtin_type_m2_int,
	builtin_type_m2_card, builtin_type_m2_real, builtin_type_m2_bool):
	Remove global variables.
        (m2_language_arch_info): Use builtin_m2_type instead of variables.
	(build_m2_types): New function.
        (m2_type_data): New variable.
        (builtin_m2_type): New function.
        (_initialize_m2_language): Do not build data types.  Register
	m2_type_data per-gdbarch data.


diff -urNp gdb-orig/gdb/gdbtypes.h gdb-head/gdb/gdbtypes.h
--- gdb-orig/gdb/gdbtypes.h	2007-06-08 19:51:06.198241768 +0200
+++ gdb-head/gdb/gdbtypes.h	2007-06-08 19:53:53.808507868 +0200
@@ -1179,11 +1179,30 @@ extern struct type *builtin_type_error;
 
 /* Modula-2 types */
 
-extern struct type *builtin_type_m2_char;
-extern struct type *builtin_type_m2_int;
-extern struct type *builtin_type_m2_card;
-extern struct type *builtin_type_m2_real;
-extern struct type *builtin_type_m2_bool;
+struct builtin_m2_type
+{
+  struct type *builtin_char;
+  struct type *builtin_int;
+  struct type *builtin_card;
+  struct type *builtin_real;
+  struct type *builtin_bool;
+};
+
+/* Return the Modula-2 type table for the specified architecture.  */
+extern const struct builtin_m2_type *builtin_m2_type (struct gdbarch *gdbarch);
+
+/* Compatibility macros to access types for the current architecture.  */
+#define builtin_type_m2_char \
+	(builtin_m2_type (current_gdbarch)->builtin_char)
+#define builtin_type_m2_int \
+	(builtin_m2_type (current_gdbarch)->builtin_int)
+#define builtin_type_m2_card \
+	(builtin_m2_type (current_gdbarch)->builtin_card)
+#define builtin_type_m2_real \
+	(builtin_m2_type (current_gdbarch)->builtin_real)
+#define builtin_type_m2_bool \
+	(builtin_m2_type (current_gdbarch)->builtin_bool)
+
 
 /* Fortran (F77) types */
 
diff -urNp gdb-orig/gdb/m2-lang.c gdb-head/gdb/m2-lang.c
--- gdb-orig/gdb/m2-lang.c	2007-06-08 19:28:55.567765501 +0200
+++ gdb-head/gdb/m2-lang.c	2007-06-08 19:59:45.169238601 +0200
@@ -389,12 +389,6 @@ static const struct op_print m2_op_print
 
 /* The built-in types of Modula-2.  */
 
-struct type *builtin_type_m2_char;
-struct type *builtin_type_m2_int;
-struct type *builtin_type_m2_card;
-struct type *builtin_type_m2_real;
-struct type *builtin_type_m2_bool;
-
 enum m2_primitive_types {
   m2_primitive_type_char,
   m2_primitive_type_int,
@@ -408,21 +402,23 @@ static void
 m2_language_arch_info (struct gdbarch *gdbarch,
 		       struct language_arch_info *lai)
 {
-  lai->string_char_type = builtin_type_m2_char;
+  const struct builtin_m2_type *builtin = builtin_m2_type (gdbarch);
+
+  lai->string_char_type = builtin->builtin_char;
   lai->primitive_type_vector
     = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_m2_primitive_types + 1,
                               struct type *);
 
   lai->primitive_type_vector [m2_primitive_type_char]
-    = builtin_type_m2_char;
+    = builtin->builtin_char;
   lai->primitive_type_vector [m2_primitive_type_int]
-    = builtin_type_m2_int;
+    = builtin->builtin_int;
   lai->primitive_type_vector [m2_primitive_type_card]
-    = builtin_type_m2_card;
+    = builtin->builtin_card;
   lai->primitive_type_vector [m2_primitive_type_real]
-    = builtin_type_m2_real;
+    = builtin->builtin_real;
   lai->primitive_type_vector [m2_primitive_type_bool]
-    = builtin_type_m2_bool;
+    = builtin->builtin_bool;
 }
 
 const struct language_defn m2_language_defn =
@@ -461,32 +457,52 @@ const struct language_defn m2_language_d
   LANG_MAGIC
 };
 
-/* Initialization for Modula-2 */
-
-void
-_initialize_m2_language (void)
+static void *
+build_m2_types (struct gdbarch *gdbarch)
 {
+  struct builtin_m2_type *builtin_m2_type
+    = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_m2_type);
+
   /* Modula-2 "pervasive" types.  NOTE:  these can be redefined!!! */
-  builtin_type_m2_int =
+  builtin_m2_type->builtin_int =
     init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
 	       0,
 	       "INTEGER", (struct objfile *) NULL);
-  builtin_type_m2_card =
+  builtin_m2_type->builtin_card =
     init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
 	       TYPE_FLAG_UNSIGNED,
 	       "CARDINAL", (struct objfile *) NULL);
-  builtin_type_m2_real =
+  builtin_m2_type->builtin_real =
     init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
 	       0,
 	       "REAL", (struct objfile *) NULL);
-  builtin_type_m2_char =
+  builtin_m2_type->builtin_char =
     init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
 	       TYPE_FLAG_UNSIGNED,
 	       "CHAR", (struct objfile *) NULL);
-  builtin_type_m2_bool =
+  builtin_m2_type->builtin_bool =
     init_type (TYPE_CODE_BOOL, TARGET_INT_BIT / TARGET_CHAR_BIT,
 	       TYPE_FLAG_UNSIGNED,
 	       "BOOLEAN", (struct objfile *) NULL);
 
+  return builtin_m2_type;
+}
+
+static struct gdbarch_data *m2_type_data;
+
+const struct builtin_m2_type *
+builtin_m2_type (struct gdbarch *gdbarch)
+{
+  return gdbarch_data (gdbarch, m2_type_data);
+}
+
+
+/* Initialization for Modula-2 */
+
+void
+_initialize_m2_language (void)
+{
+  m2_type_data = gdbarch_data_register_post_init (build_m2_types);
+
   add_language (&m2_language_defn);
 }
-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com


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